Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement api endpoint #2

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/apis/api-endpoint.ts
Original file line number Diff line number Diff line change
@@ -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,
}),
},
}
9 changes: 9 additions & 0 deletions src/apis/server-env.ts
Original file line number Diff line number Diff line change
@@ -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
},
}
9 changes: 9 additions & 0 deletions src/utils/assert.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}