-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from VaquitApp/add-groups
Add groups
- Loading branch information
Showing
16 changed files
with
181 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
VITE_API_URL="http://localhost:8000" | ||
# VITE_API_URL="http://127.0.0.1:8000" | ||
VITE_API_URL="http://localhost:8000" |
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,5 @@ | ||
import type { ParamMatcher } from '@sveltejs/kit'; | ||
|
||
export const match: ParamMatcher = (param) => { | ||
return /^\d+$/.test(param); | ||
}; |
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,11 @@ | ||
import { get } from '$lib/api'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ cookies }) => { | ||
const token = cookies.get('jwt')!; | ||
const headers = { | ||
'x-user': token | ||
}; | ||
const groups: Group[] = await get('group', headers); | ||
return { groups }; | ||
}; |
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,42 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Grupos</title> | ||
</svelte:head> | ||
|
||
<header class="row"> | ||
<h2>Grupos</h2> | ||
<a href="/groups/details" role="button">Nuevo grupo</a> | ||
</header> | ||
<main> | ||
{#if !data.groups.length} | ||
<article class="centered"> | ||
<p>Todavía no pertenece a ningún grupo. ¿Por qué no crea uno?</p> | ||
<a href="/groups/details">Crear un nuevo grupo</a> | ||
</article> | ||
{/if} | ||
{#each data.groups as group} | ||
<article> | ||
<header>{group.name}</header> | ||
<p>{group.description}</p> | ||
<a href="/groups/details/{group.id}">Ver en detalle</a> | ||
</article> | ||
{/each} | ||
</main> | ||
|
||
<style> | ||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
.centered { | ||
text-align: center; | ||
} | ||
</style> |
39 changes: 39 additions & 0 deletions
39
my-app/src/routes/groups/details/[[id=integer]]/+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,39 @@ | ||
import { error, fail } from '@sveltejs/kit'; | ||
import type { Actions } from './$types'; | ||
import { post } from '$lib/api'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
let group: Group = { name: '', description: '', id: 0, owner_id: 0 }; | ||
const id = params.id; | ||
if (id) { | ||
// TODO: load real group | ||
} | ||
return { group }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async ({ cookies, request, params }) => { | ||
const data = await request.formData(); | ||
const name = data.get('name'); | ||
const description = data.get('description'); | ||
|
||
if (!name) { | ||
throw error(400, 'Name is required'); | ||
} | ||
if (!description) { | ||
throw error(400, 'Description is required'); | ||
} | ||
|
||
const token = cookies.get('jwt')!; | ||
const body = await post('group', { name, description }, { 'x-user': token }); | ||
|
||
if (body.errors) { | ||
throw fail(400, body); | ||
} | ||
|
||
const value = body.id; | ||
|
||
return { success: true }; | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
my-app/src/routes/groups/details/[[id=integer]]/+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,32 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Nuevo Grupo</title> | ||
</svelte:head> | ||
|
||
<h2>Nuevo Grupo</h2> | ||
<form method="POST"> | ||
<fieldset> | ||
<label> | ||
Ingrese un nombre para el grupo | ||
<input type="text" name="name" value={data.group.name} placeholder="Nombre" required /> | ||
</label> | ||
<label> | ||
Ingrese una descripción para el grupo | ||
<input | ||
type="text" | ||
name="description" | ||
value={data.group.description} | ||
placeholder="Descripcion" | ||
required | ||
/> | ||
</label> | ||
<button>Crear</button> | ||
<button type="button" class="outline" on:click={() => history.back()}>Cancelar</button> | ||
</fieldset> | ||
</form> |
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 @@ | ||
declare global { | ||
type Group = { | ||
id: number; | ||
owner_id: number; | ||
name: String; | ||
description: String; | ||
}; | ||
} | ||
|
||
export {}; |
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