-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f78ea94
FE-52 ✨에피그램 목록조회 API (#34)
imsoohyeok bdea96c
Merge branch 'epic/FE-51--API' into merge/FE-51
newjinlee 40f3f02
Merge pull request #49 from epigram5-9/merge/FE-51
newjinlee 7e79878
FE-53 :sparkles: 감정이모티콘 저장 스키마 정의
newjinlee a817643
FE-53 :sparkles: 오늘의 감정 저장 api 생성
newjinlee 6d751ab
FE-53 :sparkles: getMe 함수를 사용해 로그인 상태 확인 기능 구현
newjinlee f878400
FE-53 :sparkles: 감정 한영 변환 함수
newjinlee 88f546b
FE-53 :sparkles: 감정 저장 후 토스트 알림 표시
newjinlee 7bb3b33
FE-53 :sparkles: 오늘의 감정 조회 api 생성
newjinlee 1b906fd
FE-53 :hammer: 감정 한영 변환 함수 추가
newjinlee 4c43bc0
FE-53 :sparkles: 오늘의 감정 스키마 추가 정의
newjinlee b52c4f5
FE-53 :sparkles: 오늘의 감정 조회 함수 적용
newjinlee e519107
FE-53 :truck: 오늘의 감정 type 이름 변경
newjinlee 7d15bf7
FE-53 :sparkles: useMutation 훅 사용
newjinlee 63a2a2f
FE-53 :memo: EmotionSelector 주석 추가
newjinlee febc0c3
FE-53 :fire: api 함수 에러 처리 부분 제거
newjinlee 8ff482f
FE-53 :hammer: useQuery를 사용해 오늘의 감정 조회
newjinlee 16f7b26
Merge pull request #60 from epigram5-9/feat/FE-53
newjinlee b17db48
FE-56 :sparkles: 댓글 수정 API (#84)
JeonYumin94 93b7009
FE-57 :sparkles: 댓글 삭제 API (#88)
JeonYumin94 9a5a515
FE-51 :twisted_rightwards_arrows: 공용 API 최신화 (#93)
JeonYumin94 28c185d
Merge branch 'main' into epic/FE-51--API
JeonYumin94 1c80963
FE-51 :twisted_rightwards_arrows: 공용 API 최신화 (충돌수정) (#98)
JeonYumin94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { EmotionType } from '@/types/emotion'; | ||
import type { PostEmotionRequestType, PostEmotionResponseType } from '@/schema/emotion'; | ||
import { translateEmotionToEnglish } from '@/utils/emotionMap'; | ||
import httpClient from '.'; | ||
import { getMe } from './user'; | ||
|
||
const postEmotion = async (emotion: EmotionType): Promise<PostEmotionResponseType> => { | ||
const user = await getMe(); | ||
if (!user) { | ||
throw new Error('로그인이 필요합니다.'); | ||
} | ||
|
||
const englishEmotion = translateEmotionToEnglish(emotion); | ||
const request: PostEmotionRequestType = { emotion: englishEmotion }; | ||
|
||
const response = await httpClient.post<PostEmotionResponseType>('/emotionLogs/today', { | ||
...request, | ||
userId: user.id, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
export default postEmotion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import type { GetUserReponseType, GetUserRequestType, PatchMeRequestType } from '@/schema/user'; | ||
import type { GetUserResponseType, GetUserRequestType, PatchMeRequestType } from '@/schema/user'; | ||
import httpClient from '.'; | ||
|
||
export const getMe = async (): Promise<GetUserReponseType> => { | ||
export const getMe = async (): Promise<GetUserResponseType> => { | ||
const response = await httpClient.get('/users/me'); | ||
return response.data; | ||
}; | ||
|
||
export const getUser = async (request: GetUserRequestType): Promise<GetUserReponseType> => { | ||
export const getUser = async (request: GetUserRequestType): Promise<GetUserResponseType> => { | ||
const { id } = request; | ||
const response = await httpClient.get(`/users/${id}`); | ||
return response.data; | ||
}; | ||
|
||
export const updateMe = async (request: PatchMeRequestType): Promise<GetUserReponseType> => { | ||
export const updateMe = async (request: PatchMeRequestType): Promise<GetUserResponseType> => { | ||
const response = await httpClient.patch('/users/me', { ...request }); | ||
return response.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 오늘의 감정을 선택하면 표시되는 toast입니다. | ||
* 감정을 확인하기 위해 마이페이지로 연결됩니다. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useToast } from '@/components/ui/use-toast'; | ||
import { ToastAction } from '@/components/ui/toast'; | ||
import { useRouter } from 'next/router'; | ||
|
||
interface EmotionSaveToastProps { | ||
iconType: string; | ||
} | ||
|
||
function EmotionSaveToast({ iconType }: EmotionSaveToastProps) { | ||
const { toast } = useToast(); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
toast({ | ||
title: '오늘의 감정이 저장되었습니다.', | ||
description: `오늘의 감정: ${iconType}`, | ||
action: ( | ||
<ToastAction altText='확인하기' onClick={() => router.push('/mypage')}> | ||
확인하기 | ||
</ToastAction> | ||
), | ||
}); | ||
}, [iconType, toast, router]); | ||
|
||
return null; | ||
} | ||
|
||
export default EmotionSaveToast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { deleteComment } from '@/apis/epigramComment'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
|
||
const useDeleteCommentMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (commentId: number) => deleteComment(commentId), | ||
onSuccess: () => { | ||
// 댓글 목록 쿼리 무효화 | ||
queryClient.invalidateQueries({ queryKey: ['epigramComments'] }); | ||
|
||
// 성공 메시지 표시 | ||
toast({ | ||
title: '댓글 삭제 성공', | ||
description: '댓글이 성공적으로 삭제되었습니다.', | ||
}); | ||
}, | ||
onError: (error) => { | ||
// 에러 메시지 표시 | ||
toast({ | ||
title: '댓글 삭제 실패', | ||
description: `댓글 삭제 중 오류가 발생했습니다: ${error instanceof Error ? error.message : '알 수 없는 오류'}`, | ||
variant: 'destructive', | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useDeleteCommentMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import getEmotion from '@/apis/getEmotion'; | ||
import { EmotionType } from '@/types/emotion'; | ||
|
||
const useGetEmotion = () => | ||
useQuery<EmotionType | null, Error>({ | ||
queryKey: ['emotion'], | ||
queryFn: getEmotion, | ||
}); | ||
|
||
export default useGetEmotion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { patchComment } from '@/apis/epigramComment'; | ||
import { PatchCommentRequest } from '@/types/epigram.types'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
|
||
const usePatchCommentMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: ({ commentId, ...commentData }: { commentId: number } & PatchCommentRequest) => patchComment(commentId, commentData), | ||
onSuccess: () => { | ||
// 댓글 목록 쿼리 무효화 | ||
queryClient.invalidateQueries({ queryKey: ['epigramComments'] }); | ||
|
||
// 성공 메시지 표시 | ||
toast({ | ||
title: '댓글 수정 성공', | ||
description: '댓글이 성공적으로 수정되었습니다.', | ||
}); | ||
}, | ||
onError: (error) => { | ||
// 에러 메시지 표시 | ||
toast({ | ||
title: '댓글 수정 실패', | ||
description: `댓글 수정 중 오류가 발생했습니다: ${error instanceof Error ? error.message : '알 수 없는 오류'}`, | ||
variant: 'destructive', | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
export default usePatchCommentMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import postEmotion from '@/apis/postEmotion'; | ||
import { EmotionType } from '@/types/emotion'; | ||
import { PostEmotionResponseType } from '@/schema/emotion'; | ||
|
||
const usePostEmotion = () => | ||
useMutation<PostEmotionResponseType, Error, EmotionType>({ | ||
mutationFn: postEmotion, | ||
}); | ||
|
||
export default usePostEmotion; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
좋습니다