Skip to content

Commit

Permalink
feat: SchoolSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed Apr 5, 2023
1 parent ff7ad09 commit b2f041a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {
MealRequestParam,
NeisConfig,
RequestParam,
ScheduleInfo,
ScheduleRequestParam,
SchoolInfo,
SchoolRequestParam,
} from './types'
Expand Down Expand Up @@ -113,4 +115,13 @@ export class NeisRequest {
): Promise<MealInfo[]> {
return await this.request<MealInfo>('GET', 'mealServiceDietInfo', params)
}

async SchoolScheduleRaw(
params: ScheduleRequestParam & {
ATPT_OFCDC_SC_CODE: string
SD_SCHUL_CODE: string
}
): Promise<ScheduleInfo[]> {
return await this.request<ScheduleInfo>('GET', 'SchoolSchedule', params)
}
}
20 changes: 19 additions & 1 deletion src/structures/school.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { NeisRequest } from '../http'
import type { MealInfo, MealRequestParam, SchoolInfo } from '../types'
import type {
MealInfo,
MealRequestParam,
ScheduleInfo,
ScheduleRequestParam,
SchoolInfo,
} from '../types'

/** 학교 정보를 담는 클래스입니다. */
export class School implements SchoolInfo {
Expand Down Expand Up @@ -72,4 +78,16 @@ export class School implements SchoolInfo {
async getMealOne(params: MealRequestParam): Promise<MealInfo> {
return await this.getMeal(params).then((data) => data[0])
}

async getSchedule(params: ScheduleRequestParam): Promise<ScheduleInfo[]> {
return await this.#neis.SchoolScheduleRaw({
ATPT_OFCDC_SC_CODE: this.ATPT_OFCDC_SC_CODE,
SD_SCHUL_CODE: this.SD_SCHUL_CODE,
...params,
})
}

async getScheduleOne(params: ScheduleRequestParam): Promise<ScheduleInfo> {
return await this.getSchedule(params).then((data) => data[0])
}
}
49 changes: 48 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ export interface MealRequestParam {
readonly MLSV_TO_YMD?: string
}

export type RequestParam = SchoolRequestParam | MealRequestParam
export interface ScheduleRequestParam {
/** 주야과정명 */
readonly DGHT_CRSE_SC_NM?: string
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM?: string
/** 학사일자 */
readonly AY_YMD?: string
/** 학사시작일자 */
readonly AY_FROM_YMD?: string
/** 학사종료일자 */
readonly AY_TO_YMD?: string
}

export type RequestParam =
| SchoolRequestParam
| MealRequestParam
| ScheduleRequestParam

interface BaseInfo {
/** 시도교육청코드 */
Expand Down Expand Up @@ -119,3 +135,34 @@ export interface MealInfo extends BaseInfo {
/** 급식종료일자 */
readonly MLSV_TO_YMD: string
}

export interface ScheduleInfo extends BaseInfo {
/** 학년도 */
readonly AY: string
/** 주야과정명 */
readonly DGHT_CRSE_SC_NM: string | null
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM: string
/** 수업공제일명 */
readonly SBTR_DD_SC_NM: string
/** 학사일자 */
readonly AA_YMD: string
/** 행사명 */
readonly EVENT_NM: string
/** 행사내용 */
readonly EVENT_CNTNT: string
/** 1학년행사여부 */
readonly ONE_GRADE_EVENT_YN: string
/** 2학년행사여부 */
readonly TWO_GRADE_EVENT_YN: string
/** 3학년행사여부 */
readonly THREE_GRADE_EVENT_YN: string
/** 4학년행사여부 */
readonly FOUR_GRADE_EVENT_YN: string
/** 5학년행사여부 */
readonly FIVE_GRADE_EVENT_YN: string
/** 6학년행사여부 */
readonly SIX_GRADE_EVENT_YN: string
/** 수정일 */
readonly LOAD_DTM: string
}
31 changes: 31 additions & 0 deletions tests/schedule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { logger, neis } from '.'
import type { ScheduleInfo } from '../src/types'

describe('Schedule', () => {
it('should return ScheduleInfo[]', async () => {
const schools = await neis.getSchool({
ATPT_OFCDC_SC_CODE: 'B10',
})

const data: ScheduleInfo[] = []
for await (const school of schools) {
data.push(await school.getScheduleOne({ AY_YMD: '20230301' }))
}

logger.info(data)

expect(data).toMatchObject<ScheduleInfo[]>(data)
})

it('should return ScheduleInfo', async () => {
const school = await neis.getSchoolOne({
ATPT_OFCDC_SC_CODE: 'B10',
SD_SCHUL_CODE: '7091455',
})

const data = await school.getScheduleOne({ AY_YMD: '20230301' })
logger.info(data)

expect(data).toMatchObject<ScheduleInfo>(data)
})
})

0 comments on commit b2f041a

Please sign in to comment.