diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index df06c5f7f..e9ff0bd40 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -1,5 +1,5 @@ export { CATEGORY_API_URL, getCategoryList, postCategory, deleteCategory } from './categories'; -export { getTagList } from './tags'; +export { TAG_API_URL, getTagList } from './tags'; export { customFetch } from './customFetch'; export { QUERY_KEY } from './queryKeys'; export { @@ -8,6 +8,7 @@ export { SORTING_OPTIONS, DEFAULT_SORTING_OPTION, getTemplateList, + getTemplateExplore, getTemplate, postTemplate, editTemplate, @@ -25,3 +26,4 @@ export { getLoginState, checkName, } from './authentication'; +export { LIKE_API_URL, postLike, deleteLike } from './like'; diff --git a/frontend/src/api/like.ts b/frontend/src/api/like.ts new file mode 100644 index 000000000..86369b432 --- /dev/null +++ b/frontend/src/api/like.ts @@ -0,0 +1,28 @@ +import { HttpResponse } from 'msw'; + +import { END_POINTS } from '@/routes'; +import { LikeDeleteRequest, LikePostRequest } from '@/types'; + +import { customFetch } from './customFetch'; + +const API_URL = process.env.REACT_APP_API_URL; + +export const LIKE_API_URL = `${API_URL}${END_POINTS.LIKES}`; + +export const postLike = async ({ templateId }: LikePostRequest) => { + const response = await customFetch({ + method: 'POST', + url: `${LIKE_API_URL}/${templateId}`, + }); + + return response; +}; + +export const deleteLike = async ({ templateId }: LikeDeleteRequest) => { + const response = await customFetch({ + method: 'DELETE', + url: `${LIKE_API_URL}/${templateId}`, + }); + + return response; +}; diff --git a/frontend/src/api/templates.ts b/frontend/src/api/templates.ts index ae3651026..960b81e41 100644 --- a/frontend/src/api/templates.ts +++ b/frontend/src/api/templates.ts @@ -1,6 +1,7 @@ import { END_POINTS } from '@/routes'; import type { Template, + TemplateRequest, TemplateEditRequest, TemplateListResponse, TemplateUploadRequest, @@ -8,6 +9,7 @@ import type { CustomError, } from '@/types'; import { SortingOption } from '@/types'; + import { customFetch } from './customFetch'; const API_URL = process.env.REACT_APP_API_URL; @@ -40,12 +42,15 @@ export const getTemplateList = async ({ }: TemplateListRequest) => { const queryParams = new URLSearchParams({ keyword, - memberId: String(memberId), sort, page: page.toString(), size: size.toString(), }); + if (memberId) { + queryParams.append('memberId', memberId.toString()); + } + if (categoryId) { queryParams.append('categoryId', categoryId.toString()); } @@ -54,7 +59,7 @@ export const getTemplateList = async ({ queryParams.append('tagIds', tagIds.toString()); } - const url = `${TEMPLATE_API_URL}?${queryParams.toString()}`; + const url = `${TEMPLATE_API_URL}${memberId ? '/login' : ''}?${queryParams.toString()}`; const response = await customFetch({ url, @@ -71,6 +76,7 @@ export const getTemplateExplore = async ({ sort = DEFAULT_SORTING_OPTION.key, page = 1, size = PAGE_SIZE, + memberId, }: TemplateListRequest) => { const queryParams = new URLSearchParams({ sort, @@ -78,7 +84,7 @@ export const getTemplateExplore = async ({ size: size.toString(), }); - const url = `${TEMPLATE_API_URL}?${queryParams.toString()}`; + const url = `${TEMPLATE_API_URL}${memberId ? '/login' : ''}?${queryParams.toString()}`; const response = await customFetch({ url, @@ -91,9 +97,9 @@ export const getTemplateExplore = async ({ throw new Error(response.detail); }; -export const getTemplate = async (id: number) => { +export const getTemplate = async ({ id, memberId }: TemplateRequest) => { const response = await customFetch