From 019992bcad75a94c4ac271538d8824dff17e41af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=EC=A0=95=EC=9A=B0?= Date: Fri, 19 Apr 2024 17:59:43 +0900 Subject: [PATCH 1/2] feat: implement assert util function --- src/utils/assert.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/utils/assert.ts diff --git a/src/utils/assert.ts b/src/utils/assert.ts new file mode 100644 index 00000000..a75af4fa --- /dev/null +++ b/src/utils/assert.ts @@ -0,0 +1,9 @@ +export function assert(condition: unknown, error: Error | string = new Error()): asserts condition { + if (!condition) { + if (typeof error === 'string') { + throw new Error(error) + } else { + throw error + } + } +} From 123c0593966fbbd578a2e88bae320820100f5989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=EC=A0=95=EC=9A=B0?= Date: Fri, 19 Apr 2024 18:11:41 +0900 Subject: [PATCH 2/2] feat: implement api endpoints --- src/apis/api-endpoint.ts | 67 ++++++++++++++++++++++++++++++++++++++++ src/apis/server-env.ts | 9 ++++++ 2 files changed, 76 insertions(+) create mode 100644 src/apis/api-endpoint.ts create mode 100644 src/apis/server-env.ts diff --git a/src/apis/api-endpoint.ts b/src/apis/api-endpoint.ts new file mode 100644 index 00000000..603e9c09 --- /dev/null +++ b/src/apis/api-endpoint.ts @@ -0,0 +1,67 @@ +import { ServerEnv } from '@/apis/server-env' + +enum Method { + GET = 'GET', + POST = 'POST', + PATCH = 'PATCH', + DELETE = 'DELETE', +} + +const baseUrl = ServerEnv.apiUrl() + +export const API_ENDPOINT = { + // 퀴즈 + quiz: { + getTodayQuiz: () => ({ + url: `${baseUrl}/todayQuiz`, + method: Method.GET, + }), + getBookmarks: () => ({ + url: `${baseUrl}/bookmark`, + method: Method.GET, + }), + postBookmark: (quizId: number) => ({ + url: `${baseUrl}/bookmark/${quizId}`, + method: Method.POST, + }), + deleteBookmark: (quizId: number) => ({ + url: `${baseUrl}/bookmark/${quizId}`, + method: Method.DELETE, + }), + }, + + // 문서 관련 API + document: {}, + + // 재화 관련 API + star: { + getStarEvent: () => ({ + url: `${baseUrl}/starEvent`, + method: Method.GET, + }), + }, + + // 사용자 관련 API + user: { + getUser: () => ({ + url: `${baseUrl}/user`, + method: Method.GET, + }), + }, + + // auth 관련 API + auth: { + signIn: () => ({ + url: `${baseUrl}/auth`, + method: Method.POST, + }), + verifyEmail: () => ({ + url: `${baseUrl}/auth/verification`, + method: Method.POST, + }), + checkVerification: () => ({ + url: `${baseUrl}/auth/verification/check`, + method: Method.POST, + }), + }, +} diff --git a/src/apis/server-env.ts b/src/apis/server-env.ts new file mode 100644 index 00000000..24c2dc52 --- /dev/null +++ b/src/apis/server-env.ts @@ -0,0 +1,9 @@ +import assert from 'assert' + +export const ServerEnv = { + apiUrl: () => { + assert(process.env.NEXT_PUBLIC_API_URL, 'NEXT_PUBLIC_API_URL 값이 .env.local에 없습니다.') + + return process.env.NEXT_PUBLIC_API_URL + }, +}