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

fix: 타입 정리 #85

Merged
merged 2 commits into from
Oct 2, 2024
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
20 changes: 0 additions & 20 deletions src/@types/Auction.d.ts

This file was deleted.

27 changes: 27 additions & 0 deletions src/@types/AuctionDetails.d.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터페이스 정리 확인했습니다
오늘 저녁에 백엔드 분들과 pre-acution 부분 api 협의 + 변경이 있을 것 같은데 해당 부분 추후에 전파드리겠습니다

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
declare module 'AuctionDetails' {
export interface IAuctionDetailsBase {
productId: number;
sellerName: string;
description: string;
productName: string;
minPrice: number;
imageList: string[];
}

export interface IAuctionDetails extends IAuctionDetailsBase {
timeRemaining: number;
status: string;
isSeller: boolean;
participantCount: number;
isParticipating: boolean;
bidId: number | null;
bidAmount: number;
remainingBidCount: number;
}

export interface IPreAuctionDetails extends IAuctionDetailsBase {
createdAt: string;
likeCount: number;
isLiked: boolean;
}
}
39 changes: 39 additions & 0 deletions src/@types/AuctionItem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
declare module 'AuctionItem' {
export interface IAuctionItemBase {
id: number;
name: string;
minPrice: number;
cdnPath: string;
}

export interface IPreAuctionItem extends IAuctionItemBase {
likeCount: number;
isLiked: boolean;
}

export interface IPreAuctionRegisteredItem extends IPreAuctionItem {
createdAt: string;
}

export interface IAuctionItem extends IAuctionItemBase {
participantCount: number;
timeRemaining: number;
isParticipating: boolean;
}
export interface IAuctionRegisteredItem extends IAuctionItem {
status: string;
createdAt: string;
}

export interface IUserAuctionWonItem extends IAuctionItemBase {
endDateTime: string;
winningBid: number;
}

export interface IUserAuctionLostItem extends IAuctionItemBase {
endDateTime: string;
highestBid: number;
}

export interface IUserAuctionHistoryItem extends Omit<IAuctionItem, 'isParticipating'> {}
}
2 changes: 1 addition & 1 deletion src/@types/Register.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'Register' {
export interface RegisterType {
export interface IRegister {
productName: string;
description: string;
minPrice: number;
Expand Down
4 changes: 2 additions & 2 deletions src/@types/myAuctionData.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Auction } from 'Auction';
import type { IAuctionItemBase } from 'AuctionItem';

// 개별 제품의 인터페이스
export interface AuctionItem extends Auction {
export interface AuctionItem extends IAuctionItemBase {
status: string;
createdAt: string;
}
Expand Down
76 changes: 17 additions & 59 deletions src/@types/productList.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import type {
IAuctionItem,
IAuctionRegisteredItem,
IPreAuctionItem,
IPreAuctionRegisteredItem,
IUserAuctionHistoryItem,
IUserAuctionLostItem,
IUserAuctionWonItem,
} from 'AuctionItem';

// 기본적인 페이지네이션 데이터를 위한 인터페이스
export interface PaginationData<T> {
hasNext: boolean;
Expand All @@ -9,62 +19,10 @@ export interface PaginationData<T> {
last: boolean;
}

// 공통된 리스트 아이템 인터페이스
export interface AuctionListItem {
id: number;
name: string;
cdnPath: string | null;
minPrice: number;
}

// 진행중인 경매 목록
export interface OngoingAuctionListItem extends AuctionListItem {
timeRemaining: number;
participantCount: number;
isParticipating: boolean;
}

// 사전 경매 목록
export interface PreEnrollProductListItem extends AuctionListItem {
likeCount: number;
isLiked: boolean;
}

// 정식 등록 경매
export interface OngoingAuctionRegisterdItem extends OngoingAuctionListItem {
status: string;
createdAt: string;
}

// 사전 등록 경매
export interface PreEnrollProductRegisteredItem
extends PreEnrollProductListItem {
createdAt: string;
}

// 참여 성공한 경매
export interface MyWonAuctionListItem extends AuctionListItem {
endDateTime: string;
winningBid: number;
}

export interface MyLostAuctionListItem extends AuctionListItem {
endDateTime: string;
highestBid: number;
}

// 참여 경매 목록
export interface MyHistoryAuctionListItem extends AuctionListItem {
timeRemaining: number;
participantCount: number;
}

export type OngoingAuctionListData = PaginationData<OngoingAuctionListItem>;
export type PreEnrollProductListData = PaginationData<PreEnrollProductListItem>;
export type OngoingAuctionRegisteredData =
PaginationData<OngoingAuctionRegisterdItem>;
export type PreEnrollProductRegisteredData =
PaginationData<PreEnrollProductRegisteredItem>;
export type MyWonAuctionListData = PaginationData<MyWonAuctionListItem>;
export type MyHistoryAuctionListData = PaginationData<MyHistoryAuctionListItem>;
export type MyLostAuctionListData = PaginationData<MyLostAuctionListItem>;
export type OngoingAuctionListData = PaginationData<IAuctionItem>;
export type PreEnrollProductListData = PaginationData<IPreAuctionItem>;
export type OngoingAuctionRegisteredData = PaginationData<IAuctionRegisteredItem>;
export type PreEnrollProductRegisteredData = PaginationData<IPreAuctionRegisteredItem>;
export type MyWonAuctionListData = PaginationData<IUserAuctionWonItem>;
export type MyHistoryAuctionListData = PaginationData<IUserAuctionLostItem>;
export type MyLostAuctionListData = PaginationData<IUserAuctionHistoryItem>;
2 changes: 1 addition & 1 deletion src/components/bid/Bid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vi.mocked(useGetAuctionDetails).mockReturnValue({
isParticipating: false,
isSeller: false,
minPrice: 23000,
name: 'qwer 미니 2집',
productName: 'qwer 미니 2집',
participantCount: 4,
productId: 14,
remainingBidCount: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/components/bid/EditBid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vi.mocked(useGetAuctionDetails).mockReturnValue({
isParticipating: false,
isSeller: false,
minPrice: 23000,
name: 'qwer 미니 2집',
productName: 'qwer 미니 2집',
participantCount: 4,
productId: 14,
remainingBidCount: 0,
Expand Down
28 changes: 0 additions & 28 deletions src/components/details/AuctionItem.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/details/queries.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { API_END_POINT } from '@/constants/api';
import { AuctionItem } from './AuctionItem';
import { httpClient } from '@/api/axios';
import { queryKeys } from '@/constants/queryKeys';
import { useSuspenseQuery } from '@tanstack/react-query';
import { IAuctionDetails } from 'AuctionDetails';

export const useGetAuctionDetails = (auctionId: number) => {
const getAuctionDetails = async (): Promise<AuctionItem> => {
const getAuctionDetails = async (): Promise<IAuctionDetails> => {
const response = await httpClient.get(`${API_END_POINT.AUCTIONS}/${auctionId}`);

return response.data;
};

const { data: auctionDetails } = useSuspenseQuery({
queryKey: [queryKeys.DETAILS, auctionId],
queryKey: [queryKeys.AUCTION_DETAILS, auctionId],
queryFn: getAuctionDetails,
});

Expand Down
8 changes: 4 additions & 4 deletions src/components/heart/queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UseMutateFunction, useMutation, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';

import { API_END_POINT } from '@/constants/api';
import type { IPreAuctionItem } from 'AuctionItem';
import { httpClient } from '@/api/axios';
import { queryKeys } from '@/constants/queryKeys';
import { PreRegisterAuction } from 'Auction';

export const useGetPreRegisterHeart = () => {
const getPreRegisterHeart = async (): Promise<PreRegisterAuction[]> => {
const getPreRegisterHeart = async (): Promise<IPreAuctionItem[]> => {
const response = await httpClient.get(`${API_END_POINT.PRE_REGISTER}/history`);

return response.data.items;
Expand All @@ -21,7 +21,7 @@ export const useGetPreRegisterHeart = () => {
};

export const useDeletePreRegisterHeart = (): {
mutate: UseMutateFunction<PreRegisterAuction[], Error, number, unknown>;
mutate: UseMutateFunction<IPreAuctionItem[], Error, number, unknown>;
} => {
const queryClient = useQueryClient();
const deletePreRegisterHeart = async (id: number) => {
Expand All @@ -31,7 +31,7 @@ export const useDeletePreRegisterHeart = (): {

const { mutate } = useMutation({
mutationFn: deletePreRegisterHeart,
onSuccess: (data: PreRegisterAuction[]) => {
onSuccess: (data: IPreAuctionItem[]) => {
queryClient.setQueryData([queryKeys.PRE_REGISTER_HEART], data);
queryClient.invalidateQueries({
queryKey: [queryKeys.PRE_REGISTER_HEART],
Expand Down
6 changes: 2 additions & 4 deletions src/components/home/HomeAuctionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PreRegisterAuction, RegisterAuction } from 'Auction';
import type { IAuctionItem, IPreAuctionItem } from 'AuctionItem';

import LikeCount from '../common/atomic/LikeCount';
import MinPrice from '../common/atomic/MinPrice';
Expand All @@ -7,9 +7,7 @@ import TimeLabel from '../common/atomic/TimeLabel';
import { truncateText } from '@/utils/truncateText';
import { useNavigate } from 'react-router-dom';

type HomeAuctionItemProps<T> = T extends 'pre-register'
? { kind: 'pre-register'; auction: PreRegisterAuction }
: { kind: 'register'; auction: RegisterAuction };
type HomeAuctionItemProps<T> = T extends 'pre-register' ? { kind: 'pre-register'; auction: IPreAuctionItem } : { kind: 'register'; auction: IAuctionItem };

const HomeAuctionItem = <T extends 'pre-register' | 'register'>({ kind, auction }: HomeAuctionItemProps<T>) => {
const navigate = useNavigate();
Expand Down
11 changes: 6 additions & 5 deletions src/components/home/queries.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import type { PreRegisterAuction, RegisterAuction } from 'Auction';
import { useSuspenseQueries } from '@tanstack/react-query';
import type { IAuctionItem, IPreAuctionItem } from 'AuctionItem';

import { API_END_POINT } from '@/constants/api';
import { httpClient } from '@/api/axios';
import { queryKeys } from '@/constants/queryKeys';
import { useSuspenseQueries } from '@tanstack/react-query';

export const useGetHomeAuctions = () => {
const getBestAuctions = async (): Promise<RegisterAuction[]> => {
const getBestAuctions = async (): Promise<IAuctionItem[]> => {
const response = await httpClient.get(`${API_END_POINT.BEST}`);
return response.data;
};
const getImminentAuctions = async (): Promise<RegisterAuction[]> => {
const getImminentAuctions = async (): Promise<IAuctionItem[]> => {
const response = await httpClient.get(`${API_END_POINT.IMMINENT}`);
return response.data;
};
const getPreRegisterAuctions = async (): Promise<PreRegisterAuction[]> => {
const getPreRegisterAuctions = async (): Promise<IPreAuctionItem[]> => {
const response = await httpClient.get(`${API_END_POINT.PRE_REGISTER}`);
return response.data.items;
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/order/OrderHistoryProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MyHistoryAuctionListItem } from '@/@types/productList';
import { LuUsers } from 'react-icons/lu';
import type { IUserAuctionHistoryItem } from 'AuctionItem';
import { IoPricetagsOutline } from 'react-icons/io5';
import { LuUsers } from 'react-icons/lu';
import ProductItem from '../common/item/ProductItem';

const OrderHistoryProduct = ({ product }: { product: MyHistoryAuctionListItem }) => {
const OrderHistoryProduct = ({ product }: { product: IUserAuctionHistoryItem }) => {
return (
<ProductItem product={product}>
<div className='flex'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/order/OrderLostProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MyLostAuctionListItem } from '@/@types/productList';
import type { IUserAuctionLostItem } from 'AuctionItem';
import { IoPricetagsOutline } from 'react-icons/io5';
import { LuUsers } from 'react-icons/lu';
import ProductItem from '../common/item/ProductItem';

const OrderLostProduct = ({ product }: { product: MyLostAuctionListItem }) => {
const OrderLostProduct = ({ product }: { product: IUserAuctionLostItem }) => {
return (
<ProductItem product={product}>
<div className='flex'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/order/OrderWonProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MyWonAuctionListItem } from '@/@types/productList';
import type { IUserAuctionWonItem } from 'AuctionItem';
import { IoPricetagsOutline } from 'react-icons/io5';
import { LuUsers } from 'react-icons/lu';
import ProductItem from '../common/item/ProductItem';

const OrderWonProduct = ({ product }: { product: MyWonAuctionListItem }) => {
const OrderWonProduct = ({ product }: { product: IUserAuctionWonItem }) => {
return (
<ProductItem product={product}>
<div className='flex'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/productList/OngoingProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Button from '../common/Button';
import type { IAuctionItem } from 'AuctionItem';
import { IoPricetagsOutline } from 'react-icons/io5';
import { LuUsers } from 'react-icons/lu';
import { OngoingAuctionListItem } from '@/@types/productList';
import ProductItem from '../common/item/ProductItem';
import { useNavigate } from 'react-router-dom';

const OngoingProduct = ({ product }: { product: OngoingAuctionListItem }) => {
const OngoingProduct = ({ product }: { product: IAuctionItem }) => {
const navigate = useNavigate();
const handleClick = () => navigate(`/auctions/bid/${product.id}`);
return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/productList/PreEnrollProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PreEnrollProductListItem } from '@/@types/productList';
import Button from '../common/Button';
import { FaHeart } from 'react-icons/fa';
import type { IPreAuctionItem } from 'AuctionItem';
import { IoPricetagsOutline } from 'react-icons/io5';
import ProductItem from '../common/item/ProductItem';
import Button from '../common/Button';

const PreEnrollProduct = ({ product }: { product: PreEnrollProductListItem }) => {
const PreEnrollProduct = ({ product }: { product: IPreAuctionItem }) => {
return (
<ProductItem product={product}>
<div className='flex'>
Expand Down
Loading