From 9306604f927a5fd7a8078d01993fc7f953125785 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 15:58:17 +0900 Subject: [PATCH 1/7] =?UTF-8?q?Refactor:=20=EC=98=88=EC=95=BD=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20response=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=95=84=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/BoothReserveManageResponse.java | 8 ++------ .../booth/response/BoothReserveResponse.java | 18 +++--------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveManageResponse.java b/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveManageResponse.java index dba12c13..0c6e3fb5 100644 --- a/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveManageResponse.java +++ b/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveManageResponse.java @@ -2,7 +2,6 @@ import com.openbook.openbook.service.booth.dto.BoothReservationDateDto; import com.openbook.openbook.service.booth.dto.BoothReservationDto; -import com.openbook.openbook.util.Formatter; import java.util.List; public record BoothReserveManageResponse( @@ -11,7 +10,7 @@ public record BoothReserveManageResponse( String description, int price, String imageUrl, - List dates + List reservations ) { public static BoothReserveManageResponse of(BoothReservationDto reservation){ return new BoothReserveManageResponse( @@ -20,10 +19,7 @@ public static BoothReserveManageResponse of(BoothReservationDto reservation){ reservation.description(), reservation.price(), reservation.imageUrl(), - reservation.groupedDetails().entrySet().stream() - .map(entry -> new BoothReservationDateDto( - Formatter.getFormattingDate(entry.getKey().atStartOfDay()), entry.getValue())) - .toList() + reservation.details() ); } } diff --git a/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveResponse.java b/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveResponse.java index 65fd15a4..a5675263 100644 --- a/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveResponse.java +++ b/src/main/java/com/openbook/openbook/api/booth/response/BoothReserveResponse.java @@ -1,9 +1,8 @@ package com.openbook.openbook.api.booth.response; import com.openbook.openbook.service.booth.dto.BoothReservationDateDto; -import com.openbook.openbook.service.booth.dto.BoothReservationDetailDto; import com.openbook.openbook.service.booth.dto.BoothReservationDto; -import com.openbook.openbook.util.Formatter; + import java.util.List; @@ -13,7 +12,7 @@ public record BoothReserveResponse( String description, int price, String imageUrl, - List reserveInfo + List reservations ) { public static BoothReserveResponse of(BoothReservationDto reservation){ @@ -23,18 +22,7 @@ public static BoothReserveResponse of(BoothReservationDto reservation){ reservation.description(), reservation.price(), reservation.imageUrl(), - reservation.groupedDetails().entrySet().stream() - .map(entry -> new BoothReservationDateDto( - Formatter.getFormattingDate(entry.getKey().atStartOfDay()), - entry.getValue().stream() - .map(detail -> new BoothReservationDetailDto( - detail.id(), - detail.times(), - detail.status(), - null - )).toList() - )) - .toList() + reservation.details() ); } } From 063f44f20856cdb2a91ab53ad29e55358ee79dc0 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 16:03:02 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Refactor:=20dto=20=EA=B0=92=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/booth/dto/BoothReservationDateDto.java | 6 +++++- .../service/booth/dto/BoothReservationDto.java | 14 +++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java index 5d102f21..1a468feb 100644 --- a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java +++ b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java @@ -1,9 +1,13 @@ package com.openbook.openbook.service.booth.dto; +import java.time.LocalDate; import java.util.List; public record BoothReservationDateDto( - String date, + LocalDate date, List times ) { + public static BoothReservationDateDto of(LocalDate date, List times) { + return new BoothReservationDateDto(date, times); + } } diff --git a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDto.java b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDto.java index 8f8b0adb..1f0341e4 100644 --- a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDto.java +++ b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDto.java @@ -3,8 +3,6 @@ import com.openbook.openbook.domain.booth.BoothReservation; import java.time.LocalDate; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; public record BoothReservationDto( long id, @@ -12,20 +10,18 @@ public record BoothReservationDto( String description, String imageUrl, int price, - Map> groupedDetails + LocalDate date, + List details ) { - public static BoothReservationDto of(BoothReservation boothReservation) { + public static BoothReservationDto of(BoothReservation boothReservation, List details) { return new BoothReservationDto( boothReservation.getId(), boothReservation.getName(), boothReservation.getDescription(), boothReservation.getImageUrl(), boothReservation.getPrice(), - boothReservation.getBoothReservationDetails().stream() - .collect(Collectors.groupingBy( - detail -> detail.getLinkedReservation().getDate(), - Collectors.mapping(BoothReservationDetailDto::of, Collectors.toList()) - )) + boothReservation.getDate(), + details ); } } From 6203a3905d2b3dcf41f57b767bc1f5ee0ff41371 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 16:06:41 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Refactor:=20=EC=9D=B4=EB=A6=84=EA=B3=BC=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=20=EA=B7=B8=EB=A3=B9=ED=99=94=20=EC=8B=9C?= =?UTF-8?q?=ED=82=A4=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../booth/BoothReservationService.java | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java b/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java index e593adc1..39dca254 100644 --- a/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java +++ b/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java @@ -9,6 +9,8 @@ import com.openbook.openbook.domain.booth.BoothReservation; import com.openbook.openbook.domain.user.dto.AlarmType; import com.openbook.openbook.repository.booth.BoothReservationRepository; +import com.openbook.openbook.service.booth.dto.BoothReservationDateDto; +import com.openbook.openbook.service.booth.dto.BoothReservationDetailDto; import com.openbook.openbook.service.booth.dto.BoothReservationDto; import com.openbook.openbook.exception.ErrorCode; import com.openbook.openbook.exception.OpenBookException; @@ -22,6 +24,9 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.springframework.transaction.annotation.Transactional; @Service @@ -52,13 +57,43 @@ public List getReservationsByBooth(long boothId){ if(!booth.getStatus().equals(BoothStatus.APPROVE)){ throw new OpenBookException(ErrorCode.BOOTH_NOT_APPROVED); } - return getBoothReservations(booth.getId()).stream().map(BoothReservationDto::of).toList(); + return getGroupReservation(boothId); } @Transactional public List getAllManageReservations(Long userId, Long boothId){ - Booth booth = getValidBoothOrException(userId, boothId); - return getBoothReservations(booth.getId()).stream().map(BoothReservationDto::of).toList(); + Booth booth = boothService.getBoothOrException(boothId); + if(!booth.getManager().getId().equals(userId)){ + throw new OpenBookException(ErrorCode.FORBIDDEN_ACCESS); + } + return getGroupReservation(boothId); + } + + private List getGroupReservation(Long boothId){ + List reservations = getBoothReservations(boothId); + Map> groupedByName = reservations.stream() + .collect(Collectors.groupingBy(BoothReservation::getName)); + + return groupedByName.values().stream() + .map(groupedReservations -> { + BoothReservation firstReservation = groupedReservations.get(0); + List reservationsByDate = groupedReservations.stream() + .collect(Collectors.groupingBy(BoothReservation::getDate)) + .entrySet().stream() + .map(dateEntry -> { + LocalDate date = dateEntry.getKey(); + List details = dateEntry.getValue().stream() + .flatMap(reservation -> reservationDetailService + .getReservationDetails(reservation.getId()).stream()) + .collect(Collectors.toList()); + + return BoothReservationDateDto.of(date, details); + }) + .collect(Collectors.toList()); + + return BoothReservationDto.of(firstReservation, reservationsByDate); + }) + .collect(Collectors.toList()); } public void reserveBooth(Long userId, Long detailId){ From 059b6e2d2e29446fd47334ce51193136688b13f9 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 16:07:29 +0900 Subject: [PATCH 4/7] =?UTF-8?q?Refactor:=20=EC=98=88=EC=95=BD=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EC=97=90=20=EB=A7=9E=EB=8A=94=20detail=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/booth/BoothReservationDetailService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/openbook/openbook/service/booth/BoothReservationDetailService.java b/src/main/java/com/openbook/openbook/service/booth/BoothReservationDetailService.java index b4aae8d6..d12b66aa 100644 --- a/src/main/java/com/openbook/openbook/service/booth/BoothReservationDetailService.java +++ b/src/main/java/com/openbook/openbook/service/booth/BoothReservationDetailService.java @@ -8,6 +8,7 @@ import com.openbook.openbook.exception.ErrorCode; import com.openbook.openbook.exception.OpenBookException; import com.openbook.openbook.domain.user.User; +import com.openbook.openbook.service.booth.dto.BoothReservationDetailDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,6 +17,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -42,6 +44,15 @@ public void createReservationDetail(List times, BoothReservation reserva } } + public List getReservationDetails(Long reserveId) { + List details = boothReservationDetailRepository + .findByLinkedReservationId(reserveId); + + return details.stream() + .map(BoothReservationDetailDto::of) + .collect(Collectors.toList()); + } + private void checkAvailableTime(List times, Booth booth){ Set validTimes = new HashSet<>(); times.stream() From ed1cf7f29020f6d5b0de3f85272ae2bb111fb386 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 16:08:41 +0900 Subject: [PATCH 5/7] =?UTF-8?q?Refactor:=20=EC=98=88=EC=95=BD=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=20=EB=B0=98=ED=99=98=ED=95=A0=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/booth/BoothReservationDetailRepository.java | 3 +++ .../openbook/repository/booth/BoothReservationRepository.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/openbook/openbook/repository/booth/BoothReservationDetailRepository.java b/src/main/java/com/openbook/openbook/repository/booth/BoothReservationDetailRepository.java index 429011c8..3bb4db1f 100644 --- a/src/main/java/com/openbook/openbook/repository/booth/BoothReservationDetailRepository.java +++ b/src/main/java/com/openbook/openbook/repository/booth/BoothReservationDetailRepository.java @@ -4,7 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface BoothReservationDetailRepository extends JpaRepository { + List findByLinkedReservationId(Long reservationId); } diff --git a/src/main/java/com/openbook/openbook/repository/booth/BoothReservationRepository.java b/src/main/java/com/openbook/openbook/repository/booth/BoothReservationRepository.java index 3487f869..fc9737c4 100644 --- a/src/main/java/com/openbook/openbook/repository/booth/BoothReservationRepository.java +++ b/src/main/java/com/openbook/openbook/repository/booth/BoothReservationRepository.java @@ -10,7 +10,7 @@ @Repository public interface BoothReservationRepository extends JpaRepository { - @Query("SELECT b FROM BoothReservation b WHERE b.linkedBooth.id=:boothId GROUP BY b.date") + @Query("SELECT b FROM BoothReservation b WHERE b.linkedBooth.id=:boothId ") List findBoothReservationByLinkedBoothId(Long boothId); boolean existsByLinkedBoothIdAndDateAndName(Long boothId, LocalDate date, String name); } From 5afb600dd7eb2c3337dd7f2de9b79a783ad5fb51 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Tue, 5 Nov 2024 16:49:03 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Refactor:=20=EB=82=A0=EC=A7=9C=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openbook/service/booth/dto/BoothReservationDateDto.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java index 1a468feb..c5d8f6bf 100644 --- a/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java +++ b/src/main/java/com/openbook/openbook/service/booth/dto/BoothReservationDateDto.java @@ -1,13 +1,15 @@ package com.openbook.openbook.service.booth.dto; +import com.openbook.openbook.util.Formatter; + import java.time.LocalDate; import java.util.List; public record BoothReservationDateDto( - LocalDate date, + String date, List times ) { public static BoothReservationDateDto of(LocalDate date, List times) { - return new BoothReservationDateDto(date, times); + return new BoothReservationDateDto(Formatter.getFormattingDate(date.atStartOfDay()), times); } } From 0086d5d7776436840a71c7ea4271959497522b61 Mon Sep 17 00:00:00 2001 From: gitseoyeon Date: Wed, 6 Nov 2024 15:08:05 +0900 Subject: [PATCH 7/7] =?UTF-8?q?Fix:=20=EC=98=88=EC=95=BD=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/openbook/openbook/exception/ErrorCode.java | 1 + .../openbook/service/booth/BoothReservationService.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/openbook/openbook/exception/ErrorCode.java b/src/main/java/com/openbook/openbook/exception/ErrorCode.java index e34083c0..344e88bc 100644 --- a/src/main/java/com/openbook/openbook/exception/ErrorCode.java +++ b/src/main/java/com/openbook/openbook/exception/ErrorCode.java @@ -41,6 +41,7 @@ public enum ErrorCode { EVENT_NOT_APPROVED(HttpStatus.CONFLICT, "승인되지 않은 행사입니다."), BOOTH_NOT_APPROVED(HttpStatus.CONFLICT, "승인되지 않은 부스입니다."), + UNAVAILABLE_RESERVED_DATE(HttpStatus.CONFLICT, "예약 가능 날짜가 아닙니다."), UNAVAILABLE_RESERVED_TIME(HttpStatus.CONFLICT, "예약 가능 시간이 아닙니다."), ALREADY_RESERVED_DATE(HttpStatus.CONFLICT, "이미 존재하는 예약 날짜 입니다."), DUPLICATE_RESERVED_TIME(HttpStatus.CONFLICT, "중복 되는 시간 데이터가 있습니다."), diff --git a/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java b/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java index 39dca254..56173d5b 100644 --- a/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java +++ b/src/main/java/com/openbook/openbook/service/booth/BoothReservationService.java @@ -108,9 +108,8 @@ private void checkValidReservationDetail(BoothReservationDetail boothReservation if(!boothReservationDetail.getStatus().equals(BoothReservationStatus.EMPTY)) { throw new OpenBookException(ErrorCode.ALREADY_RESERVED_SERVICE); } - - if(LocalTime.parse(boothReservationDetail.getTime()).isBefore(LocalTime.now())){ - throw new OpenBookException(ErrorCode.UNAVAILABLE_RESERVED_TIME); + if(boothReservationDetail.getLinkedReservation().getDate().isBefore(LocalDate.now())){ + throw new OpenBookException(ErrorCode.UNAVAILABLE_RESERVED_DATE); } }