Skip to content

Commit fbaedb0

Browse files
authored
feat: impl get national assembly schedule list (#14)
* feat: impl get national assembly schedule list Signed-off-by: sunrabbit123 <[email protected]> * docs: add getNationalAssemblySchedule comment for tag api origin Signed-off-by: sunrabbit123 <[email protected]> * ci: add test code Signed-off-by: sunrabbit123 <[email protected]> --------- Signed-off-by: sunrabbit123 <[email protected]>
1 parent a49d7c8 commit fbaedb0

File tree

6 files changed

+132
-2
lines changed

6 files changed

+132
-2
lines changed

src/constant/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,13 @@ export const translatedVariableDictionary = {
5959
대표발의자코드: 'leadProposerCode',
6060
본회의심의결과: 'plenarySessionReviewResult',
6161
의결일: 'resolutionDate',
62+
일정_종류: 'scheduleType',
63+
일정_내용: 'scheduleContent',
64+
일정_일자: 'scheduleDate',
65+
일정_시간: 'scheduleTime',
66+
회의_구분: 'conferenceDivision',
67+
회의_회기: 'conferenceSession',
68+
회의_차수: 'conferenceDegree',
69+
행사_주체자: 'eventInstitution',
70+
행사_장소: 'eventPlace',
6271
} as const;

src/lawmaker/getLawmakerList.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ export const getLawmakerList = async ({ page, take, ...rest }: Argument) => {
8080
{ NAAS_CD, NAAS_NM, PLPT_NM, BLNG_CMIT_NM }
8181
);
8282

83-
return res.ALLNAMEMBER[1].row.map(transform);
83+
return res[command][1].row.map(transform);
8484
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
import { getNationalAssemblySchedule } from './getNationalAssemblySchedule';
3+
import { callOpenApi } from '../functional';
4+
import { translatedVariableDictionary } from '../constant';
5+
6+
vi.mock('../functional', () => ({
7+
callOpenApi: vi.fn(),
8+
}));
9+
10+
describe('getNationalAssemblySchedule', () => {
11+
it('should return a list of national assembly schedules', async () => {
12+
const mockResponse = {
13+
ALLSCHEDULE: [
14+
null,
15+
{
16+
row: [
17+
{
18+
SCH_KIND: 'Meeting',
19+
SCH_CN: 'Committee Meeting',
20+
SCH_DT: '2023-05-01',
21+
SCH_TM: '09:00',
22+
CONF_DIV: 'Regular',
23+
CMIT_NM: 'Committee A',
24+
CONF_SESS: '1',
25+
CONF_DGR: '1',
26+
EV_INST_NM: 'National Assembly',
27+
EV_PLC: 'Room 123',
28+
},
29+
],
30+
},
31+
],
32+
};
33+
34+
(callOpenApi as any).mockResolvedValueOnce(mockResponse);
35+
36+
const schedules = await getNationalAssemblySchedule({ page: 1, take: 10 });
37+
38+
expect(schedules).toHaveLength(1);
39+
expect(schedules[0]).toEqual({
40+
[translatedVariableDictionary['일정_종류']]: 'Meeting',
41+
[translatedVariableDictionary['일정_내용']]: 'Committee Meeting',
42+
[translatedVariableDictionary['일정_일자']]: '2023-05-01',
43+
[translatedVariableDictionary['일정_시간']]: '09:00',
44+
[translatedVariableDictionary['회의_구분']]: 'Regular',
45+
[translatedVariableDictionary['위원회명']]: 'Committee A',
46+
[translatedVariableDictionary['회의_회기']]: '1',
47+
[translatedVariableDictionary['회의_차수']]: '1',
48+
[translatedVariableDictionary['행사_주체자']]: 'National Assembly',
49+
[translatedVariableDictionary['행사_장소']]: 'Room 123',
50+
});
51+
});
52+
53+
it('should return an empty list when no schedules are found', async () => {
54+
const mockResponse = {
55+
ALLSCHEDULE: [null, { row: [] }],
56+
};
57+
58+
(callOpenApi as any).mockResolvedValueOnce(mockResponse);
59+
60+
const schedules = await getNationalAssemblySchedule({ page: 1, take: 10 });
61+
62+
expect(schedules).toHaveLength(0);
63+
});
64+
65+
it('should throw an error when callOpenApi fails', async () => {
66+
const mockError = new Error('Failed to fetch schedules');
67+
(callOpenApi as any).mockRejectedValueOnce(mockError);
68+
69+
await expect(getNationalAssemblySchedule({ page: 1, take: 10 })).rejects.toThrow('Failed to fetch schedules');
70+
});
71+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { translatedVariableDictionary } from '../constant';
2+
import { callOpenApi } from '../functional';
3+
import { PaginationType } from '../types/callOpenApi';
4+
5+
interface NationalAssemblySchedule {
6+
SCH_KIND: string; // 일정종류
7+
SCH_CN: string; // 일정내용
8+
SCH_DT: string; // 일자
9+
SCH_TM: string; // 시간
10+
CONF_DIV: string; // 회의구분
11+
CMIT_NM: string; // 위원회명
12+
CONF_SESS: string; // 회의회기
13+
CONF_DGR: string; // 회의차수
14+
EV_INST_NM: string; // 행사주체자
15+
EV_PLC: string; // 행사장소
16+
}
17+
18+
type Row = {
19+
[k in keyof NationalAssemblySchedule]: NationalAssemblySchedule[k] | null;
20+
};
21+
22+
type Argument = {
23+
scheduleKind?: string;
24+
scheduleDate?: string;
25+
} & PaginationType;
26+
27+
const command = 'ALLSCHEDULE';
28+
29+
const transform = (v: Row) => ({
30+
[translatedVariableDictionary['일정_종류']]: v.SCH_KIND,
31+
[translatedVariableDictionary['일정_내용']]: v.SCH_CN,
32+
[translatedVariableDictionary['일정_일자']]: v.SCH_DT,
33+
[translatedVariableDictionary['일정_시간']]: v.SCH_TM,
34+
[translatedVariableDictionary['회의_구분']]: v.CONF_DIV,
35+
[translatedVariableDictionary['위원회명']]: v.CMIT_NM,
36+
[translatedVariableDictionary['회의_회기']]: v.CONF_SESS,
37+
[translatedVariableDictionary['회의_차수']]: v.CONF_DGR,
38+
[translatedVariableDictionary['행사_주체자']]: v.EV_INST_NM,
39+
[translatedVariableDictionary['행사_장소']]: v.EV_PLC,
40+
});
41+
/**
42+
* @description call https://open.assembly.go.kr/portal/data/service/selectAPIServicePage.do/OOWY4R001216HX11437
43+
*/
44+
export const getNationalAssemblySchedule = async ({ page, take, ...rest }: Argument) => {
45+
const { scheduleKind: SCH_KIND, scheduleDate: SCH_DT } = rest;
46+
const res = await callOpenApi<typeof command, Row>(command, { page, take }, { SCH_KIND, SCH_DT });
47+
48+
return res[command][1].row.map(transform);
49+
};

src/national-assembly/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { getNationalAssemblySchedule } from './getNationalAssemblySchedule';

src/types/callOpenApi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export type PaginationType = {
33
take: number;
44
};
55

6-
export type ApiCommand = ('ALLNAMEMBER' | 'TVBPMBILL11') & string;
6+
export type ApiCommand = ('ALLNAMEMBER' | 'ALLSCHEDULE' | 'TVBPMBILL11') & string;
77

88
export const OpenApiResponseKind = {
99
'INFO-000': '정상 처리되었습니다.',

0 commit comments

Comments
 (0)