-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(time): add fetch function getLectureList / getMajorList & add en…
…dpoint constant (#97)
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
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,6 @@ | ||
const TIMETABLE_ENDPOINT = { | ||
getLectureList: 'api/v1/lecture/retrieve', | ||
getMajorList: 'api/v1/lecture/retrieve/major', | ||
}; | ||
|
||
export default TIMETABLE_ENDPOINT; |
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,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<GetLectureListResponse> { | ||
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(); | ||
} |
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,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<GetMajorListResponse> { | ||
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(); | ||
} |