From 720fb35326316f2f771783e819846fcc0d1186e9 Mon Sep 17 00:00:00 2001 From: Bhasher Date: Sat, 6 Jan 2024 23:21:56 +0100 Subject: [PATCH] Projects page --- frontend/src/lib/api/projectsApi.ts | 60 ++++++++- .../src/lib/components/project/Column.svelte | 3 +- .../components/projects/SelectProject.svelte | 16 +-- .../src/lib/components/tags/SelectTags.svelte | 3 +- frontend/src/lib/stores/cards.ts | 53 -------- frontend/src/lib/stores/projectTags.ts | 126 ------------------ frontend/src/lib/stores/views.ts | 88 ------------ frontend/src/lib/types/Project.ts | 41 +++++- frontend/src/routes/+page.svelte | 59 ++------ 9 files changed, 107 insertions(+), 342 deletions(-) delete mode 100644 frontend/src/lib/stores/cards.ts delete mode 100644 frontend/src/lib/stores/projectTags.ts delete mode 100644 frontend/src/lib/stores/views.ts diff --git a/frontend/src/lib/api/projectsApi.ts b/frontend/src/lib/api/projectsApi.ts index a3eef55..6d15f05 100644 --- a/frontend/src/lib/api/projectsApi.ts +++ b/frontend/src/lib/api/projectsApi.ts @@ -1,10 +1,34 @@ import type Card from '$lib/types/Card'; -import type Project from '$lib/types/Project'; +import Project from '$lib/types/Project'; import ProjectTag from '$lib/types/ProjectTag'; import api, { processError } from '$lib/utils/api'; import { parseCards } from '$lib/utils/parser'; import status from '$lib/utils/status'; +async function getAll(): Promise { + const response = await api.get('/v1/projects'); + + if (response.status !== status.OK) { + processError(response, 'Failed to fetch projects'); + return []; + } + + return Project.parseAll(response.data); +} + +async function create(title: string): Promise { + const response = await api.post('/v1/projects', { + title + }); + + if (response.status !== status.Created) { + processError(response, 'Failed to create project'); + return null; + } + + return response.data.id; +} + async function get(projectId: number): Promise { const response = await api.get(`/v1/projects/${projectId}`); @@ -16,6 +40,30 @@ async function get(projectId: number): Promise { return response.data; } +async function update(projectId: number, title: string): Promise { + const response = await api.put(`/v1/projects/${projectId}`, { + title + }); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to update project'); + return false; + } + + return true; +} + +async function delete_(projectId: number): Promise { + const response = await api.delete(`/v1/projects/${projectId}`); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to delete project'); + return false; + } + + return true; +} + async function getCards(projectId: number): Promise { const response = await api.get(`/v1/projects/${projectId}/cards`); @@ -39,3 +87,13 @@ async function getTags(project: Project): Promise { return projectTags; } + +export default { + create, + get, + update, + delete: delete_, + getAll, + getCards, + getTags +}; diff --git a/frontend/src/lib/components/project/Column.svelte b/frontend/src/lib/components/project/Column.svelte index 654bf92..a4943d8 100644 --- a/frontend/src/lib/components/project/Column.svelte +++ b/frontend/src/lib/components/project/Column.svelte @@ -4,11 +4,10 @@ import type Card from '$lib/types/Card'; import type TagValue from '$lib/types/TagValue'; import { get } from 'svelte/store'; - import { createCardTagApi, deleteCardTagApi, updateCardTagApi } from '../../api/cards'; - import { updateTagAPI as updateTagOptionAPI } from '../../api/tags'; import projectTags from '../../stores/projectTags'; import CardComponent from '../card/Card.svelte'; import AddIcon from '../icons/AddIcon.svelte'; + import { import } from { createCardTagApi, deleteCardTagApi, updateCardTagApi }; export let projectId: number; export let optionId: number | null = null; diff --git a/frontend/src/lib/components/projects/SelectProject.svelte b/frontend/src/lib/components/projects/SelectProject.svelte index 9c86c08..9ca3fad 100644 --- a/frontend/src/lib/components/projects/SelectProject.svelte +++ b/frontend/src/lib/components/projects/SelectProject.svelte @@ -1,10 +1,7 @@

Projects

    - {#if projects} - {#each projects as project} - + {#if $projects} + {#each $projects as project} + {/each} {/if}
@@ -66,10 +23,10 @@ id="add" tabindex="0" role="button" - on:click={createProject} + on:click={Project.create} on:keydown={(e) => { if (e.key === 'Enter') { - createProject(); + Project.create(); } }} >