Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receita frontend #51

Merged
merged 8 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ public Pacote getPacote() {
public TipoReceita getTipoReceita() {
return tipoReceita;
}

public void setReceitaId(Long receitaId) {
this.receitaId = receitaId;
}

public void setPath(String path) {
this.path = path;
}

public void setNome(String nome) {
this.nome = nome;
}

public void setPacote(Pacote pacote) {
this.pacote = pacote;
}

public void setTipoReceita(TipoReceita tipoReceita) {
this.tipoReceita = tipoReceita;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,23 @@ public Long getTipoReceita() {
return tipoReceita;
}

public void setReceitaId(Long receitaId) {
this.receitaId = receitaId;
}

public void setPath(String path) {
this.path = path;
}

public void setNome(String nome) {
this.nome = nome;
}

public void setPacote(Long pacote) {
this.pacote = pacote;
}

public void setTipoReceita(Long tipoReceita) {
this.tipoReceita = tipoReceita;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ public Pacote getPacote() {
public TipoReceita getTipoReceita() {
return tipoReceita;
}

public void setReceitaId(Long receitaId) {
this.receitaId = receitaId;
}

public void setPath(String path) {
this.path = path;
}

public void setNome(String nome) {
this.nome = nome;
}

public void setPacote(Pacote pacote) {
this.pacote = pacote;
}

public void setTipoReceita(TipoReceita tipoReceita) {
this.tipoReceita = tipoReceita;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public String getNome() {
return nome;
}

public void setTipoReceitaId(Long tipoReceitaId) {
this.tipoReceitaId = tipoReceitaId;
}

public void setNome(String nome) {
this.nome = nome;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public String getNome() {
public void setNome(String nome) {
this.nome = nome;
}

public void setTipoReceitaId(Long tipoReceitaId) {
this.tipoReceitaId = tipoReceitaId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers("/encomenda/**").authenticated()
.requestMatchers("/user/delete/data").authenticated()
.requestMatchers("/tipoReceita/**").authenticated()
.requestMatchers("/receita/**").authenticated()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui metes por Admin

.requestMatchers("/api-docs/**").permitAll()
.requestMatchers("/swagger-ui/**").permitAll()

Expand Down
35 changes: 34 additions & 1 deletion desofs_svelte_front_end/src/lib/Types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ type Delivery = {
user: User;
};

//Recipes
type RecipeDTOSend = {
path: string;
nome: string;
pacote: number;
tipoReceita: number;
};

type RecipePatchSend = {
receitaId: number;
path: string;
nome: string;
pacote: number;
tipoReceita: number;
};

type Recipe = {
receitaId: number;
path: string;
nome: string;
pacote: Package;
tipoReceita: RecipeType;
};

type RecipeType = {
tipoReceitaId: number;
nome: string;
};

enum StateDelivery {
REGISTADO,
ENTREGUE,
Expand All @@ -121,5 +150,9 @@ export type {
DeliveryDTOSend,
Delivery,
DeliveryDTOPatch,
StateDelivery
StateDelivery,
RecipeDTOSend,
RecipePatchSend,
RecipeType,
Recipe
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
text="GestΓ£o de pacotes"
gotoName="/package-management"
/>

<Button className="recipe-management-button" text="Receitas" gotoName="/recipe" />
{/if}
{#if data.user}
<Button className="dashboard-button" text="Dashboard" gotoName="/dashboard" />
Expand Down
10 changes: 10 additions & 0 deletions desofs_svelte_front_end/src/routes/recipe/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { PageServerLoad } from './$types';
import type { Recipe } from '$lib/Types/types';
import { sendRequest } from '$lib/scripts';

export const load: PageServerLoad = async ({ locals }) => {
const response = await sendRequest(`receita/all`, 'GET', '', locals.user.token);

const recipes: Recipe[] = await response.json();
return { recipes };
};
67 changes: 67 additions & 0 deletions desofs_svelte_front_end/src/routes/recipe/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<script lang="ts">
import type { PageData } from './$types';
import { goto, invalidateAll } from '$app/navigation';
import { sendRequest } from '$lib/scripts';

export let data: PageData;

async function deleteRecipe(recipeId: number) {
const response = await sendRequest(`receita/delete/${recipeId}`, 'DELETE', '', data.user.token);

if (response.ok) {
goto('/recipe');
} else {
console.error('Error deleting recipe');
}

await invalidateAll();
}
</script>

<!-- 2 partes horizontais -->
<div class="bg-gray-100 px-20 pt-10 min-h-screen">
<div class="flex flex-col border rounded bg-white px-20 py-12 gap-5">
<div class="flex">
<div style="flex-grow: 1;text-align: end;">
<button
style="margin-left: auto;"
class="ml-auto inline-block rounded border px-4 py-2 bg-white hover:bg-gray-200 transition-colors duration-300"
on:click={() => goto('/recipe/create-recipe')}><i class="fa-solid fa-plus"></i></button
>
</div>
</div>
<table class="table-auto text-center">
<thead>
<tr class="h-12">
<th class="border text-xl">Package</th>
<th class="border text-xl">Recipe Type</th>
<th class="border text-xl">Path</th>
<th class="border text-xl">Name</th>
<th class="border text-xl">Actions</th>
</tr>
</thead>
<tbody>
{#each data.recipes as item}
<tr class="h-13">
<td class="border py-5">{item.pacote.pacoteId}</td>
<td class="border py-5">{item.tipoReceita.tipoReceitaId}</td>
<td class="border py-5">{item.path}</td>
<td class="border py-5">{item.nome}</td>
<td class="border py-5">
<button
class="inline-block rounded border px-4 py-2 bg-white hover:bg-gray-200 transition-colors duration-300"
on:click={() => goto(`/recipe/edit-recipe/${item.receitaId}`)}
><i class="fa-solid fa-pen-to-square"></i></button
>
<button
class="inline-block rounded border px-4 py-2 bg-white hover:bg-gray-200 transition-colors duration-300"
on:click={() => deleteRecipe(item.receitaId)}
><i class="fa-solid fa-trash"></i></button
>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { PageServerLoad } from './$types';
import type { Package, RecipeType } from '$lib/Types/types';
import { sendRequest } from '$lib/scripts';

export const load: PageServerLoad = async ({ locals }) => {
const responsePacotes = await sendRequest('pacote/all', 'GET', '', '');
const pacotes: Package[] = await responsePacotes.json();

const responseTipoReceitas = await sendRequest('tipoReceita/list', 'GET', '', locals.user.token);
const tipoReceitas: RecipeType[] = await responseTipoReceitas.json();

return { pacotes, tipoReceitas };
};
105 changes: 105 additions & 0 deletions desofs_svelte_front_end/src/routes/recipe/create-recipe/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<script lang="ts">
import type { PageData } from './$types';
import { goto } from '$app/navigation';
import type { RecipeDTOSend } from '$lib/Types/types';
import { sendRequest } from '$lib/scripts';

export let data: PageData;

let packageId = 0;
let path = '';
let name = '';
let recipeTypeId = 0;

async function handleSubmit() {
const recipe: RecipeDTOSend = {
path: path,
nome: name,
tipoReceita: recipeTypeId,
pacote: packageId
};

const response = await sendRequest(
`receita/save`,
'POST',
JSON.stringify(recipe),
data.user.token
);

if (response.ok) {
goto('/recipe');
} else {
console.error('Failed to save recipe');
}
}

async function handleCancel() {
window.location.href = '/recipe';
}
</script>

<div class="bg-gray-100 px-20 pt-10 min-h-screen">
<h1 class="text-5xl font-bold mb-8 text-center">Create Recipe</h1>
<form class="grid grid-rows-3 border rounded bg-white px-20 py-12 gap-16">
<div class="flex flex-col gap-2 min-h-10 justify-evenly">
<div class="flex flex-row gap-2 content-center items-center">
<label class="min-w-40" for="name">Name</label>
<input
bind:value={name}
type="text"
name="name"
id="name"
class="rounded border border-current p-1 min-w-80"
/>
</div>
<div class="flex flex-row gap-2 content-center items-center">
<label class="min-w-40" for="path">Path</label>
<input
bind:value={path}
type="text"
name="path"
id="path"
class="rounded border border-current p-1 min-w-80"
/>
</div>
<div class="flex flex-row gap-2 content-center items-center">
<label class="min-w-40" for="tipoReceita">Recipe Type</label>
<select
bind:value={recipeTypeId}
name="tipoReceita"
id="tipoReceita"
class="rounded border border-current p-2 bg-white min-w-80"
>
{#each data.tipoReceitas as type}
<option value={type.tipoReceitaId}>{type.nome}</option>
{/each}
</select>
</div>
<div class="flex flex-row gap-2 content-center items-center">
<label class="min-w-40" for="pacote">Package</label>
<select
bind:value={packageId}
name="pacote"
id="pacote"
class="rounded border border-current p-2 bg-white min-w-80"
>
{#each data.pacotes as type}
<option value={type.pacoteId}>{type.nome}</option>
{/each}
</select>
</div>
</div>
<div class="flex flex-row gap-2 justify-center max-h-12">
<button
on:click={handleCancel}
class="inline-block rounded border px-4 py-2 bg-rose-600 hover:bg-red-600 transition-colors duration-300"
>Cancel</button
>
<button
on:click={handleSubmit}
class="inline-block rounded border px-4 py-2 bg-sky-600 hover:bg-blue-600 transition-colors duration-300"
>Add</button
>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { PageServerLoad } from './$types';
import type { Package, Recipe, RecipeType } from '$lib/Types/types';
import { sendRequest } from '$lib/scripts';

export const load: PageServerLoad = async ({ params, locals }) => {
const recipeIdId = params.recipeId;

const responsePacotes = await sendRequest('pacote/all', 'GET', '', '');
const pacotes: Package[] = await responsePacotes.json();

const responseTipoReceitas = await sendRequest('tipoReceita/list', 'GET', '', locals.user.token);
const tipoReceitas: RecipeType[] = await responseTipoReceitas.json();

const responseEncomenda = await sendRequest(
`receita/get/${recipeIdId}`,
'GET',
'',
locals.user.token
);
const recipe: Recipe = await responseEncomenda.json();

return { pacotes, recipe, tipoReceitas };
};
Loading
Loading