Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/api/applicationApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import api from './api';
import { AxiosError } from 'axios';
import type { NoticeInfo } from './alertApi';
import type { ShopInfo } from './shopApi';
import type { UserProfileItem } from './userApi';

interface ErrorMessage {
message: string;
}

export interface LinkInfo {
rel: string;
description: string;
Expand Down Expand Up @@ -63,3 +69,95 @@ export interface ApplicationNoticeResponse {
export interface ApplicationRequest {
status: 'accepted' | 'rejected' | 'canceled';
}

// GET /shops/{shop_id}/notices/{notice_id}/applications - 가게의 특정 공고의 지원 목록 조회
export const getNoticeApplications = async (
shopId: string,
noticeId: string,
query?: { offset?: number; limit?: number },
): Promise<ApplicationNoticeResponse> => {
try {
const newQuery = new URLSearchParams({
offset: String(query?.offset ?? ''),
limit: String(query?.limit ?? ''),
});
const response = await api.get<ApplicationNoticeResponse>(
`/shops/${shopId}/notices/${noticeId}/applications?${newQuery}`,
);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};

// POST /shops/{shop_id}/notices/{notice_id}/applications - 가게의 특정 공고 지원 등록
export const postNoticeApplications = async (
shopId: string,
noticeId: string,
): Promise<ApplicationNoticeInfo> => {
try {
const response = await api.post<ApplicationNoticeInfo>(
`/shops/${shopId}/notices/${noticeId}/applications`,
);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};

// PUT /shops/{shop_id}/notices/{notice_id}/applications/{application_id} - 가게의 특정 공고 지원 승인, 거절 또는 취소
export const putNoticeApplications = async (
shopId: string,
noticeId: string,
applicationId: string,
body: ApplicationRequest,
): Promise<ApplicationNoticeInfo> => {
try {
const response = await api.put<ApplicationNoticeInfo>(
`/shops/${shopId}/notices/${noticeId}/applications/${applicationId}`,
body,
);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};

// GET /users/{user_id}/applications - 유저의 지원 목록 조회
export const getUserApplications = async (
userId: string,
query?: { offset?: number; limit?: number },
): Promise<ApplicationUserResponse> => {
try {
const newQuery = new URLSearchParams({
offset: String(query?.offset ?? ''),
limit: String(query?.limit ?? ''),
});
const response = await api.get<ApplicationUserResponse>(
`/users/${userId}/applications?${newQuery}`,
);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};