-
Notifications
You must be signed in to change notification settings - Fork 1
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
FE-51 🔀 공용 API 머지 요청 #92
Changes from 21 commits
f78ea94
bdea96c
40f3f02
7e79878
a817643
6d751ab
f878400
88f546b
7bb3b33
1b906fd
4c43bc0
b52c4f5
e519107
7d15bf7
63a2a2f
febc0c3
8ff482f
16f7b26
b17db48
93b7009
9a5a515
28c185d
1c80963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AddEpigramRequestType, AddEpigramResponseType } from '@/schema/addEpigram'; | ||
import httpClient from '.'; | ||
|
||
const postEpigram = async (request: AddEpigramRequestType): Promise<AddEpigramResponseType> => { | ||
const response = await httpClient.post<AddEpigramResponseType>('/epigrams', request); | ||
return response.data; | ||
}; | ||
|
||
export default postEpigram; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PostSigninRequestType, PostSigninResponseType } from '@/schema/auth'; | ||
import httpClient from '.'; | ||
|
||
const postSignin = async (request: PostSigninRequestType): Promise<PostSigninResponseType> => { | ||
const response = await httpClient.post('/auth/signIn', request); | ||
return response.data; | ||
}; | ||
|
||
export default postSignin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import httpClient from '@/apis/index'; | ||
import { CommentRequestSchema, CommentRequestType, CommentResponseSchema, CommentResponseType } from '@/schema/comment'; | ||
import { PostCommentRequest, PatchCommentRequest } from '@/types/epigram.types'; | ||
|
||
export const getEpigramComments = async (params: CommentRequestType): Promise<CommentResponseType> => { | ||
try { | ||
// 요청 파라미터 유효성 검사 | ||
const validatedParams = CommentRequestSchema.parse(params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다 |
||
|
||
const { id, limit, cursor } = validatedParams; | ||
|
||
// NOTE: URL의 쿼리 문자열을 사용 | ||
// NOTE : cursor값이 있다면 ?limit=3&cursor=100, 없다면 ?limit=3,(숫자는 임의로 지정한 것) | ||
const queryParams = new URLSearchParams({ | ||
limit: limit.toString(), | ||
...(cursor !== undefined && { cursor: cursor.toString() }), | ||
}); | ||
|
||
const response = await httpClient.get<CommentResponseType>(`/epigrams/${id}/comments?${queryParams.toString()}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const response = await httpClient.get<CommentResponseType>(`/epigrams/${id}/comments`,{params:{ limit, cursor}});
|
||
|
||
// 응답 데이터 유효성 검사 | ||
const validatedData = CommentResponseSchema.parse(response.data); | ||
|
||
return validatedData; | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
throw new Error(`댓글을 불러오는데 실패했습니다: ${error.message}`); | ||
} | ||
throw error; | ||
} | ||
}; | ||
|
||
export const postComment = async (commentData: PostCommentRequest) => { | ||
const response = await httpClient.post('/comments', commentData); | ||
return response.data; | ||
}; | ||
|
||
export const patchComment = async (commentId: number, commentData: PatchCommentRequest) => { | ||
const response = await httpClient.patch(`/comments/${commentId}`, commentData); | ||
return response.data; | ||
}; | ||
|
||
export const deleteComment = async (commentId: number) => { | ||
const response = await httpClient.delete(`/comments/${commentId}`); | ||
return response.data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { EmotionType } from '@/types/emotion'; | ||
import type { GetEmotionResponseType } from '@/schema/emotion'; | ||
import { translateEmotionToKorean } from '@/utils/emotionMap'; | ||
import httpClient from '.'; | ||
import { getMe } from './user'; | ||
|
||
const getEmotion = async (): Promise<EmotionType | null> => { | ||
const user = await getMe(); | ||
if (!user) { | ||
throw new Error('로그인이 필요합니다.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactoring const user = await getMe();
if (!user) {
throw new Error('로그인이 필요합니다.');
} 이거 커스텀훅으로! |
||
|
||
const response = await httpClient.get<GetEmotionResponseType>('/emotionLogs/today', { | ||
params: { userId: user.id }, | ||
}); | ||
|
||
if (response.status === 204) { | ||
return null; // No content | ||
} | ||
|
||
const koreanEmotion = translateEmotionToKorean(response.data.emotion); | ||
return koreanEmotion; | ||
}; | ||
|
||
export default getEmotion; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { GetEpigramsParamsType, GetEpigramsResponseType, GetEpigramsResponse } from '@/schema/epigrams'; | ||
import httpClient from '.'; | ||
|
||
const getEpigrams = async (params: GetEpigramsParamsType): Promise<GetEpigramsResponseType> => { | ||
const response = await httpClient.get(`/epigrams`, { params }); | ||
|
||
// 데이터 일치하는지 확인 | ||
const parsedResponse = GetEpigramsResponse.parse(response.data); | ||
return parsedResponse; | ||
}; | ||
|
||
export default getEpigrams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
존재의미?