Skip to content

Commit a49d7c8

Browse files
StatPanstat-pansunrabbit123
authored
Feature/add getBillList function (#12)
* chore: add ApiCommand for Bill * chore: add new entries to translatedVariableDictionary * feat: add getBillList feature * chore: remove useless console command * chore: change some variable names after review * chore: change some values to Camel * chore: last variable name change * chore: bill variable name style changed law openapi -> our`s * refactor: remove destructuring assignment, use rest object --------- Co-authored-by: statpan <[email protected]> Co-authored-by: 오병진 <[email protected]>
1 parent 0bcd71c commit a49d7c8

File tree

6 files changed

+238
-1
lines changed

6 files changed

+238
-1
lines changed

src/bill/getBillList.spec.ts

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
import { getBillList } from './getBillList';
3+
import { callOpenApi } from '../functional';
4+
import { translatedVariableDictionary } from '../constant';
5+
6+
vi.mock('../functional', () => ({
7+
callOpenApi: vi.fn(),
8+
}));
9+
10+
describe('getBillList', () => {
11+
it('should return a list of bills', async () => {
12+
const mockResponse = {
13+
TVBPMBILL11: [
14+
null,
15+
{
16+
row: [
17+
{
18+
BILL_ID: 'PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6',
19+
BILL_NO: '2126707',
20+
AGE: '21',
21+
BILL_NAME: '문화다양성의 보호와 증진에 관한 법률 일부개정법률안',
22+
PROPOSER: '이자스민의원 등 10인',
23+
PROPOSER_KIND: '의원',
24+
PROPOSE_DT: '2024-05-29',
25+
CURR_COMMITTEE_ID: '9700513',
26+
CURR_COMMITTEE: '문화체육관광위원회',
27+
COMMITTEE_DT: '2024-05-29',
28+
COMMITTEE_PROC_DT: null,
29+
LINK_URL: 'https://likms.assembly.go.kr/bill/billDetail.do?billId=PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6',
30+
RST_PROPOSER: '이자스민',
31+
LAW_PROC_RESULT_CD: null,
32+
LAW_PROC_DT: null,
33+
LAW_PRESENT_DT: null,
34+
LAW_SUBMIT_DT: null,
35+
CMT_PROC_RESULT_CD: null,
36+
CMT_PROC_DT: null,
37+
CMT_PRESENT_DT: null,
38+
RST_MONA_CD: 'SZ51175J',
39+
PROC_RESULT_CD: '임기만료폐기',
40+
PROC_DT: '2024-05-29',
41+
},
42+
],
43+
},
44+
],
45+
};
46+
47+
(callOpenApi as any).mockResolvedValueOnce(mockResponse);
48+
49+
const bills = await getBillList({ page: 1, take: 10 });
50+
51+
expect(bills).toHaveLength(1);
52+
expect(bills[0]).toEqual({
53+
[translatedVariableDictionary['의안ID']]: 'PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6',
54+
[translatedVariableDictionary['의안번호']]: '2126707',
55+
[translatedVariableDictionary['대']]: '21',
56+
[translatedVariableDictionary['의안명']]: '문화다양성의 보호와 증진에 관한 법률 일부개정법률안',
57+
[translatedVariableDictionary['제안자']]: '이자스민의원 등 10인',
58+
[translatedVariableDictionary['제안자구분']]: '의원',
59+
[translatedVariableDictionary['제안일']]: '2024-05-29',
60+
[translatedVariableDictionary['소관위코드']]: '9700513',
61+
[translatedVariableDictionary['소관위']]: '문화체육관광위원회',
62+
[translatedVariableDictionary['소관위회부일']]: '2024-05-29',
63+
[translatedVariableDictionary['위원회심사_처리일']]: null,
64+
[translatedVariableDictionary['의안상세정보_URL']]:
65+
'https://likms.assembly.go.kr/bill/billDetail.do?billId=PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6',
66+
[translatedVariableDictionary['대표발의자']]: '이자스민',
67+
[translatedVariableDictionary['법사위처리결과']]: null,
68+
[translatedVariableDictionary['법사위처리일']]: null,
69+
[translatedVariableDictionary['법사위상정일']]: null,
70+
[translatedVariableDictionary['법사위회부일']]: null,
71+
[translatedVariableDictionary['소관위처리결과']]: null,
72+
[translatedVariableDictionary['소관위처리일']]: null,
73+
[translatedVariableDictionary['소관위상정일']]: null,
74+
[translatedVariableDictionary['대표발의자코드']]: 'SZ51175J',
75+
[translatedVariableDictionary['본회의심의결과']]: '임기만료폐기',
76+
[translatedVariableDictionary['의결일']]: '2024-05-29',
77+
});
78+
});
79+
80+
it('should return an empty list when no bills are found', async () => {
81+
const mockResponse = {
82+
TVBPMBILL11: [null, { row: [] }],
83+
};
84+
85+
(callOpenApi as any).mockResolvedValueOnce(mockResponse);
86+
87+
const bills = await getBillList({ page: 1, take: 10 });
88+
89+
expect(bills).toHaveLength(0);
90+
});
91+
92+
it('should throw an error when callOpenApi fails', async () => {
93+
const mockError = new Error('Failed to fetch bills');
94+
(callOpenApi as any).mockRejectedValueOnce(mockError);
95+
96+
await expect(getBillList({ page: 1, take: 10 })).rejects.toThrow('Failed to fetch bills');
97+
});
98+
});

src/bill/getBillList.ts

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { callOpenApi } from '../functional';
2+
import { PaginationType } from '../types/callOpenApi';
3+
import { translatedVariableDictionary } from '../constant';
4+
5+
// https://open.assembly.go.kr/portal/data/service/selectAPIServicePage.do/O4K6HM0012064I15889
6+
// 법률안 심사 및 처리(의안검색) 구현
7+
8+
interface Bill {
9+
BILL_ID: string; // 의안ID
10+
BILL_NO: string; // 의안번호
11+
AGE: string; // 대
12+
BILL_NAME: string; // 의안명(한글)
13+
PROPOSER: string; // 제안자
14+
PROPOSER_KIND: string; // 제안자구분
15+
PROPOSE_DT: string; // 제안일
16+
CURR_COMMITTEE_ID: string; // 소관위코드
17+
CURR_COMMITTEE: string; // 소관위
18+
COMMITTEE_DT: string; // 소관위회부일
19+
COMMITTEE_PROC_DT: string; // 위원회심사_처리일
20+
LINK_URL: string; // 의안상세정보_URL
21+
RST_PROPOSER: string; // 대표발의자
22+
LAW_PROC_RESULT_CD: string; // 법사위처리결과
23+
LAW_PROC_DT: string; // 법사위처리일
24+
LAW_PRESENT_DT: string; // 법사위상정일
25+
LAW_SUBMIT_DT: string; // 법사위회부일
26+
CMT_PROC_RESULT_CD: string; // 소관위처리결과
27+
CMT_PROC_DT: string; // 소관위처리일
28+
CMT_PRESENT_DT: string; // 소관위상정일
29+
RST_MONA_CD: string; // 대표발의자코드
30+
PROC_RESULT_CD: string; // 본회의심의결과
31+
PROC_DT: string; // 의결일
32+
}
33+
34+
type Row = {
35+
[k in keyof Bill]: Bill[k] | null;
36+
};
37+
38+
type Argument = {
39+
billID?: string; // 의안ID, 예시: BILL_ID='PRC_Z2Z1Z0Z3X2L4M0H9A2V6K5R0V7P2H1'
40+
billNumber?: string; // 의안번호, 예시: BILL_NO='2114286'
41+
age?: string; // 대, 예시: AGE='21'
42+
billName?: string; // 의안명(한글), 예시: BILL_NAME='의안명(한글) 검색어' (예시) BILL_NAME="80년
43+
proposer?: string; // 제안자, 예시: PROPOSER='제안자 검색어' (예시) PROPOSER=2012년
44+
proposerDivision?: string; // 제안자구분, 예시: PROPOSER_KIND='정부'
45+
jurisdictionCommitteeCode?: string; // 소관위코드, 예시: CURR_COMMITTEE_ID='B002368'
46+
jurisdictionCommittee?: string; // 소관위, 예시: CURR_COMMITTEE='소관위 검색어' (예시) CURR_COMMITTEE=2002
47+
plenarySessionReviewResult?: string; // 본회의심의결과, 예시: PROC_RESULT_CD='회기불계속폐기'
48+
resolutionDate?: string; // 의결일, 예시: PROC_DT='2021-12-31'
49+
} & PaginationType;
50+
51+
const command = 'TVBPMBILL11';
52+
53+
const transform = (v: Row) => ({
54+
[translatedVariableDictionary['의안ID']]: v.BILL_ID,
55+
[translatedVariableDictionary['의안번호']]: v.BILL_NO,
56+
[translatedVariableDictionary['대']]: v.AGE,
57+
[translatedVariableDictionary['의안명']]: v.BILL_NAME,
58+
[translatedVariableDictionary['제안자']]: v.PROPOSER,
59+
[translatedVariableDictionary['제안자구분']]: v.PROPOSER_KIND,
60+
[translatedVariableDictionary['제안일']]: v.PROPOSE_DT,
61+
[translatedVariableDictionary['소관위코드']]: v.CURR_COMMITTEE_ID,
62+
[translatedVariableDictionary['소관위']]: v.CURR_COMMITTEE,
63+
[translatedVariableDictionary['소관위회부일']]: v.COMMITTEE_DT,
64+
[translatedVariableDictionary['위원회심사_처리일']]: v.COMMITTEE_PROC_DT,
65+
[translatedVariableDictionary['의안상세정보_URL']]: v.LINK_URL,
66+
[translatedVariableDictionary['대표발의자']]: v.RST_PROPOSER,
67+
[translatedVariableDictionary['법사위처리결과']]: v.LAW_PROC_RESULT_CD,
68+
[translatedVariableDictionary['법사위처리일']]: v.LAW_PROC_DT,
69+
[translatedVariableDictionary['법사위상정일']]: v.LAW_PRESENT_DT,
70+
[translatedVariableDictionary['법사위회부일']]: v.LAW_SUBMIT_DT,
71+
[translatedVariableDictionary['소관위처리결과']]: v.CMT_PROC_RESULT_CD,
72+
[translatedVariableDictionary['소관위처리일']]: v.CMT_PROC_DT,
73+
[translatedVariableDictionary['소관위상정일']]: v.CMT_PRESENT_DT,
74+
[translatedVariableDictionary['대표발의자코드']]: v.RST_MONA_CD,
75+
[translatedVariableDictionary['본회의심의결과']]: v.PROC_RESULT_CD,
76+
[translatedVariableDictionary['의결일']]: v.PROC_DT,
77+
});
78+
79+
/**
80+
* @description implementation of 법률안 심사 및 처리 API
81+
*/
82+
export const getBillList = async ({ page, take, ...rest }: Argument) => {
83+
const res = await callOpenApi<typeof command, Row>(
84+
command,
85+
{ page, take },
86+
{
87+
BILL_ID: rest.billID,
88+
BILL_NO: rest.billNumber,
89+
AGE: rest.age,
90+
BILL_NAME: rest.billName,
91+
PROPOSER: rest.proposer,
92+
PROPOSER_KIND: rest.proposerDivision,
93+
CURR_COMMITTEE_ID: rest.jurisdictionCommitteeCode,
94+
CURR_COMMITTEE: rest.jurisdictionCommittee,
95+
PROC_RESULT_CD: rest.plenarySessionReviewResult,
96+
PROC_DT: rest.resolutionDate,
97+
}
98+
);
99+
return res.TVBPMBILL11[1].row.map(transform);
100+
};

src/bill/index.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// src/bill/index.spec.ts
2+
import { describe, it, expect } from 'vitest';
3+
import { getBillList } from './index';
4+
5+
describe('bill index.ts', () => {
6+
it('should export getBillList', () => {
7+
expect(getBillList).toBeDefined();
8+
});
9+
});

src/bill/index.ts

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

src/constant/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* @ignore `~코드`와 같은 이름을 지칭하는 변수의 경우 `Code`로 끝나야함
55
* @ignore `~일자`와 같은 이름을 지칭하는 변수의 경우 `Date`로 끝나야함
66
* @ignore `~구분`과 같은 이름을 지칭하는 변수의 경우 `Division`으로 끝나야함, 만약 `구분명`이라면 `Division`을 사용
7+
* @ignore `~처리`과 같은 이름을 지칭하는 변수의 경우 `Process`으로 끝나야함
8+
* @ignore `~상정`과 같은 이름을 지칭하는 변수의 경우 `Present`으로 끝나야함
9+
* @ignore `~회부`과 같은 이름을 지칭하는 변수의 경우 `Submit`으로 끝나야함
10+
* @ignore `~의결`과 같은 이름을 지칭하는 변수의 경우 `Resolution`으로 끝나야함
711
*/
812
export const translatedVariableDictionary = {
913
국회의원코드: 'lawmakerCode',
@@ -30,4 +34,29 @@ export const translatedVariableDictionary = {
3034
약력: 'profile',
3135
사무실호실: 'officeRoom',
3236
사진: 'picture',
37+
38+
// 의안 관련 추가
39+
의안ID: 'billID',
40+
의안번호: 'billNumber',
41+
: 'age',
42+
의안명: 'billName',
43+
제안자: 'proposer',
44+
제안자구분: 'proposerDivision',
45+
제안일: 'proposeDate',
46+
소관위코드: 'jurisdictionCommitteeCode',
47+
소관위: 'jurisdictionCommittee',
48+
소관위회부일: 'jurisdictionCommitteeSubmitDate',
49+
위원회심사_처리일: 'committeeReviewProcessDate',
50+
의안상세정보_URL: 'billDetailUrl',
51+
대표발의자: 'leadProposer',
52+
법사위처리결과: 'legislationAndJudiciaryCommitteeProcessResult',
53+
법사위처리일: 'legislationAndJudiciaryCommitteeProcessDate',
54+
법사위상정일: 'legislationAndJudiciaryCommitteePresentDate',
55+
법사위회부일: 'legislationAndJudiciaryCommitteeSubmitDate',
56+
소관위처리결과: 'jurisdictionCommitteeProcessResult',
57+
소관위처리일: 'jurisdictionCommitteeProcessDate',
58+
소관위상정일: 'jurisdictionCommitteePresentDate',
59+
대표발의자코드: 'leadProposerCode',
60+
본회의심의결과: 'plenarySessionReviewResult',
61+
의결일: 'resolutionDate',
3362
} as const;

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' & string;
6+
export type ApiCommand = ('ALLNAMEMBER' | 'TVBPMBILL11') & string;
77

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

0 commit comments

Comments
 (0)