Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 어드민 API 연동 #159

Merged
merged 33 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
14ee6fc
feat: 선착순 밸런스 게임 이벤트 불러오기 API 연동
jhj2713 Aug 13, 2024
86e1e63
fix: API에 맞게 option 수정
jhj2713 Aug 13, 2024
32600fa
feat: 추첨 이벤트 조회 API 연동
jhj2713 Aug 13, 2024
31d1dac
fix: 추첨 이벤트 수정 API 요청 수정
jhj2713 Aug 13, 2024
b3592bd
fix: participants -> participantsList
jhj2713 Aug 13, 2024
cf6d678
feat: 이미지 업로드 로직 구현
jhj2713 Aug 13, 2024
77d589a
fix: 타입 수정 및 불필요한 구문 삭제
jhj2713 Aug 13, 2024
8d9e6d3
feat: 이미지 API 연동
jhj2713 Aug 14, 2024
5c8a356
fix: 이미지 업로드 조건 수정
jhj2713 Aug 14, 2024
416be8e
feat: 무한 스크롤 params 수정
jhj2713 Aug 14, 2024
c868c4f
feat: 이벤트 진행 날짜 / 시간 예외처리 추가
jhj2713 Aug 14, 2024
91ff881
feat: 추첨 이벤트 수정 API 반영
jhj2713 Aug 14, 2024
a751bcb
feat: 수정 API 연동
jhj2713 Aug 14, 2024
7e2ad0c
feat: 기대평 삭제 로직 구현
jhj2713 Aug 14, 2024
d4684a3
fix: infinite 조회 수정
jhj2713 Aug 14, 2024
067550f
fix: token 로직 수정
jhj2713 Aug 14, 2024
11bc298
feat: 기대평 무한 스크롤
jhj2713 Aug 14, 2024
6972546
fix: API 요청 칼럼 맞추기
jhj2713 Aug 14, 2024
82f0158
fix: start fetching 조건 추가
jhj2713 Aug 14, 2024
787597d
feat: 오류 시 cookie 제거 로직 구현
jhj2713 Aug 14, 2024
1466aa5
fix: intersection observer 수정
jhj2713 Aug 14, 2024
3b40b7d
fix: memo 적용
jhj2713 Aug 14, 2024
85ff362
fix: 불필요한 props 삭제
jhj2713 Aug 14, 2024
859f1f0
refactor: useMemo 적용
jhj2713 Aug 14, 2024
f02c18a
fix: ModalComponent가 isOpen 상태에 따라 계속 리렌더링되는 현상 방지
jhj2713 Aug 15, 2024
265fd51
chore: header에 root 라우팅 적용
jhj2713 Aug 16, 2024
8d02920
feat: 추첨 API 연동
jhj2713 Aug 16, 2024
8e0afed
fix: participant fetch 조건 수정
jhj2713 Aug 16, 2024
de33a99
refactor: getMsTime util 적용
jhj2713 Aug 19, 2024
bb37f19
chore: 필요없는 await 삭제
jhj2713 Aug 19, 2024
f0b236d
chore: index -> idx
jhj2713 Aug 19, 2024
31f8bf3
chore: validate 문구 수정
jhj2713 Aug 19, 2024
69886df
chore: useCallback 추가
jhj2713 Aug 19, 2024
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
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
Loading