-
Notifications
You must be signed in to change notification settings - Fork 0
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
Receita frontend #51
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
789be4f
fix: Fix security config
P0RTW0N a540435
fix: Fix tipoReceita endpoint
P0RTW0N 1fed459
fix: Fix tipoReceita endpoint
P0RTW0N 7ef01b5
feat : Add Receita functionalities
P0RTW0N 824bc97
fix: fix console.log
P0RTW0N 7088732
style: chang style
P0RTW0N 86a7a4b
fix: fix unused import
P0RTW0N c86ad88
Merge branch 'main' into Receita_Frontend
P0RTW0N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
13 changes: 13 additions & 0 deletions
13
desofs_svelte_front_end/src/routes/recipe/create-recipe/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
105
desofs_svelte_front_end/src/routes/recipe/create-recipe/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
23 changes: 23 additions & 0 deletions
23
desofs_svelte_front_end/src/routes/recipe/edit-recipe/[recipeId]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aqui metes por Admin