From f78ea94c69bf43b04232f4c0d867a15bd6f7cfb5 Mon Sep 17 00:00:00 2001 From: imsoohyeok <160010477+imsoohyeok@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:51:59 +0900 Subject: [PATCH] =?UTF-8?q?FE-52=20=20=E2=9C=A8=EC=97=90=ED=94=BC=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EB=AA=A9=EB=A1=9D=EC=A1=B0=ED=9A=8C=20API=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FE-52 feat: api schema 작성 * FE-52 ✨feat: getEpigrams api 작성 * FE-522 ✨fix: default export로 변경 * FE-52 ✨test: 테스트 코드 작성 * FE-52 ✨feat: BaseUrl, TeamID 상수 추가 및 axios baseTRL 수정 * FE-52 ✨fix: schema 및 apis 파일 수정 * FE-52 ✨test: 테스트 코드 삭제 * FE-52 ✨fix: .env파일 생성 및 BaseURL 수정 * FE-52 ✨fix: limit 타입 수정(optional 삭제) * FE-52 ✨text: 테 테스트코드 삭제 * FE-52 ✨fix: api GET요청 주소 수정('epigrams' -> '/epigrams') --- src/apis/.http | 0 src/apis/getEpigrams.ts | 12 ++++++++++++ src/schema/epigrams.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/apis/.http create mode 100644 src/apis/getEpigrams.ts create mode 100644 src/schema/epigrams.ts diff --git a/src/apis/.http b/src/apis/.http new file mode 100644 index 00000000..e69de29b diff --git a/src/apis/getEpigrams.ts b/src/apis/getEpigrams.ts new file mode 100644 index 00000000..9685bc60 --- /dev/null +++ b/src/apis/getEpigrams.ts @@ -0,0 +1,12 @@ +import { GetEpigramsParamsType, GetEpigramsResponseType, GetEpigramsResponse } from '@/schema/epigrams'; +import httpClient from '.'; + +const getEpigrams = async (params: GetEpigramsParamsType): Promise => { + const response = await httpClient.get(`/epigrams`, { params }); + + // 데이터 일치하는지 확인 + const parsedResponse = GetEpigramsResponse.parse(response.data); + return parsedResponse; +}; + +export default getEpigrams; diff --git a/src/schema/epigrams.ts b/src/schema/epigrams.ts new file mode 100644 index 00000000..46a7cb85 --- /dev/null +++ b/src/schema/epigrams.ts @@ -0,0 +1,33 @@ +import * as z from 'zod'; + +export const GetEpigramsParams = z.object({ + limit: z.number(), + cursor: z.number().optional(), + keyword: z.string().optional(), + writerId: z.number().optional(), +}); + +export const GetEpigramsResponse = z.object({ + totalCount: z.number(), + nextCursor: z.number(), + list: z.array( + z.object({ + likeCount: z.number(), + tags: z.array( + z.object({ + name: z.string(), + id: z.number(), + }), + ), + writerId: z.number(), + referenceUrl: z.string(), + referenceTitle: z.string(), + author: z.string(), + content: z.string(), + id: z.number(), + }), + ), +}); + +export type GetEpigramsParamsType = z.infer; +export type GetEpigramsResponseType = z.infer;