From 68da8ce1b1e360987f168a348603c02fdd0f4856 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 15:41:40 +0900 Subject: [PATCH 01/11] fix: fix delete user error --- .../services/lecture/taken-lecture.command.ts | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app/business/services/lecture/taken-lecture.command.ts b/app/business/services/lecture/taken-lecture.command.ts index 477ed4f0..18dd2853 100644 --- a/app/business/services/lecture/taken-lecture.command.ts +++ b/app/business/services/lecture/taken-lecture.command.ts @@ -5,6 +5,7 @@ import { httpErrorHandler } from '@/app/utils/http/http-error-handler'; import { BadRequestError } from '@/app/utils/http/http-error'; import { revalidateTag } from 'next/cache'; import { TAG } from '@/app/utils/http/tag'; +import { cookies } from 'next/headers'; export const registerUserGrade = async (prevState: FormState, formData: FormData) => { const parsingText = await parsePDFtoText(formData); @@ -43,29 +44,34 @@ export const parsePDFtoText = async (formData: FormData) => { }; export const deleteTakenLecture = async (lectureId: number) => { - try { - const response = await fetch(API_PATH.takenLectures, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ lectureId }), - }); - const result = await response.json(); - httpErrorHandler(response, result); - } catch (error) { - if (error instanceof BadRequestError) { - return { - isSuccess: false, - }; - } else { - throw error; - } + // try { + const response = await fetch(`${API_PATH.takenLectures}/${lectureId}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${cookies().get('accessToken')?.value}`, + }, + }); + // fetch 가 수정되면서 바꿀 예정이므로 현재는 작동만 되도록 수정 + if (response.ok) { + return { + isSuccess: true, + }; + } else { + return { + isSuccess: false, + }; } + // } catch (error) { + // if (error instanceof BadRequestError) { + // return { + // isSuccess: false, + // }; + // } else { + // throw error; + // } + // } revalidateTag(TAG.GET_TAKEN_LECTURES); - return { - isSuccess: true, - }; }; export const addTakenLecture = async (lectureId: number) => { From a983f79b2a3dbfe99323728833e45980932a51a3 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 16:52:00 +0900 Subject: [PATCH 02/11] =?UTF-8?q?chore:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/business/services/lecture/taken-lecture.query.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/business/services/lecture/taken-lecture.query.ts b/app/business/services/lecture/taken-lecture.query.ts index cb09092e..968e84bd 100644 --- a/app/business/services/lecture/taken-lecture.query.ts +++ b/app/business/services/lecture/taken-lecture.query.ts @@ -4,10 +4,10 @@ import { cookies } from 'next/headers'; export interface TakenLecturesResponse { totalCredit: number; - takenLectures: TakenLectrueInfoResponse[]; + takenLectures: TakenLectureInfoResponse[]; } -interface TakenLectrueInfoResponse { +interface TakenLectureInfoResponse { [index: string]: string | number; id: number; year: string; From 5757a7e9932307e5212e852de5a946137027fa55 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 18:42:54 +0900 Subject: [PATCH 03/11] fix: add server action async --- app/business/services/auth.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/business/services/auth.ts b/app/business/services/auth.ts index 719f2c8b..1758b66d 100644 --- a/app/business/services/auth.ts +++ b/app/business/services/auth.ts @@ -1,6 +1,7 @@ 'use server'; import { cookies } from 'next/headers'; -export const getToken = (): string | undefined => { +export const getToken = async (): Promise => { return cookies().get('accessToken')?.value; }; +// server action은 async를 써야함 From 3d39ad70f13818b3a870376902513e96d84c9139 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 18:44:50 +0900 Subject: [PATCH 04/11] fix: fix taken lecture command --- .../services/lecture/taken-lecture.command.ts | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/app/business/services/lecture/taken-lecture.command.ts b/app/business/services/lecture/taken-lecture.command.ts index 18dd2853..48ccc8b8 100644 --- a/app/business/services/lecture/taken-lecture.command.ts +++ b/app/business/services/lecture/taken-lecture.command.ts @@ -6,6 +6,7 @@ import { BadRequestError } from '@/app/utils/http/http-error'; import { revalidateTag } from 'next/cache'; import { TAG } from '@/app/utils/http/tag'; import { cookies } from 'next/headers'; +import { getToken } from '../auth'; export const registerUserGrade = async (prevState: FormState, formData: FormData) => { const parsingText = await parsePDFtoText(formData); @@ -52,8 +53,10 @@ export const deleteTakenLecture = async (lectureId: number) => { Authorization: `Bearer ${cookies().get('accessToken')?.value}`, }, }); - // fetch 가 수정되면서 바꿀 예정이므로 현재는 작동만 되도록 수정 + // http error handling에서 result가 필수값이므로 사용할 수 없음 + // 하지만 fetch 가 수정되면서 바꿀 예정이므로 현재는 작동만 되도록 if (response.ok) { + revalidateTag(TAG.GET_TAKEN_LECTURES); return { isSuccess: true, }; @@ -71,38 +74,33 @@ export const deleteTakenLecture = async (lectureId: number) => { // throw error; // } // } - revalidateTag(TAG.GET_TAKEN_LECTURES); }; export const addTakenLecture = async (lectureId: number) => { - try { - const response = await fetch(API_PATH.takenLectures, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ lectureId }), - }); - const result = await response.json(); - httpErrorHandler(response, result); - } catch (error) { - if (error instanceof BadRequestError) { - return { - isSuccess: false, - isFailure: true, - validationError: {}, - message: '과목 추가에 실패했습니다', - }; - } else { - throw error; - } + const token = await getToken(); + const response = await fetch(API_PATH.takenLectures, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ lectureId }), + }); + // delete taken lecture과 비슷한 이유로 코드 수정 + if (response.ok) { + revalidateTag(TAG.GET_TAKEN_LECTURES); + return { + isSuccess: true, + isFailure: false, + validationError: {}, + message: '과목 추가에 성공했습니다', + }; + } else { + return { + isSuccess: false, + isFailure: true, + validationError: {}, + message: '과목 추가에 실패했습니다', + }; } - - revalidateTag(TAG.GET_TAKEN_LECTURES); - return { - isSuccess: true, - isFailure: false, - validationError: {}, - message: '과목 추가에 성공했습니다', - }; }; From 87ca5d7841546ebfb8b02e0989ebdfa55ef3118b Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 19:01:54 +0900 Subject: [PATCH 05/11] chore: completion division -> complete division --- app/business/services/user/user.query.ts | 3 +- app/business/services/user/user.validation.ts | 4 +- app/mocks/data.mock.ts | 80 ++++++++++--------- .../user/user-info-card/user-info-content.tsx | 2 +- .../user-info-navigator.tsx | 2 +- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/app/business/services/user/user.query.ts b/app/business/services/user/user.query.ts index 2a16c823..f5a902e0 100644 --- a/app/business/services/user/user.query.ts +++ b/app/business/services/user/user.query.ts @@ -20,7 +20,7 @@ export async function auth(): Promise { try { - const response = await fetch(`${API_PATH.user}`, { + const response = await fetch(`${API_PATH.user}/me`, { headers: { Authorization: `Bearer ${cookies().get('accessToken')?.value}`, }, @@ -29,7 +29,6 @@ export async function fetchUser(): Promise Date: Sun, 16 Jun 2024 19:03:06 +0900 Subject: [PATCH 06/11] chore: modify lecture type --- app/mocks/db.mock.ts | 10 +++++----- app/store/querys/lecture.ts | 13 +++++-------- .../lecture-search/lecture-search-result.tsx | 8 ++++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/mocks/db.mock.ts b/app/mocks/db.mock.ts index c3cb4a90..1021baf2 100644 --- a/app/mocks/db.mock.ts +++ b/app/mocks/db.mock.ts @@ -1,4 +1,3 @@ -import { SearchLecturesResponse } from '../store/querys/lecture'; import { TakenLecturesResponse } from '../business/services/lecture/taken-lecture.query'; import { CreditResponse, ResultCategoryDetailResponse } from '../store/querys/result'; import { @@ -8,20 +7,21 @@ import { InitUserInfoResponse, } from '../business/services/user/user.type'; import { takenLectures, credits, searchLectures, userInfo, users, resultCategoryDetailInfo } from './data.mock'; +import { SearchedLectureInfoResponse } from '../store/querys/lecture'; interface MockDatabaseState { takenLectures: TakenLecturesResponse; resultCategoryDetailInfo: ResultCategoryDetailResponse; credits: CreditResponse[]; users: SignUpRequestBody[]; - searchLectures: SearchLecturesResponse; + searchLectures: SearchedLectureInfoResponse[]; userInfo: UserInfoResponse; } type MockDatabaseAction = { reset: () => void; getTakenLectures: () => TakenLecturesResponse; - getSearchLectures: () => SearchLecturesResponse; + getSearchLectures: () => SearchedLectureInfoResponse[]; addTakenLecture: (lectureId: number) => boolean; deleteTakenLecture: (lectureId: number) => boolean; createUser: (user: SignUpRequestBody) => boolean; @@ -49,7 +49,7 @@ export const mockDatabase: MockDatabaseAction = { return false; }, addTakenLecture: (lectureId) => { - const lecture = mockDatabaseStore.searchLectures.lectures.find((lecture) => lecture.id === lectureId); + const lecture = mockDatabaseStore.searchLectures.find((lecture) => lecture.id === lectureId); if (!lecture) { return false; } @@ -85,7 +85,7 @@ export const mockDatabase: MockDatabaseAction = { return { studentNumber: '', studentName: null, - completionDivision: null, + completeDivision: null, totalCredit: null, takenCredit: null, graduated: null, diff --git a/app/store/querys/lecture.ts b/app/store/querys/lecture.ts index 5c4957bf..c2acb84c 100644 --- a/app/store/querys/lecture.ts +++ b/app/store/querys/lecture.ts @@ -7,7 +7,7 @@ import { API_PATH } from '@/app/business/api-path'; import { getToken } from '@/app/business/services/auth'; import { LectureInfoResponse } from './result'; -export type SearchedLectureInfoResponse = LectureInfoResponse & { isTaken: boolean }; +export type SearchedLectureInfoResponse = LectureInfoResponse & { taken: boolean; revoked: boolean }; export const useFetchSearchLecture = () => { const searchWord = useAtomValue(searchWordAtom); @@ -20,15 +20,12 @@ export const useFetchSearchLecture = () => { }); }; -export interface SearchLecturesResponse { - lectures: SearchedLectureInfoResponse[]; -} - export const fetchSearchLectures = async (type: string, keyword: string) => { - const response = await axios(`${API_PATH.lectures}?type=${type}&&keyword=${keyword}`, { + const token = await getToken(); + const response = await axios(`${API_PATH.lectures}?type=${type}&&keyword=${keyword}`, { headers: { - Authorization: `Bearer ${getToken()}`, + Authorization: `Bearer ${token}`, }, }); - return response.data.lectures; + return response.data; }; diff --git a/app/ui/lecture/lecture-search/lecture-search-result.tsx b/app/ui/lecture/lecture-search/lecture-search-result.tsx index 87b67cf2..99e16488 100644 --- a/app/ui/lecture/lecture-search/lecture-search-result.tsx +++ b/app/ui/lecture/lecture-search/lecture-search-result.tsx @@ -7,8 +7,8 @@ import { useFetchSearchLecture } from '@/app/store/querys/lecture'; export default function LectureSearchResult() { const { data } = useFetchSearchLecture(); - const renderAddActionButton = (item: SearchedLectureInfoResponse, isTaken: boolean) => { - return ; + const renderAddActionButton = (item: SearchedLectureInfoResponse, taken: boolean) => { + return ; }; const render = (item: SearchedLectureInfoResponse, index: number) => { @@ -17,11 +17,11 @@ export default function LectureSearchResult() { {Object.keys(searchLectureItem).map((key, index) => { - if (key === 'id' || key === 'isTaken') return null; + if (key === 'id' || key === 'taken' || key === 'revoked') return null; return {searchLectureItem[key]}; })} {renderAddActionButton ? ( - {renderAddActionButton(searchLectureItem, item.isTaken)} + {renderAddActionButton(searchLectureItem, item.taken)} ) : null} From e6540341d1ff4ffc1cada7a393fb48f1da5a4a7c Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 19:04:03 +0900 Subject: [PATCH 07/11] style: modify lecture search drawer style --- app/ui/lecture/lecture-search/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ui/lecture/lecture-search/index.tsx b/app/ui/lecture/lecture-search/index.tsx index fa14cdf7..e94c4626 100644 --- a/app/ui/lecture/lecture-search/index.tsx +++ b/app/ui/lecture/lecture-search/index.tsx @@ -26,7 +26,7 @@ export default function LectureSearch() { const searchable = searchWord.keyword && searchWord.keyword.length > 1; return ( -
+
{searchable ? ( From 36e16dd76f23a11647cba71ccf3c19d809588665 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 16 Jun 2024 19:07:43 +0900 Subject: [PATCH 08/11] feat: implement closed lecture --- app/ui/lecture/lecture-search/lecture-search-bar.tsx | 3 ++- app/ui/lecture/lecture-search/lecture-search-result.tsx | 2 +- app/ui/lecture/taken-lecture/delete-taken-lecture-button.tsx | 2 +- app/ui/view/molecule/list/list-row.tsx | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/ui/lecture/lecture-search/lecture-search-bar.tsx b/app/ui/lecture/lecture-search/lecture-search-bar.tsx index 96d6b7af..8404a791 100644 --- a/app/ui/lecture/lecture-search/lecture-search-bar.tsx +++ b/app/ui/lecture/lecture-search/lecture-search-bar.tsx @@ -38,7 +38,7 @@ export default function LectureSearchBar() {
-
+
+
※ 회색으로 표기된 과목은 폐강과목입니다
); diff --git a/app/ui/lecture/lecture-search/lecture-search-result.tsx b/app/ui/lecture/lecture-search/lecture-search-result.tsx index 99e16488..dcb3dcd6 100644 --- a/app/ui/lecture/lecture-search/lecture-search-result.tsx +++ b/app/ui/lecture/lecture-search/lecture-search-result.tsx @@ -14,7 +14,7 @@ export default function LectureSearchResult() { const render = (item: SearchedLectureInfoResponse, index: number) => { const searchLectureItem = item; return ( - + {Object.keys(searchLectureItem).map((key, index) => { if (key === 'id' || key === 'taken' || key === 'revoked') return null; diff --git a/app/ui/lecture/taken-lecture/delete-taken-lecture-button.tsx b/app/ui/lecture/taken-lecture/delete-taken-lecture-button.tsx index e451be5f..1c07d46c 100644 --- a/app/ui/lecture/taken-lecture/delete-taken-lecture-button.tsx +++ b/app/ui/lecture/taken-lecture/delete-taken-lecture-button.tsx @@ -43,7 +43,7 @@ export default function DeleteTakenLectureButton({ lectureId, onDelete }: Delete >