diff --git a/frontend/src/api/cards.ts b/frontend/src/api/cards.ts deleted file mode 100644 index f442ae5..0000000 --- a/frontend/src/api/cards.ts +++ /dev/null @@ -1,104 +0,0 @@ -import type TagValue from '$lib/types/TagValue'; -import type Card from '$lib/types/Card'; -import api, { processError } from '$lib/utils/api'; -import status from '$lib/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/api/projects.ts b/frontend/src/api/projects.ts deleted file mode 100644 index 23a1cbf..0000000 --- a/frontend/src/api/projects.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type Card from '$lib/types/Card'; -import type Project from '$lib/types/Project'; -import api, { processError } from '$lib/utils/api'; -import { parseCards } from '$lib/utils/parser'; -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/api/tags.ts b/frontend/src/api/tags.ts deleted file mode 100644 index 0b582e8..0000000 --- a/frontend/src/api/tags.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type TagOption from '$lib/types/TagOption'; -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; -}