Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/api/adapters/store.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { StoreDetailDataDTO } from "@/api/dto/store.dto";
import type { BreakTime, RestaurantDetail } from "@/types/store";
import type { BreakTime, RestaurantDetail, StoreDetailDataDTO } from "@/types/store";

export function toRestaurantDetail(dto: StoreDetailDataDTO): RestaurantDetail {
const breakTime = toBreakTime(dto.breakStartTime, dto.breakEndTime);
Expand Down
9 changes: 1 addition & 8 deletions src/api/axios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { type AxiosError, type InternalAxiosRequestConfig } from "axios";

import { useAuthStore } from "@/stores/useAuthStore";
import type { ApiError } from "@/types/api";
import type { ApiError, ApiResponseWithFlags } from "@/types/api";

import { isApiResponse, normalizeApiError } from "./api.error";
import { clearAuth, postRefresh } from "./auth";
Expand Down Expand Up @@ -38,13 +38,6 @@ api.interceptors.request.use((config: InternalAxiosRequestConfig) => {

let refreshPromise: ReturnType<typeof postRefresh> | null = null;

type ApiResponseWithFlags = {
code?: string;
message?: string;
success?: boolean;
isSuccess?: boolean;
};

api.interceptors.response.use(
(res) => {
const data = res.data;
Expand Down
31 changes: 2 additions & 29 deletions src/api/bookings.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import { api } from "./axios";

type ApiBookingStatus = "PENDING" | "CONFIRMED" | "COMPLETED" | "CANCELED";

interface Booking {
bookingId: number;
storeName: string;
storeAddress: string;
bookingDate: string;
bookingTime: string;
partySize: number;
tableNumbers: string;
amount: number | null;
paymentMethod: string;
status: ApiBookingStatus;
}
import type { ApiBookingStatus, BookingResponse, GetBookingParams } from "@/types/booking";

interface BookingResponse {
bookingList: Booking[];
listSize: number;
totalPage: number;
totalElements: number;
isFirst: boolean;
isLast: boolean;
}

type GetBookingParams = {
page: number;
status?: ApiBookingStatus;
};
import { api } from "./axios";

export const getBookings = async (
status?: ApiBookingStatus,
Expand Down
37 changes: 0 additions & 37 deletions src/api/dto/store.dto.ts

This file was deleted.

40 changes: 4 additions & 36 deletions src/api/endpoints/bookings.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
import { api } from "../axios";

type APiResult<T> = {
isSucceess?: boolean;
success?: boolean;
code?: string;
message?: string;
result: T;
};
import type { ApiResponse } from "@/types/api";
import type { UserBookingsResult } from "@/types/booking";

type BookingListItem = {
bookingId: number;
storeName: string;
storeAddress: string;
bookingDate: string;
bookingTime: {
hour: number;
minute: number;
second: number;
nano: number;
};
partySize: number;
tableNumbers: string;
amount: number;
paymentMethod: string;
status: string;
};

type UserBookingsResult = {
bookingList: BookingListItem[];
listSize: number;
totalPage: number;
totalElements: number;
isFirst: boolean;
isLast: boolean;
};
import { api } from "../axios";

export async function getUserBookings(page = 1) {
const res = await api.get<APiResult<UserBookingsResult>>(`/api/v1/users/bookings?page=${page}`);
const res = await api.get<ApiResponse<UserBookingsResult>>(`/api/v1/users/bookings?page=${page}`);
return res.data.result;
}
50 changes: 15 additions & 35 deletions src/api/endpoints/member.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,41 @@
import { api } from "../axios";
import type { ApiResponse } from "@/types/api";
import type {
ChangePasswordRequest,
ChangePasswordResponse,
MemberInfo,
PatchMemberInfo,
} from "@/types/member";

type ApiEnvelope<T> = {
isSuccess?: boolean;
success?: boolean;
code?: string;
message?: string;
result: T;
};
import { api } from "../axios";

type MemberInfo = {
id: number;
profileImage: string | null;
email: string;
name: string;
phoneNumber: string;
};
export async function getMemberInfo() {
const res = await api.get<ApiEnvelope<MemberInfo>>("/api/v1/member/info");
const res = await api.get<ApiResponse<MemberInfo>>("/api/v1/member/info");
if (!res.data.isSuccess || !res.data.result) {
throw new Error(res.data.message ?? "회원정보 조회 실패");
}
return res.data.result;
}

type PatchMemberInfo = {
name: string;
phoneNumber: string;
};

export async function patchMemberInfo(body: PatchMemberInfo) {
const res = await api.patch<ApiEnvelope<string>>("/api/v1/member/info", body);
const res = await api.patch<ApiResponse<string>>("/api/v1/member/info", body);
if (!res.data?.isSuccess) {
throw new Error(res.data?.message ?? "회원정보 수정 실패");
}
return res.data.result;
}
Comment thread
dew102938 marked this conversation as resolved.

export async function putProfileImage(file: File) {
const formData = new FormData();
formData.append("profileImage", file);
const res = await api.put<ApiEnvelope<string>>("/api/v1/member/profile-image", formData);
const res = await api.put<ApiResponse<string>>("/api/v1/member/profile-image", formData);
if (!res.data.isSuccess) {
throw new Error(res.data.message ?? "프로필 업로드 실패");
}
return res.data.result;
}

type ChangePasswordRequest = {
currentPassword: string;
newPassword: string;
newPasswordConfirm: string;
};

type ChangePasswordResponse = {
change: boolean;
changeAt: string;
message: string;
};
export async function putChangePassword(body: ChangePasswordRequest) {
const res = await api.put<ApiEnvelope<ChangePasswordResponse>>("/api/v1/member/password", body);
const res = await api.put<ApiResponse<ChangePasswordResponse>>("/api/v1/member/password", body);
if (!res.data?.isSuccess) {
throw new Error(res.data.message ?? "비밀번호 변경에 실패했습니다");
}
Expand Down
27 changes: 3 additions & 24 deletions src/api/endpoints/menus.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
import type { MenuCategory, MenuItem } from "@/types/menus";
import type { ApiResponse } from "@/types/api";
import type { MenuCategory, MenuItem, MenuListResult } from "@/types/menus";

import { api } from "../axios";

type ApiResult<T> = {
isSuccess?: boolean;
success?: boolean;
code?: string;
message?: string;
result: T;
};

type MenuDto = {
menuId: number;
name: string;
description?: string;
price: number;
category: MenuCategory | string;
imageUrl?: string;
isSoldOut: boolean;
};

type MenuListResult = {
menus: MenuDto[];
};

export async function getMenus(storeId: string): Promise<MenuItem[]> {
const { data } = await api.get<ApiResult<MenuListResult>>(`/api/v1/stores/${storeId}/menus`);
const { data } = await api.get<ApiResponse<MenuListResult>>(`/api/v1/stores/${storeId}/menus`);
if (!data?.isSuccess) {
throw {
status: 0,
Expand Down
34 changes: 5 additions & 29 deletions src/api/endpoints/payments.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { api } from "../axios";

type ApiEnvelope<T> = {
isSuccess?: boolean;
success?: boolean;
code?: string;
message?: string;
result: T;
};
import type { ApiResponse } from "@/types/api";
import type { PaymentConfirmResult, PaymentRequestResult } from "@/types/payment";

type PaymentRequestResult = {
paymentId: number;
bookingId: number;
orderId: string;
amount: number;
requestedAt: string;
};
import { api } from "../axios";

export async function requestPayment(body: { bookingId: number }) {
const res = await api.post<ApiEnvelope<PaymentRequestResult>>(`/api/v1/payments/request`, body);
const res = await api.post<ApiResponse<PaymentRequestResult>>(`/api/v1/payments/request`, body);
if (!res.data?.isSuccess) {
throw {
status: 0,
Expand All @@ -28,23 +15,12 @@ export async function requestPayment(body: { bookingId: number }) {
return res.data.result;
}

type PaymentConfirmResult = {
paymentId: number;
status: string;
approvedAt: string;
orderId: string;
amount: number;
paymentMethod: string;
paymentProvider: string;
receiptUrl: string;
};

export async function confirmPayment(body: {
paymentKey: string;
orderId: string;
amount: number;
}) {
const res = await api.post<ApiEnvelope<PaymentConfirmResult>>("/api/v1/payments/confirm", body);
const res = await api.post<ApiResponse<PaymentConfirmResult>>("/api/v1/payments/confirm", body);
if (!res.data?.isSuccess) {
throw new Error(res.data?.message ?? "결제 승인에 실패했습니다.");
}
Expand Down
Loading
Loading