Skip to content

Commit

Permalink
Merge pull request #159 from softeerbootcamp4th/feat/#148-admin-api
Browse files Browse the repository at this point in the history
[Feat] 어드민 API 연동
  • Loading branch information
sooyeoniya authored Aug 19, 2024
2 parents 6f2491f + 69886df commit 59b01f0
Show file tree
Hide file tree
Showing 34 changed files with 799 additions and 515 deletions.
24 changes: 24 additions & 0 deletions admin/src/apis/imageAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PostImageResponse } from "@/types/imageApi";
import "@/types/lotteryApi";
import { fetchWithTimeout } from "@/utils/fetchWithTimeout";

const baseURL = `${import.meta.env.VITE_API_URL}/admin/image`;

export const ImageAPI = {
async postImage(image: FormData, token: string): Promise<PostImageResponse> {
try {
const response = await fetchWithTimeout(`${baseURL}`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
},
body: image,
});

return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
};
164 changes: 38 additions & 126 deletions admin/src/apis/lotteryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GetLotteryResponse,
GetLotteryWinnerParams,
GetLotteryWinnerResponse,
PatchLotteryExpectationParams,
PostLotteryWinnerResponse,
PutLotteryParams,
PutLotteryResponse,
Expand All @@ -17,45 +18,23 @@ const headers = {
};

export const LotteryAPI = {
async getLottery(): Promise<GetLotteryResponse> {
async getLottery(token: string): Promise<GetLotteryResponse> {
try {
return new Promise((resolve) =>
resolve([
{
startDate: "2024-07-26",
startTime: "00:00:00",
endDate: "2024-08-25",
endTime: "23:59:00",
appliedCount: 1000000,
winnerCount: 363,
status: "BEFORE",
},
])
);
const response = await fetchWithTimeout(`${baseURL}`, {
method: "GET",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async putLottery(body: PutLotteryParams): Promise<PutLotteryResponse> {
async putLottery(body: PutLotteryParams, token: string): Promise<PutLotteryResponse> {
try {
return new Promise((resolve) =>
resolve({
startDate: "2024-08-26",
startTime: "00:00:00",
endDate: "2024-09-25 23:59",
endTime: "00:00:00",
winnerCount: 363,
})
);
const response = await fetchWithTimeout(`${baseURL}`, {
method: "PUT",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
body: JSON.stringify(body),
});
return response.json();
Expand All @@ -64,65 +43,28 @@ export const LotteryAPI = {
throw error;
}
},
async postLotteryWinner(): Promise<PostLotteryWinnerResponse> {
async postLotteryWinner(token: string): Promise<PostLotteryWinnerResponse> {
try {
return new Promise((resolve) => resolve({ message: "요청에 성공하였습니다." }));
const response = await fetchWithTimeout(`${baseURL}/winner`, {
method: "POST",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async getLotteryParticipant({
size,
page,
phoneNumber,
}: GetLotteryWinnerParams): Promise<GetLotteryParticipantResponse> {
async getLotteryParticipant(
{ size, page, phoneNumber }: GetLotteryWinnerParams,
token: string
): Promise<GetLotteryParticipantResponse> {
try {
return new Promise((resolve) =>
resolve({
participants: [
{
id: 1,
phoneNumber: "010-1111-2222",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
createdAt: "2024-08-12T02:10:37.279369",
updatedAt: "2024-08-12T02:13:48.390954",
},
{
id: 2,
phoneNumber: "010-1111-2223",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
createdAt: "2024-08-12T02:10:37.279369",
updatedAt: "2024-08-12T02:13:48.390954",
},
{
id: 3,
phoneNumber: "010-1111-2224",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
createdAt: "2024-08-12T02:10:37.279369",
updatedAt: "2024-08-12T02:13:48.390954",
},
],
isLastPage: true,
totalParticipants: 10000,
})
);
const response = await fetchWithTimeout(
`${baseURL}/participants?size=${size}&page=${page}&number=${phoneNumber}`,
{
method: "GET",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
}
);
return response.json();
Expand All @@ -131,46 +73,16 @@ export const LotteryAPI = {
throw error;
}
},
async getLotteryWinner({
size,
page,
phoneNumber,
}: GetLotteryWinnerParams): Promise<GetLotteryWinnerResponse> {
async getLotteryWinner(
{ size, page, phoneNumber }: GetLotteryWinnerParams,
token: string
): Promise<GetLotteryWinnerResponse> {
try {
return new Promise((resolve) =>
resolve({
participants: [
{
id: 1,
phoneNumber: "010-1111-2222",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
{
id: 2,
phoneNumber: "010-1111-2223",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
{
id: 3,
phoneNumber: "010-1111-2224",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
],
isLastPage: false,
totalParticipants: 10000,
})
);
const response = await fetchWithTimeout(
`${baseURL}/winner?size=${size}&page=${page}&number=${phoneNumber}`,
{
method: "GET",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
}
);
return response.json();
Expand All @@ -179,31 +91,16 @@ export const LotteryAPI = {
throw error;
}
},
async getLotteryExpectations({
participantId,
}: GetLotteryExpectationsParams): Promise<GetLotteryExpectationsResponse> {
async getLotteryExpectations(
{ participantId, size, page }: GetLotteryExpectationsParams,
token: string
): Promise<GetLotteryExpectationsResponse> {
try {
return new Promise((resolve) =>
resolve([
{
casperId: 1,
expectation: "기대평 1",
},
{
casperId: 2,
expectation: "기대평 2",
},
{
casperId: 3,
expectation: "기대평 3",
},
])
);
const response = await fetchWithTimeout(
`${baseURL}/participants/${participantId}/expectations`,
`${baseURL}/participants/${participantId}/expectations?page=${page}&size=${size}`,
{
method: "GET",
headers: headers,
headers: { ...headers, Authorization: `Bearer ${token}` },
}
);
return response.json();
Expand All @@ -212,4 +109,19 @@ export const LotteryAPI = {
throw error;
}
},
async patchLotteryExpectation(
{ casperId }: PatchLotteryExpectationParams,
token: string
): Promise<{}> {
try {
await fetchWithTimeout(`${baseURL}/expectations/${casperId}`, {
method: "PATCH",
headers: { ...headers, Authorization: `Bearer ${token}` },
});
return {};
} catch (error) {
console.error("Error:", error);
throw error;
}
},
};
Loading

0 comments on commit 59b01f0

Please sign in to comment.