Skip to content

Commit

Permalink
feat: findReservations (전체 예약 조회) API 마이그레이션
Browse files Browse the repository at this point in the history
  • Loading branch information
2yunseong committed Nov 8, 2023
1 parent e86cd80 commit bbbcbda
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
26 changes: 26 additions & 0 deletions frontend/src/api-v2/guestReservation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AxiosResponse } from 'axios';
import { QueryFunction, QueryKey } from 'react-query';
import THROW_ERROR from 'constants/throwError';
import { QueryGuestReservationsSuccessV2 } from 'types/response-v2';
import apiV2 from './apiv2';

interface DeleteGuestReservationParamsV2 {
Expand All @@ -17,6 +20,15 @@ export interface GuestReservationParamsV2 {
};
}

export interface QueryMapReservationsParamsV2 {
mapId: number;
date: string;
}

export interface QuerySpaceReservationsParamsV2 extends QueryMapReservationsParamsV2 {
spaceId: number;
}

export interface PostGuestReservationParamsV2 extends GuestReservationParamsV2 {
mapId: number;
spaceId: number;
Expand All @@ -28,6 +40,20 @@ interface PutGuestReservationParamsV2 extends GuestReservationParamsV2 {
reservationId: number;
}

export const queryGuestReservationsV2: QueryFunction<
AxiosResponse<QueryGuestReservationsSuccessV2>,
[QueryKey, QuerySpaceReservationsParamsV2]
> = ({ queryKey }) => {
const [, data] = queryKey;
const { mapId, spaceId, date } = data;

if (!mapId) {
throw new Error(THROW_ERROR.INVALID_MAP_ID);
}

return apiV2.get(`/api/maps/${mapId}/spaces/${spaceId}/reservations?date=${date}`);
};

export const postGuestReservationV2 = ({
reservation,
mapId,
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/hooks/query-v2/useGuestReservationsV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AxiosError, AxiosResponse } from 'axios';
import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query';
import { QuerySpaceReservationsParamsV2, queryGuestReservationsV2 } from 'api-v2/guestReservation';
import { ErrorResponse } from 'types/response';
import { QueryGuestReservationsSuccessV2 } from 'types/response-v2';

const useGuestReservationsV2 = <TData = AxiosResponse<QueryGuestReservationsSuccessV2>>(
{ mapId, spaceId, date }: QuerySpaceReservationsParamsV2,
options?: UseQueryOptions<
AxiosResponse<QueryGuestReservationsSuccessV2>,
AxiosError<ErrorResponse>,
TData,
[QueryKey, QuerySpaceReservationsParamsV2]
>
): UseQueryResult<TData, AxiosError<ErrorResponse>> =>
useQuery(['getGuestReservations', { mapId, spaceId, date }], queryGuestReservationsV2, options);

export default useGuestReservationsV2;
6 changes: 5 additions & 1 deletion frontend/src/hooks/query-v2/useManagerMapReservationsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const useManagerMapReservationsV2 = <TData = AxiosResponse<QueryManagerMapReserv
[QueryKey, QueryMapReservationsParamsV2]
>
): UseQueryResult<TData, AxiosError<ErrorResponse>> =>
useQuery(['getManagerMapReservations', { mapId, date }], queryManagerMapReservationsV2, options);
useQuery(
['getManagerMapReservationsV2', { mapId, date }],
queryManagerMapReservationsV2,
options
);

export default useManagerMapReservationsV2;
3 changes: 2 additions & 1 deletion frontend/src/pages/GuestMap/units/ReservationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Input from 'components/Input/Input';
import ManagerReservationListItem from 'components/ManagerReservationListItem/ManagerReservationListItem';
import Select from 'components/Select/Select';
import DATE from 'constants/date';
import useGuestReservationsV2 from 'hooks/query-v2/useGuestReservationsV2';
import useGuestReservations from 'hooks/query/useGuestReservations';
import useGuestSpace from 'hooks/query/useGuestSpace';
import { AccessTokenContext } from 'providers/AccessTokenProvider';
Expand Down Expand Up @@ -41,7 +42,7 @@ const ReservationList = ({
data: reservations,
isLoadingError,
isSuccess,
} = useGuestReservations(
} = useGuestReservationsV2(
{
mapId: mapId,
spaceId: +selectedSpaceId,
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/types/response-v2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MapItem, SpaceReservation } from './common';
import { MapItem, Reservation, SpaceReservation } from './common';

export interface MapItemResponseV2
extends Omit<MapItem, 'mapDrawing' | 'sharingMapId' | 'notice' | 'managerEmail'> {
Expand All @@ -16,3 +16,7 @@ export type QueryManagerMapSuccessV2 = MapItemResponseV2;
export interface QueryManagerMapReservationsSuccessV2 {
data: SpaceReservation[];
}

export interface QueryGuestReservationsSuccessV2 {
reservations: Reservation[];
}

0 comments on commit bbbcbda

Please sign in to comment.