diff --git a/apps/time/src/widgets/time-table/api/endpoint.ts b/apps/time/src/widgets/time-table/api/endpoint.ts new file mode 100644 index 00000000..f4032e7d --- /dev/null +++ b/apps/time/src/widgets/time-table/api/endpoint.ts @@ -0,0 +1,6 @@ +const TIMETABLE_ENDPOINT = { + getLectureList: 'api/v1/lecture/retrieve', + getMajorList: 'api/v1/lecture/retrieve/major', +}; + +export default TIMETABLE_ENDPOINT; diff --git a/apps/time/src/widgets/time-table/api/getLectureList.ts b/apps/time/src/widgets/time-table/api/getLectureList.ts new file mode 100644 index 00000000..6b420c2a --- /dev/null +++ b/apps/time/src/widgets/time-table/api/getLectureList.ts @@ -0,0 +1,75 @@ +import { DayKor } from '@/shared/types'; +import type { + DayCampus, + DayPeriod, + Grade, + LectureKey, + NightCampus, + NightPeriod, +} from '@/widgets/time-table'; +import { TIMETABLE_ENDPOINT } from '@/widgets/time-table'; + +export interface GetLectureListParams { + campus: (DayCampus | NightCampus)[]; + type: LectureKey[]; + grade: Grade[]; + day: DayKor[]; + time: (DayPeriod | NightPeriod)[]; + major: string[]; + lectureName: string; + cursor: number; + limit: number; +} + +export interface GetLectureListReponseValue { + id: number; + campus: string; + category: string; + code: string; + credit: 0; + grade: 0; + groupName: string; + isExceeded: true; + major: string; + name: string; + professor: string; + room: string; + year: 0; + semester: string; + time: string; + type: LectureKey; +} + +export interface GetLectureListResponse { + success: boolean; + data: { + values: GetLectureListReponseValue[]; + }; + hasPrevious: boolean; + hasNext: boolean; +} + +export async function getLectureList({ + ...params +}: GetLectureListParams): Promise { + const apiURL = new URL( + `${process.env.NEXT_PUBLIC_SERVER_URL}/${TIMETABLE_ENDPOINT.getLectureList}`, + ); + + Object.entries(params).forEach(([key, value]) => { + if (value) { + apiURL.searchParams.set( + key, + Array.isArray(value) ? value.join(',') : String(value), + ); + } + }); + + const res = await fetch(apiURL); + + if (!res.ok) { + throw new Error('강의 정보 불러오기에 실패했습니다.'); + } + + return res.json(); +} diff --git a/apps/time/src/widgets/time-table/api/getMajorList.ts b/apps/time/src/widgets/time-table/api/getMajorList.ts new file mode 100644 index 00000000..c7e56f82 --- /dev/null +++ b/apps/time/src/widgets/time-table/api/getMajorList.ts @@ -0,0 +1,28 @@ +import { TIMETABLE_ENDPOINT } from '@/widgets/time-table'; + +export interface GetMajorListParams { + major: string; +} + +export interface GetMajorListResponse { + success: boolean; + data: string[]; +} + +export async function getMajorList({ + major, +}: GetMajorListParams): Promise { + const apiURL = new URL( + `${process.env.NEXT_PUBLIC_SERVER_URL}/${TIMETABLE_ENDPOINT.getMajorList}`, + ); + + apiURL.searchParams.set('major', major); + + const res = await fetch(apiURL); + + if (!res.ok) { + throw new Error('전공 리스트 불러오기에 실패했습니다.'); + } + + return res.json(); +}