Skip to content

Commit

Permalink
Merge branch 'main' into epic/FE-13--main-page
Browse files Browse the repository at this point in the history
  • Loading branch information
newjinlee committed Aug 1, 2024
2 parents f54b0d3 + 0accbb8 commit ea71821
Show file tree
Hide file tree
Showing 65 changed files with 2,310 additions and 86 deletions.
3 changes: 3 additions & 0 deletions public/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/icon/cancelIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/likeIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/meatballIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/none-epi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/placeLink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions src/apis/epigram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import axios, { AxiosError } from 'axios';
import { GetEpigramResponseType, EpigramRequestType } from '@/schema/epigram';
import { DeleteEpigramType } from '@/types/epigram.types';
import { AddEpigramResponseType, EditEpigramRequestType } from '@/schema/addEpigram';
import httpClient from '.';

export const getEpigram = async (request: EpigramRequestType): Promise<GetEpigramResponseType> => {
const { id } = request;

if (id === undefined) {
throw new Error('Epigram ID가 제공되지 않았습니다.');
}

try {
const response = await httpClient.get(`/epigrams/${id}`);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response) {
throw new Error(`API 에러: ${axiosError.response.status}`);
} else if (axiosError.request) {
throw new Error('서버로부터 응답을 받지 못했습니다.');
} else {
throw new Error('요청 설정 중 오류가 발생했습니다.');
}
} else {
throw new Error('예상치 못한 오류가 발생했습니다.');
}
}
};

export const deleteEpigram = async (id: number): Promise<DeleteEpigramType> => {
const response = await httpClient.delete(`/epigrams/${id}`);
return response.data;
};

// NOTE: 에피그램 수정 api 함수
export const patchEpigram = async (request: EditEpigramRequestType): Promise<AddEpigramResponseType> => {
const { id, ...data } = request;
const response = await httpClient.patch(`/epigrams/${id}`, data);
return response.data;
};

export const toggleEpigramLike = async (request: EpigramRequestType): Promise<GetEpigramResponseType> => {
const { id } = request;

if (id === undefined) {
throw new Error('Epigram ID가 제공되지 않았습니다.');
}

try {
const response = await httpClient.post(`/epigrams/${id}/like`);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response?.status === 400) {
// 이미 좋아요를 눌렀다면, 좋아요 취소 요청을 보냅니다.
const response = await httpClient.delete(`/epigrams/${id}/like`);
return response.data;
}
// 그 외의 에러 처리
if (axiosError.response) {
throw new Error(`API 에러: ${axiosError.response.status}`);
} else if (axiosError.request) {
throw new Error('서버로부터 응답을 받지 못했습니다.');
} else {
throw new Error('요청 설정 중 오류가 발생했습니다.');
}
} else {
throw new Error('예상치 못한 오류가 발생했습니다.');
}
}
};
8 changes: 8 additions & 0 deletions src/apis/epigramComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export const getEpigramComments = async (params: CommentRequestType): Promise<Co
}
};

export const getMyEpigramComments = async (params: CommentRequestType): Promise<CommentResponseType> => {
const { id, ...restParams } = params;
const response = await httpClient.get(`/users/${id}/comments`, {
params: restParams,
});
return response.data;
};

export const postComment = async (commentData: PostCommentRequest) => {
const response = await httpClient.post('/comments', commentData);
return response.data;
Expand Down
11 changes: 11 additions & 0 deletions src/apis/postGoogleOauth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import httpClient from '.';

const postGoogleOauth = async (code: string) => {
const response = await httpClient.post('/auth/signIn/GOOGLE', {
redirectUri: process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI,
token: code,
});
return response.data;
};

export default postGoogleOauth;
12 changes: 12 additions & 0 deletions src/apis/postNaverOauth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import httpClient from '.';

const postNaverOauth = async (code: string, state: string) => {
const response = await httpClient.post('/auth/signIn/NAVER', {
state,
redirectUri: process.env.NEXT_PUBLIC_NAVER_REDIRECT_URI,
token: code,
});
return response.data;
};

export default postNaverOauth;
51 changes: 48 additions & 3 deletions src/apis/queries.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { createQueryKeyStore } from '@lukemorales/query-key-factory';
import { GetUserRequestType } from '@/schema/user';
import { EpigramRequestType } from '@/schema/epigram';
import { CommentRequestType } from '@/schema/comment';
import { GetMonthlyEmotionLogsRequestType } from '@/schema/emotion';
import { getMe, getUser } from './user';
import { GetEpigramsParamsType } from '@/schema/epigrams';
import { getMe, getUser, getMyContentCount } from './user';
import { getEpigram } from './epigram';
import { getEpigramComments, getMyEpigramComments } from './epigramComment';
import getMonthlyEmotionLogs from './emotion';
import getEpigrams from './getEpigrams';

const quries = createQueryKeyStore({
const queries = createQueryKeyStore({
user: {
getMe: () => ({
queryKey: ['getMe'],
Expand All @@ -14,6 +20,45 @@ const quries = createQueryKeyStore({
queryKey: [request],
queryFn: () => getUser(request),
}),
getMyContentCount: (request: GetUserRequestType) => ({
queryKey: ['getMyContentCount', request],
queryFn: () => getMyContentCount(request),
}),
},
// NOTE: Epigram 관련 query함수
epigram: {
getEpigram: (request: EpigramRequestType) => ({
queryKey: ['epigram', request.id, request],
queryFn: () => {
if (request.id === undefined) {
throw new Error('Epigram ID가 제공되지 않았습니다.');
}
return getEpigram(request);
},
enabled: request.id !== undefined,
}),
},
epigramComment: {
getComments: (request: CommentRequestType) => ({
queryKey: ['epigramComments', request],
queryFn: () => getEpigramComments(request),
}),
getMyComments: (request: CommentRequestType) => ({
queryKey: ['myEpigramComments', request],
queryFn: () => getMyEpigramComments(request),
}),
},
emotion: {
getMonthlyEmotionLogs: (request: GetMonthlyEmotionLogsRequestType) => ({
queryKey: ['getMonthlyEmotionLogs', request],
queryFn: () => getMonthlyEmotionLogs(request),
}),
},
epigrams: {
getEpigrams: (request: GetEpigramsParamsType) => ({
queryKey: ['getEpigrams', request],
queryFn: () => getEpigrams(request),
}),
},
emotion: {
getMonthlyEmotionLogs: (request: GetMonthlyEmotionLogsRequestType) => ({
Expand All @@ -23,4 +68,4 @@ const quries = createQueryKeyStore({
},
});

export default quries;
export default queries;
Loading

0 comments on commit ea71821

Please sign in to comment.