-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 회의실 예약 api 연동 #158
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
The head ref may contain hidden characters: "146-feat-\uD68C\uC758\uC2E4-\uC608\uC57D-api-\uC5F0\uB3D9"
[Feat] 회의실 예약 api 연동 #158
Changes from all commits
2227752
6035d2d
b59b319
ba36929
a965e5e
edec6c4
b699d6a
5d172a9
89256a2
5455e74
ff0a603
bcd7153
a31a9a5
5b13d7d
68b7509
f4fe529
91538f8
36d19c4
7ca617e
148782a
7415987
bd4251d
a06463d
9adf451
8741df0
1a61069
2212335
5e9b927
1bff89b
922819e
ccacd92
63c159a
04bf146
50ecef9
eae0d8d
8c0ea9a
d43dfec
c5e6928
5e530ca
63ef483
d40cc8d
e017100
51302b2
baa7c99
7acf60f
fe70af3
f34e28e
3a13add
f40963b
8e1d62f
470e286
68f7525
50de238
4c49e9a
231f0d6
c3fe489
0a93601
fdb399a
66e93ae
46827bc
40141c4
6cd3733
607ef16
2b8e892
e07c405
e2e7d37
039ce1c
47c3efb
5c113e8
2ffd91e
740b31f
35b4ee8
3fbdd59
8f8e3c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { API_ENDPOINTS } from "@repo/constants"; | ||
| import { type IReservation, type TReservationStatus } from "@repo/types/src/reservationType"; | ||
| import { axiosRequester } from "@/lib/axios"; | ||
|
|
||
| // 특정 유저의 오늘 날짜 예약 전체 조회 | ||
| interface GetUserReservationsParams { | ||
| userId: string; | ||
| } | ||
|
|
||
| export const getUserReservations = async (params: GetUserReservationsParams): Promise<IReservation[]> => { | ||
| const { userId } = params; | ||
| const { data } = await axiosRequester<IReservation[]>({ | ||
| options: { | ||
| method: "GET", | ||
| url: API_ENDPOINTS.RESERVATION.GET_USER_RESERVATIONS(userId), | ||
| }, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| // 아이템 타입 및 날짜에 대한 예약 조회 | ||
| interface GetReservationsByTypeAndDateParams { | ||
| itemType: "room" | "seat" | "equipment"; | ||
| date: string; | ||
| status?: TReservationStatus; | ||
| } | ||
|
|
||
| export const getReservationsByTypeAndDate = async ( | ||
| params: GetReservationsByTypeAndDateParams, | ||
| ): Promise<IReservation[]> => { | ||
| const { itemType, date, status } = params; | ||
| const { data } = await axiosRequester<IReservation[]>({ | ||
| options: { | ||
| method: "GET", | ||
| url: API_ENDPOINTS.RESERVATION.GET_RESERVATIONS_BY_TYPE_AND_DATE(itemType, date), | ||
| params: { | ||
| status, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| // 예약 생성 | ||
| export interface CreateReservationParams { | ||
| itemId: string; | ||
| savedReservation: IReservation; | ||
| } | ||
|
|
||
| export interface CreateReservationRequest { | ||
| userId: string; | ||
| itemType: "room"; | ||
| startAt: string; | ||
| endAt: string; | ||
| status: "reserved"; | ||
| notes: string; | ||
| attendees: string[]; | ||
| } | ||
|
Comment on lines
+52
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
다음과 같이 수정할 것을 제안합니다: export interface CreateReservationRequest {
userId: string;
- itemType: "room";
+ itemType: "room" | "seat" | "equipment";
startAt: string;
endAt: string;
- status: "reserved";
+ status: TReservationStatus;
notes: string;
attendees: string[];
}
|
||
|
|
||
| export interface CreateReservationResponse { | ||
| message: string; | ||
| savedReservation: IReservation; | ||
| } | ||
|
|
||
| export const createReservation = async ( | ||
| itemId: string, | ||
| reservationData: CreateReservationRequest, | ||
| ): Promise<IReservation> => { | ||
| const { data } = await axiosRequester<CreateReservationResponse>({ | ||
| options: { | ||
| method: "POST", | ||
| url: API_ENDPOINTS.RESERVATION.CREATE_RESERVATION(itemId), | ||
| data: reservationData, | ||
| }, | ||
| }); | ||
|
|
||
| return data.savedReservation; | ||
| }; | ||
|
Comment on lines
+71
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 에러 핸들링 추가 필요
다음과 같이 코드에 에러 핸들링을 추가할 수 있습니다: export const createReservation = async (
itemId: string,
reservationData: CreateReservationRequest,
): Promise<IReservation> => {
- const { data } = await axiosRequester<CreateReservationResponse>({
- options: {
- method: "POST",
- url: API_ENDPOINTS.RESERVATION.CREATE_RESERVATION(itemId),
- data: reservationData,
- },
- });
-
- return data.savedReservation;
+ try {
+ const { data } = await axiosRequester<CreateReservationResponse>({
+ options: {
+ method: "POST",
+ url: API_ENDPOINTS.RESERVATION.CREATE_RESERVATION(itemId),
+ data: reservationData,
+ },
+ });
+
+ return data.savedReservation;
+ } catch (error) {
+ // 에러 처리 로직 추가
+ throw error;
+ }
};
|
||
|
|
||
| export interface UpdateReservationRequest { | ||
| startAt?: string; | ||
| endAt?: string; | ||
| status?: TReservationStatus; | ||
| notes?: string; | ||
| attendees?: string[]; | ||
| } | ||
|
|
||
| export interface UpdateReservationResponse { | ||
| message: string; | ||
| updatedReservation: IReservation; | ||
| } | ||
|
|
||
| export const updateReservation = async ( | ||
| reservationId: string, | ||
| reservationData: UpdateReservationRequest, | ||
| ): Promise<IReservation> => { | ||
| const { data } = await axiosRequester<UpdateReservationResponse>({ | ||
| options: { | ||
| method: "PATCH", | ||
| url: API_ENDPOINTS.RESERVATION.UPDATE_RESERVATION(reservationId), | ||
| data: reservationData, | ||
| }, | ||
| }); | ||
|
|
||
| return data.updatedReservation; | ||
| }; | ||
|
Comment on lines
+95
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
다음과 같이 수정할 수 있습니다: export const updateReservation = async (
reservationId: string,
reservationData: UpdateReservationRequest,
): Promise<IReservation> => {
- const { data } = await axiosRequester<UpdateReservationResponse>({
- options: {
- method: "PATCH",
- url: API_ENDPOINTS.RESERVATION.UPDATE_RESERVATION(reservationId),
- data: reservationData,
- },
- });
-
- return data.updatedReservation;
+ try {
+ const { data } = await axiosRequester<UpdateReservationResponse>({
+ options: {
+ method: "PATCH",
+ url: API_ENDPOINTS.RESERVATION.UPDATE_RESERVATION(reservationId),
+ data: reservationData,
+ },
+ });
+
+ return data.updatedReservation;
+ } catch (error) {
+ // 에러 처리 로직 추가
+ throw error;
+ }
};
|
||
|
|
||
| export const deleteReservation = async (reservationId: string): Promise<void> => { | ||
| await axiosRequester({ | ||
| options: { | ||
| method: "DELETE", | ||
| url: API_ENDPOINTS.RESERVATION.DELETE_RESERVATION(reservationId), | ||
| }, | ||
| }); | ||
| }; | ||
|
Comment on lines
+110
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
에러 처리를 추가하려면 다음과 같이 수정할 수 있습니다: export const deleteReservation = async (reservationId: string): Promise<void> => {
- await axiosRequester({
- options: {
- method: "DELETE",
- url: API_ENDPOINTS.RESERVATION.DELETE_RESERVATION(reservationId),
- },
- });
+ try {
+ await axiosRequester({
+ options: {
+ method: "DELETE",
+ url: API_ENDPOINTS.RESERVATION.DELETE_RESERVATION(reservationId),
+ },
+ });
+ } catch (error) {
+ // 에러 처리 로직 추가
+ throw error;
+ }
};
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect, useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface UseCurrentTimePositionProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slotWidth: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startHour: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endHour: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+7
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. props보다는 prams로 이름짓는건 어떨까?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 그렇네 hook이였네 이걸 어케봤담 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface UseCurrentTimePositionReturn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentPosition: number | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentTime: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return type 같은데 return 보다는 result로 이름짓는건 어떨까? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function useCurrentTimePosition({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slotWidth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startHour, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endHour, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: UseCurrentTimePositionProps): UseCurrentTimePositionReturn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [currentPosition, setCurrentPosition] = useState<number | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [currentTime, setCurrentTime] = useState<string>(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updatePosition = (): void => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const now = new Date(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentMinutes = now.getHours() * 60 + now.getMinutes(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const totalMinutes = (endHour - startHour) * 60; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentMinutes < startHour * 60 || currentMinutes >= endHour * 60) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCurrentPosition(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCurrentTime(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const relativeMinutes = currentMinutes - startHour * 60; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const scheduleWidth = slotWidth * (endHour - startHour) * 2; // Assuming 30-minute slots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const position = (relativeMinutes / totalMinutes) * scheduleWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCurrentPosition(position); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hours = String(now.getHours()).padStart(2, "0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const minutes = String(now.getMinutes()).padStart(2, "0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCurrentTime(`${hours}:${minutes}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updatePosition(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const interval = setInterval(updatePosition, 60000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clearInterval(interval); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [slotWidth, startHour, endHour]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion useEffect 구현에 대한 몇 가지 개선사항이 있습니다.
다음과 같은 개선을 제안합니다: +const MINUTE_IN_MS = 60000;
+const MINUTES_PER_HOUR = 60;
+
+const calculateTimePosition = (
+ now: Date,
+ startHour: number,
+ endHour: number,
+ slotWidth: number,
+): number | null => {
+ const currentMinutes = now.getHours() * MINUTES_PER_HOUR + now.getMinutes();
+ const totalMinutes = (endHour - startHour) * MINUTES_PER_HOUR;
+
+ if (currentMinutes < startHour * MINUTES_PER_HOUR || currentMinutes >= endHour * MINUTES_PER_HOUR) {
+ return null;
+ }
+
+ const relativeMinutes = currentMinutes - startHour * MINUTES_PER_HOUR;
+ const scheduleWidth = slotWidth * (endHour - startHour) * 2;
+ return (relativeMinutes / totalMinutes) * scheduleWidth;
+};
+
+const formatTime = (date: Date): string => {
+ const hours = String(date.getHours()).padStart(2, "0");
+ const minutes = String(date.getMinutes()).padStart(2, "0");
+ return `${hours}:${minutes}`;
+};
useEffect(() => {
const updatePosition = (): void => {
const now = new Date();
- const currentMinutes = now.getHours() * 60 + now.getMinutes();
- const totalMinutes = (endHour - startHour) * 60;
-
- if (currentMinutes < startHour * 60 || currentMinutes >= endHour * 60) {
- setCurrentPosition(null);
- setCurrentTime("");
- return;
- }
-
- const relativeMinutes = currentMinutes - startHour * 60;
- const scheduleWidth = slotWidth * (endHour - startHour) * 2;
- const position = (relativeMinutes / totalMinutes) * scheduleWidth;
-
+ const position = calculateTimePosition(now, startHour, endHour, slotWidth);
setCurrentPosition(position);
-
- const hours = String(now.getHours()).padStart(2, "0");
- const minutes = String(now.getMinutes()).padStart(2, "0");
- setCurrentTime(`${hours}:${minutes}`);
+ setCurrentTime(position === null ? "" : formatTime(now));
};
updatePosition();
- const interval = setInterval(updatePosition, 60000);
+ const interval = setInterval(updatePosition, MINUTE_IN_MS);
return () => {
clearInterval(interval);
};
}, [slotWidth, startHour, endHour]);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { currentPosition, currentTime }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
| import { useMemo } from "react"; | ||
| import { type IReservation } from "@repo/types"; | ||
| import { timeToMinutes } from "../utils/timeToMinutes"; | ||
|
|
||
| /** | ||
| * 예약 데이터를 슬롯 인덱스에 매핑하는 커스텀 훅 | ||
| * @param schedules 예약 데이터 배열 | ||
| * @param startHour 시작 시간 | ||
| * @param endHour 종료 시간 | ||
| * @param minutesPerSlot 슬롯당 분 단위 | ||
| * @returns 슬롯별 예약 상태 배열 | ||
| */ | ||
| export const useSlotReservations = ( | ||
| schedules: IReservation[], | ||
| startHour: number, | ||
| endHour: number, | ||
| minutesPerSlot: number, | ||
| ): (IReservation | null)[] => { | ||
|
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 입력값 유효성 검사 추가 필요 startHour, endHour, minutesPerSlot에 대한 유효성 검사가 없습니다. 잘못된 입력값으로 인한 예기치 않은 동작을 방지하기 위해 검증 로직이 필요합니다. 다음과 같은 검증 로직 추가를 제안합니다: export const useSlotReservations = (
schedules: IReservation[],
startHour: number,
endHour: number,
minutesPerSlot: number,
): (IReservation | null)[] => {
+ if (startHour >= endHour) {
+ throw new Error('시작 시간은 종료 시간보다 작아야 합니다.');
+ }
+ if (minutesPerSlot <= 0 || minutesPerSlot > 60) {
+ throw new Error('슬롯당 분은 1-60 사이여야 합니다.');
+ }
return useMemo(() => { |
||
| return useMemo(() => { | ||
| const totalSlots = (endHour - startHour) * 2; // 30분 단위 | ||
| const slotReservations: (IReservation | null)[] = Array(totalSlots).fill(null); | ||
|
|
||
| schedules.forEach((schedule) => { | ||
| const startMinutes = timeToMinutes(schedule.startAt) - startHour * 60; | ||
| const endMinutes = timeToMinutes(schedule.endAt) - startHour * 60; | ||
|
|
||
| const startIndex = Math.floor(startMinutes / minutesPerSlot); | ||
| const endIndex = Math.ceil(endMinutes / minutesPerSlot); | ||
|
|
||
| for (let i = startIndex; i < endIndex; i++) { | ||
| if (i >= 0 && i < totalSlots) { | ||
| slotReservations[i] = schedule; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return slotReservations; | ||
| }, [schedules, startHour, endHour, minutesPerSlot]); | ||
| }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const MEETING_ROOMS_TYPE = "room"; |
Uh oh!
There was an error while loading. Please reload this page.