Skip to content

Commit

Permalink
Feat: 객실 관리하기 로직 구현 및 수정하기 API (#181)
Browse files Browse the repository at this point in the history
Co-authored-by: 89882 <[email protected]>
  • Loading branch information
syb0127 and gahyuun authored Jan 25, 2024
1 parent 05cec59 commit 2078e92
Show file tree
Hide file tree
Showing 25 changed files with 862 additions and 182 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-responsive": "^9.0.2",
"react-infinite-scroll-component": "^6.1.0",
"react-router-dom": "^6.21.1",
"react-scripts": "5.0.1",
"recoil": "^0.7.7",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function App() {
</Route>
<Route element={<RoomLayout />}>
<Route
path={`/:accommodationId${ROUTES.ROOM_UPDATE}`}
path={`/:accommodationId/:roomId${ROUTES.ROOM_UPDATE}`}
element={<RoomUpdate />}
/>
</Route>
Expand Down
11 changes: 0 additions & 11 deletions src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ instance.interceptors.request.use(
instance.interceptors.response.use(
(response) => response,
(error) => {
if (
error.response?.status === HTTP_STATUS_CODE.UNAUTHORIZED &&
window.location.pathname !== ROUTES.SIGNIN &&
window.location.pathname !== ROUTES.SIGNIN_AGREEMENT &&
window.location.pathname !== ROUTES.SIGNUP &&
window.location.pathname !== ROUTES.SIGNUP_SUCCESS
) {
handleUnauthorized();
} else if (error.response?.status === HTTP_STATUS_CODE.NOTFOUND) {
console.log('여기 404에러 핸들링 필요해요~');
}
return Promise.reject(error);
},
);
20 changes: 14 additions & 6 deletions src/api/room/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
RoomListResponseData,
RoomData,
RoomPostResponseData,
AccommodationData,
RoomDeleteResponseData,
RoomUpdateData,
RoomUpdateResponseData,
} from './type';

export const ROOM_API = {
Expand All @@ -15,10 +17,16 @@ export const ROOM_API = {
data,
},
),
getRoomList: (accommodationId: string) =>
instance.get<Response<RoomListResponseData>>(
`/api/rooms/list/${accommodationId}?pageSize={pageSize}&pageNum={pageNum}`,
getRoomList: (accommodationId: string, pageSize: number, pageNum: number) =>
instance.get<RoomListResponseData>(
`/api/rooms/list/${accommodationId}?pageSize=${pageSize}&pageNum=${pageNum}`,
),
// editRoom: (params: RoomEditParams) =>
// instance.patch<Response<null>>('/api/rooms/{roomId}', params),
deleteRoom: (roomId: number) =>
instance.delete<Response<RoomDeleteResponseData>>(`/api/rooms/${roomId}`),
getRoomDetail: (roomId: string) =>
instance.get<RoomDeleteResponseData>(`/api/rooms/${roomId}`),
updateRoom: (data: RoomUpdateData, roomId: string) =>
instance.put<Response<RoomUpdateResponseData>>(`/api/rooms/${roomId}`, {
data,
}),
};
70 changes: 67 additions & 3 deletions src/api/room/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type RoomListResponseData = {
totalPages: number;
totalElements: number;
isLast: boolean;
rooms: RoomData[];
rooms: RoomCardData[];
};

export type Options = {
Expand All @@ -27,6 +27,32 @@ export type Image = {
url: string;
};

export type ImageUrls = {
urls: string[];
};

export type Coupons = {
id: number;
name: string;
price: number;
};

export type RoomCardData = {
id: number;
name: string;
price: number | null;
discountPrice: number | null;
defaultCapacity: number | null;
maxCapacity: number | null;
checkInTime: string;
checkOutTime: string;
amount: number | null;
images: Image[];
option: Options;
coupons: Coupons[];
status: string;
};

export type RoomData = {
name: string;
price: number | null;
Expand All @@ -53,6 +79,44 @@ export type RoomPostResponseData = {
options: Options;
};

export type AccommodationData = {
accommodationId: number;
export type RoomDeleteResponseData = {
id: number;
name: string;
price: number;
defaultCapacity: number | null;
maxCapacity: number | null;
checkInTime: string;
checkOutTime: string;
soldOut: boolean;
amount: number;
images: Image[];
option: Options;
};

export type RoomUpdateData = {
name: string;
price: number | null;
defaultCapacity: number | null;
maxCapacity: number | null;
checkInTime: string;
checkOutTime: string;
status: string;
amount: number | null;
addImages: Image[];
removeImages: Image[];
options: Options;
};

export type RoomUpdateResponseData = {
id: number;
name: string;
price: number | null;
defaultCapacity: number | null;
maxCapacity: number | null;
checkInTime: string;
checkOutTime: string;
status: string;
amount: number | null;
images: Image[];
options: Options;
};
4 changes: 2 additions & 2 deletions src/assets/data/roomData.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"amount": 5,
"images": [
{
"url": "https://images/pension_room2_2.webp"
"url": "http://tong.visitkorea.or.kr/cms/resource/77/2876777_image2_1.jpg"
},
{
"url": "https://images/pension_room2_1.webp"
"url": "http://tong.visitkorea.or.kr/cms/resource/77/2876777_image2_1.jpg"
}
],
"option": {
Expand Down
27 changes: 27 additions & 0 deletions src/assets/data/roomDeleteData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"message": "성공적으로 객실을 삭제했습니다.",
"data": {
"id": 289,
"name": "",
"price": 100000,
"defaultCapacity": 2,
"maxCapacity": 6,
"checkInTime": "15:00",
"checkOutTime": "12:00",
"soldOut": false,
"count": 5,
"images": [
{
"url": "https://images/pension_room2_2.webp"
},
{
"url": "https://images/pension_room2_1.webp"
}
],
"options": {
"airCondition": true,
"tv": true,
"internet": true
}
}
}
29 changes: 29 additions & 0 deletions src/assets/data/roomDetailData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"message": "성공적으로 객실을 조회했습니다.",
"data": {
"id": 1,
"name": "",
"price": 100000,
"defaultCapacity": 2,
"maxCapacity": 6,
"checkInTime": "15:00",
"checkOutTime": "12:00",
"soldOut": false,
"count": 5,
"images": [
{
"roomImageId": 1,
"url": "http://tong.visitkorea.or.kr/cms/resource/77/2876777_image2_1.jpg"
},
{
"roomImageId": 2,
"url": "http://tong.visitkorea.or.kr/cms/resource/77/2876777_image2_1.jpg"
}
],
"options": {
"airCondition": true,
"tv": true,
"internet": true
}
}
}
Loading

0 comments on commit 2078e92

Please sign in to comment.