-
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
Result fetch/#92 #95
Result fetch/#92 #95
Changes from 11 commits
a64aa6b
c2bf74a
27c0dbf
42a0e34
05062a9
a2a6509
93e1b47
81bfc3c
9c284e3
aa1bb7e
0661f2c
aa1d274
02a1e0f
9e3c7ff
e795740
b13ec94
05e3838
511760c
b46edb8
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ import { LectureInfo } from '@/app/type/lecture'; | |
import { API_PATH } from '../api-path'; | ||
import { cookies } from 'next/headers'; | ||
import { httpErrorHandler } from '@/app/utils/http/http-error-handler'; | ||
import { RESULT_CATEGORY } from '@/app/utils/key/result-category.key'; | ||
|
||
export interface ResultCategoryDetailLectures { | ||
yougyung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
categoryName: string; | ||
|
@@ -19,6 +20,20 @@ export interface ResultCategoryDetailInfo { | |
completed: boolean; | ||
} | ||
|
||
export interface Major { | ||
majorType: 'PRIMARY' | 'DUAL' | 'SUB'; | ||
major: string; | ||
} | ||
|
||
export interface ResultUserInfo { | ||
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.
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. ๊ธฐ์กด์ Mock data๋ก ํ์ฉ๋๊ณ ์๋ user์ ์ค์ ์๋ต๋ฐ๋ data์ ์ฐจ์ด๋ก ์ธํด ๋ถ๋ฆฌ ๋ฐ ํตํฉํ๋ ์ฝ๋๋ก ๋ฆฌํฉํ ๋ง์ ์งํํ ์์ ์
๋๋ค. |
||
studentNumber: string; | ||
studentName: string; | ||
completionDivision: Major[]; | ||
totalCredit: number; | ||
takenCredit: number; | ||
graduated: boolean; | ||
} | ||
|
||
export interface ResultUserInfo { | ||
yougyung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
studentNumber: string; | ||
studentName: string; | ||
|
@@ -28,10 +43,32 @@ export interface ResultUserInfo { | |
takenCredit: number; | ||
} | ||
|
||
export interface Credit { | ||
category: keyof typeof RESULT_CATEGORY; | ||
totalCredit: number; | ||
takenCredit: number; | ||
completed: boolean; | ||
} | ||
export const fetchResultCategoryDetailInfo = async (category: string): Promise<ResultCategoryDetailInfo> => { | ||
//FIX : category๋ฅผ querystring์ผ๋ก ํธ์ถํ๋ ๊ฑด์ mock๋จ๊ณ์์๋ ๋ถํ์ํ ๊ฒ์ผ๋ก ์์, ์ค์ api ์ฐ๊ฒฐ์ ๋ณ๊ฒฝ ์์ | ||
try { | ||
const response = await fetch(`${API_PATH.resultCategoryDetailInfo}`, { | ||
const response = await fetch(API_PATH.resultCategoryDetailInfo, { | ||
headers: { | ||
Authorization: `Bearer ${cookies().get('accessToken')?.value}`, | ||
}, | ||
}); | ||
const result = await response.json(); | ||
httpErrorHandler(response, result); | ||
|
||
return result; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
|
||
export const fetchCredits = async (): Promise<Credit[]> => { | ||
try { | ||
const response = await fetch(API_PATH.credits, { | ||
headers: { | ||
Authorization: `Bearer ${cookies().get('accessToken')?.value}`, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { UserInfoResponse } from './user.type'; | |
import { cookies } from 'next/headers'; | ||
import { isValidation } from '@/app/utils/zod/validation.util'; | ||
import { UserInfoResponseSchema } from './user.validation'; | ||
import { ResultUserInfo } from '../result/result.query'; | ||
|
||
export async function getUserInfo(): Promise<UserInfoResponse> { | ||
try { | ||
|
@@ -26,3 +27,20 @@ export async function getUserInfo(): Promise<UserInfoResponse> { | |
throw error; | ||
} | ||
} | ||
|
||
export async function fetchResultUserInfo(): Promise<ResultUserInfo> { | ||
try { | ||
const response = await fetch(API_PATH.resultUserInfo, { | ||
headers: { | ||
Authorization: `Bearer ${cookies().get('accessToken')?.value}`, | ||
}, | ||
}); | ||
|
||
const result = await response.json(); | ||
|
||
httpErrorHandler(response, result); | ||
return result; | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
Comment on lines
+31
to
+46
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. ํ์๊ฐ์
๋ก์ง์ผ๋ก ์ธํด fetch Result userInfo๋ฅผ ๋ง๋์
จ๋ค๊ณ ํ์
จ๋๋ฐ, ํน์ ์ด๋ก ์ธํด ์ด๋ค ๋ฌธ์ ๊ฐ ์์๋์ง ์๋ ค์ฃผ์ค ์ ์๋์!? 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. ํ์ฌ mock data์ ์ค์ backend์์ ์ ์กํด์ฃผ๋ ๏ฟฝtype์ด ์ผ์นํ์ง ์์(๋ค์ ๊ณต ๋ฑ์ ์ฌ์ ๋ก ๋ณ๊ฒฝ๋์์ต๋๋ค) UserInfo type์ ๋ณ๊ฒฝํด์ฃผ๋ ๊ณผ์ ์ด ํ์ํ์ต๋๋ค. englishlevel studentID ๋ฑ์ ์์ฑ์ ํ์๊ฐ์ ๊ณผ์ ์์ ์ฌ์ฉ๋๋ ์์ฑ์ด๋ผ๋ ์๊ฐ์ด ๋ค์ด์, type์ ์ ๊ฐ ์์๋ก ๋ณ๊ฒฝํ์ง ์๊ณ ์๋กญ๊ฒ ์์ฑํ์ต๋๋ค |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import { HttpResponse, http, delay } from 'msw'; | ||
import { API_PATH } from '../../business/api-path'; | ||
import { mockDatabase } from '../db.mock'; | ||
import { ErrorResponseData } from '@/app/utils/http/http-error-handler'; | ||
import { Credit, ResultCategoryDetailInfo } from '@/app/business/result/result.query'; | ||
|
||
export const resultHandlers = [ | ||
http.get(API_PATH.resultCategoryDetailInfo, async () => { | ||
const resultCategoryDetailInfo = mockDatabase.getResultCategoryDetailInfo(); | ||
await delay(4000); | ||
return HttpResponse.json(resultCategoryDetailInfo); | ||
http.get<never, never, ResultCategoryDetailInfo | ErrorResponseData>( | ||
`${API_PATH.resultCategoryDetailInfo}`, | ||
async ({ request }) => { | ||
const accessToken = request.headers.get('Authorization')?.replace('Bearer ', ''); | ||
if (accessToken === 'undefined' || !accessToken) { | ||
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
const data = mockDatabase.getResultCategoryDetailInfo(); | ||
await delay(3000); | ||
|
||
if (!data) { | ||
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
return HttpResponse.json(data); | ||
}, | ||
), | ||
http.get<never, never, Credit[] | ErrorResponseData>(`${API_PATH.credits}`, async ({ request }) => { | ||
const accessToken = request.headers.get('Authorization')?.replace('Bearer ', ''); | ||
if (accessToken === 'undefined' || !accessToken) { | ||
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
const data = mockDatabase.getCredits(); | ||
await delay(5000); | ||
if (!data) { | ||
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
return HttpResponse.json(data); | ||
}), | ||
]; |
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.
async ํค์๋๋ฅผ ๋ฃ์ ์ด์ ๋ฅผ ์ค๋ช ํด์ฃผ์ค ์ ์๋์?
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.
๊ธฐ์กด ๊ตฌ์กฐ์์๋ data fetching์ ํด๋น ์ปดํฌ๋ํธ์์ ์งํํ๋๋ฐ, ๊ตฌ์กฐ ๋ณ๊ฒฝ์ด ๋ฐ์ํ๋ฉด์ ์์ ์ ๋๋ฝํ ๋ถ๋ถ๊ฐ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค. 02a1e0f