Skip to content

Commit 20c8996

Browse files
committed
refactor(recruit): 모집 상태 API 및 스키마 코드 위치 변경 (#17)
스키마와 api 파일 모두 recruitment-status에서 recruitment로 이동
1 parent adf165c commit 20c8996

7 files changed

Lines changed: 51 additions & 52 deletions

File tree

apps/recruit/src/app/(home)/_components/RecruitmentActive.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const RecruitmentActive = () => {
1818

1919
const [isModalOpen, setIsModalOpen] = useState(false);
2020
const {data: recruitmentStatus} = useRecruitmentStatusQuery();
21-
const generation = recruitmentStatus?.data?.generationId ?? '';
21+
const generation = recruitmentStatus?.generationId ?? '';
2222

2323
const {isAuthenticated} = useAuthStore();
2424

apps/recruit/src/app/apply/_hooks/useApplyFormController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from '@/hooks/mutations/useApply.mutation';
2929
import {useQueryClient} from '@tanstack/react-query';
3030
import {QUERY_KEYS} from '@/constants/query-keys';
31-
import {getRecruitmentStatus} from '@/services/api/recruitment/recruitment-status.api';
31+
import {getRecruitmentStatus} from '@/services/api/recruitment/recruitment.api';
3232
import {ROUTES} from '@/constants/routes';
3333

3434
interface UseApplyFormControllerReturn {
@@ -133,7 +133,7 @@ export const useApplyFormController = (): UseApplyFormControllerReturn => {
133133
staleTime: 0, // 항상 서버에서 최신 데이터 가져오기
134134
});
135135

136-
if (!latest.data.isActive) {
136+
if (!latest.isActive) {
137137
alert('모집 기간이 종료되었습니다.');
138138
router.push(ROUTES.HOME);
139139
return false;

apps/recruit/src/hooks/queries/useRecruitmentStatus.query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {useQuery} from '@tanstack/react-query';
22
import {useRecruitmentStore} from '@/store/useRecruitmentStore';
33
import {useEffect} from 'react';
44
import {QUERY_KEYS} from '@/constants/query-keys';
5-
import {getRecruitmentStatus} from '@/services/api/recruitment/recruitment-status.api';
5+
import {getRecruitmentStatus} from '@/services/api/recruitment/recruitment.api';
66

77
export const useRecruitmentStatusQuery = (options?: {
88
refetchInterval?: number;
@@ -19,9 +19,9 @@ export const useRecruitmentStatusQuery = (options?: {
1919

2020
// 서버 데이터로 store 동기화
2121
useEffect(() => {
22-
if (query.data?.data) {
22+
if (query.data) {
2323
const {isActive, generationId, isAdditionalRecruitmentActive} =
24-
query.data.data;
24+
query.data;
2525

2626
setIsRecruiting(isActive);
2727
setIsAdditional(isAdditionalRecruitmentActive);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import z from 'zod';
22

3+
export const RecruitmentStatusResponseSchema = z.object({
4+
isActive: z.boolean(),
5+
generationId: z.number().nullable(),
6+
isAdditionalRecruitmentActive: z.boolean(),
7+
});
8+
39
export const RecruitmentNotifyRequestSchema = z.object({email: z.email()});
410

11+
export type RecruitmentStatusResponse = z.infer<
12+
typeof RecruitmentStatusResponseSchema
13+
>;
514
export type RecruitmentNotifyRequest = z.infer<
615
typeof RecruitmentNotifyRequestSchema
716
>;

apps/recruit/src/schemas/status/recruitment-status.schema.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/recruit/src/services/api/recruitment/recruitment-status.api.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

apps/recruit/src/services/api/recruitment/recruitment.api.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
import {RecruitmentNotifyRequest} from '@/schemas/recruitment/recruitment.schema';
1+
import {createSuccessResponseSchema} from '@/schemas/common/common-schema';
2+
import {
3+
RecruitmentNotifyRequest,
4+
RecruitmentStatusResponse,
5+
RecruitmentStatusResponseSchema,
6+
} from '@/schemas/recruitment/recruitment.schema';
27
import {publicAxios} from '@/services/config/axios';
38
import {ENDPOINT} from '@/services/constant/endpoint';
49
import {handleApiError} from '@/services/utils/apiHelper';
10+
import {AxiosResponse} from 'axios';
11+
12+
/**
13+
* 모집 상태 조회
14+
* - 모집 종료/시작 여부는 최종 제출 시점에 반드시 재확인 필요
15+
*/
16+
export const getRecruitmentStatus =
17+
async (): Promise<RecruitmentStatusResponse> => {
18+
try {
19+
const response: AxiosResponse = await publicAxios.get(
20+
ENDPOINT.RECRUITMENT.STATUS,
21+
{
22+
params: {_ts: Date.now()},
23+
headers: {
24+
'Cache-Control': 'no-cache',
25+
Pragma: 'no-cache',
26+
},
27+
}
28+
);
29+
30+
const responseSchema = createSuccessResponseSchema(
31+
RecruitmentStatusResponseSchema
32+
);
33+
const validatedResponse = responseSchema.parse(response.data);
34+
35+
return validatedResponse.data;
36+
} catch (error) {
37+
return handleApiError(error);
38+
}
39+
};
540

641
/** 모집 알림 구독 신청 */
742
export const postRecruitmentNotify = async (

0 commit comments

Comments
 (0)