diff --git a/frontend/src/components/project/card/modal_tags.svelte b/frontend/src/components/project/card/modal_tags.svelte deleted file mode 100644 index 01ba14d..0000000 --- a/frontend/src/components/project/card/modal_tags.svelte +++ /dev/null @@ -1,21 +0,0 @@ - - - - {#if card.tags} - {#each Object.values($projectTags) as projectTag} - t.tag_id === projectTag.id)} - bind:projectTag - {card} - /> - {/each} - {/if} - -
diff --git a/frontend/src/lib/api/cards.ts b/frontend/src/lib/api/cards.ts new file mode 100644 index 0000000..aeb8387 --- /dev/null +++ b/frontend/src/lib/api/cards.ts @@ -0,0 +1,103 @@ +import type { Card, TagValue } from '../stores/interfaces'; +import api, { processError } from '../utils/api'; +import status from '../utils/status'; + +export async function newCardApi(projectId: number, tags: TagValue[]): Promise { + const response = await api.post(`/v1/cards`, { + project_id: projectId, + title: 'Untitled', + content: '' + }); + + if (response.status !== status.Created) { + processError(response, 'Failed to create card'); + return Promise.reject(); + } + + const id: number = response.data.id; + + const consistant_tags = []; + + for (const tag of tags) { + if ((tag.option_id === -1 && tag.value == '') || tag.tag_id === -1) continue; + await createCardTagApi(id, tag.tag_id, tag.option_id, tag.value); + consistant_tags.push({ ...tag, card_id: id }); + } + + return { + id: id, + project_id: projectId, + title: 'Untitled', + content: '', + tags: consistant_tags + }; +} + +export async function updateCardApi(card: Card): Promise { + const response = await api.put(`/v1/cards/${card.id}`, { + project_id: card.project_id, + title: card.title, + content: card.content + }); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to update card'); + return false; + } + + return true; +} + +export async function deleteCardApi(cardID: number): Promise { + const response = await api.delete(`/v1/cards/${cardID}`); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to delete card'); + return Promise.reject(); + } +} + +export async function createCardTagApi( + cardId: number, + tagId: number, + optionId: number | null, + value: string | null +): Promise { + const response = await api.post(`/v1/cards/${cardId}/tags/${tagId}`, { + option_id: optionId, + value: value + }); + + if (response.status !== status.Created) { + processError(response, 'Failed to create card tag'); + return false; + } + + return true; +} + +export async function deleteCardTagApi(cardID: number, tagID: number): Promise { + const response = await api.delete(`/v1/cards/${cardID}/tags/${tagID}`); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to delete tag'); + return Promise.reject(); + } +} + +export async function updateCardTagApi( + cardID: number, + tagID: number, + option_id: number | null, + value: string | null +): Promise { + const response = await api.put(`/v1/cards/${cardID}/tags/${tagID}`, { + option_id: option_id == -1 ? null : option_id, + value: value == '' ? null : value + }); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to update card tag'); + return Promise.reject(); + } +} diff --git a/frontend/src/lib/api/projects.ts b/frontend/src/lib/api/projects.ts new file mode 100644 index 0000000..44160cf --- /dev/null +++ b/frontend/src/lib/api/projects.ts @@ -0,0 +1,25 @@ +import { parseCards, type Card, type Project } from '$lib/stores/interfaces'; +import api, { processError } from '$lib/utils/api'; +import status from '$lib/utils/status'; + +export async function getProjectAPI(projectId: number): Promise { + const response = await api.get(`/v1/projects/${projectId}`); + + if (response.status !== status.OK) { + processError(response, 'Failed to fetch project'); + return Promise.reject(); + } + + return response.data; +} + +export async function getProjectCardsAPI(projectId: number): Promise { + const response = await api.get(`/v1/projects/${projectId}/cards`); + + if (response.status !== status.OK) { + processError(response, 'Failed to fetch cards'); + return Promise.reject(); + } + + return parseCards(response.data); +} diff --git a/frontend/src/lib/api/tags.ts b/frontend/src/lib/api/tags.ts new file mode 100644 index 0000000..07cbd8f --- /dev/null +++ b/frontend/src/lib/api/tags.ts @@ -0,0 +1,17 @@ +import type { MeTag, TagOption } from '$lib/stores/interfaces'; +import api, { processError } from '$lib/utils/api'; +import status from '$lib/utils/status'; + +export async function updateTagAPI(option: TagOption): Promise { + const response = + option.value === '' + ? await api.delete(`/v1/tags/${option.tag_id}/options/${option.id}`) + : await api.put(`/v1/tags/${option.tag_id}/options/${option.id}`, option); + + if (response.status !== status.NoContent) { + processError(response, 'Failed to update tag option'); + return false; + } + + return true; +} diff --git a/frontend/src/components/icons/addIcon.svelte b/frontend/src/lib/components/icons/addIcon.svelte similarity index 100% rename from frontend/src/components/icons/addIcon.svelte rename to frontend/src/lib/components/icons/addIcon.svelte diff --git a/frontend/src/components/icons/chevron-right-svgrepo-com.svg b/frontend/src/lib/components/icons/chevron-right-svgrepo-com.svg similarity index 100% rename from frontend/src/components/icons/chevron-right-svgrepo-com.svg rename to frontend/src/lib/components/icons/chevron-right-svgrepo-com.svg diff --git a/frontend/src/components/icons/closeIcon.svelte b/frontend/src/lib/components/icons/closeIcon.svelte similarity index 100% rename from frontend/src/components/icons/closeIcon.svelte rename to frontend/src/lib/components/icons/closeIcon.svelte diff --git a/frontend/src/components/icons/editIcon.svelte b/frontend/src/lib/components/icons/editIcon.svelte similarity index 100% rename from frontend/src/components/icons/editIcon.svelte rename to frontend/src/lib/components/icons/editIcon.svelte diff --git a/frontend/src/components/icons/menu_opener.svelte b/frontend/src/lib/components/icons/menu_opener.svelte similarity index 100% rename from frontend/src/components/icons/menu_opener.svelte rename to frontend/src/lib/components/icons/menu_opener.svelte diff --git a/frontend/src/components/icons/trashIcon.svelte b/frontend/src/lib/components/icons/trashIcon.svelte similarity index 100% rename from frontend/src/components/icons/trashIcon.svelte rename to frontend/src/lib/components/icons/trashIcon.svelte diff --git a/frontend/src/components/icons/viewIcon.svelte b/frontend/src/lib/components/icons/viewIcon.svelte similarity index 100% rename from frontend/src/components/icons/viewIcon.svelte rename to frontend/src/lib/components/icons/viewIcon.svelte diff --git a/frontend/src/components/project/card/card.svelte b/frontend/src/lib/components/project/card/card.svelte similarity index 73% rename from frontend/src/components/project/card/card.svelte rename to frontend/src/lib/components/project/card/card.svelte index 18fe130..8dab445 100644 --- a/frontend/src/components/project/card/card.svelte +++ b/frontend/src/lib/components/project/card/card.svelte @@ -1,7 +1,7 @@ diff --git a/frontend/src/components/project/card/modal_tag/modal_tag_title.svelte b/frontend/src/lib/components/project/card/modal_tag/modal_tag_title.svelte similarity index 88% rename from frontend/src/components/project/card/modal_tag/modal_tag_title.svelte rename to frontend/src/lib/components/project/card/modal_tag/modal_tag_title.svelte index 41d6da5..2fa0bc2 100644 --- a/frontend/src/components/project/card/modal_tag/modal_tag_title.svelte +++ b/frontend/src/lib/components/project/card/modal_tag/modal_tag_title.svelte @@ -1,10 +1,10 @@ @@ -127,7 +127,7 @@ {option.value} diff --git a/frontend/src/lib/components/project/card/modal_tags.svelte b/frontend/src/lib/components/project/card/modal_tags.svelte new file mode 100644 index 0000000..7d4c9e6 --- /dev/null +++ b/frontend/src/lib/components/project/card/modal_tags.svelte @@ -0,0 +1,17 @@ + + + + {#if card.tags} + {#each Object.values($ProjectTags) as projectTag} + t.tag_id === projectTag.id)} {projectTag} {card} /> + {/each} + {/if} + +
diff --git a/frontend/src/components/project/column.svelte b/frontend/src/lib/components/project/column.svelte similarity index 98% rename from frontend/src/components/project/column.svelte rename to frontend/src/lib/components/project/column.svelte index ff94904..2f4b172 100644 --- a/frontend/src/components/project/column.svelte +++ b/frontend/src/lib/components/project/column.svelte @@ -1,12 +1,12 @@