Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -11,7 +10,7 @@ public record BoothReserveManageResponse(
String description,
int price,
String imageUrl,
List<BoothReservationDateDto> dates
List<BoothReservationDateDto> reservations
) {
public static BoothReserveManageResponse of(BoothReservationDto reservation){
return new BoothReserveManageResponse(
Expand All @@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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;


Expand All @@ -13,7 +12,7 @@ public record BoothReserveResponse(
String description,
int price,
String imageUrl,
List<BoothReservationDateDto> reserveInfo
List<BoothReservationDateDto> reservations
) {
public static BoothReserveResponse of(BoothReservationDto reservation){

Expand All @@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "중복 되는 시간 데이터가 있습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoothReservationDetail, Long> {
List<BoothReservationDetail> findByLinkedReservationId(Long reservationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Repository
public interface BoothReservationRepository extends JpaRepository<BoothReservation, Long> {
@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<BoothReservation> findBoothReservationByLinkedBoothId(Long boothId);
boolean existsByLinkedBoothIdAndDateAndName(Long boothId, LocalDate date, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -42,6 +44,15 @@ public void createReservationDetail(List<String> times, BoothReservation reserva
}
}

public List<BoothReservationDetailDto> getReservationDetails(Long reserveId) {
List<BoothReservationDetail> details = boothReservationDetailRepository
.findByLinkedReservationId(reserveId);

return details.stream()
.map(BoothReservationDetailDto::of)
.collect(Collectors.toList());
}

private void checkAvailableTime(List<String> times, Booth booth){
Set<String> validTimes = new HashSet<>();
times.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -52,13 +57,43 @@ public List<BoothReservationDto> 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<BoothReservationDto> 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<BoothReservationDto> getGroupReservation(Long boothId){
List<BoothReservation> reservations = getBoothReservations(boothId);
Map<String, List<BoothReservation>> groupedByName = reservations.stream()
.collect(Collectors.groupingBy(BoothReservation::getName));

return groupedByName.values().stream()
.map(groupedReservations -> {
BoothReservation firstReservation = groupedReservations.get(0);
List<BoothReservationDateDto> reservationsByDate = groupedReservations.stream()
.collect(Collectors.groupingBy(BoothReservation::getDate))
.entrySet().stream()
.map(dateEntry -> {
LocalDate date = dateEntry.getKey();
List<BoothReservationDetailDto> 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){
Expand All @@ -73,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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +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(
String date,
List<BoothReservationDetailDto> times
) {
public static BoothReservationDateDto of(LocalDate date, List<BoothReservationDetailDto> times) {
return new BoothReservationDateDto(Formatter.getFormattingDate(date.atStartOfDay()), times);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
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,
String name,
String description,
String imageUrl,
int price,
Map<LocalDate, List<BoothReservationDetailDto>> groupedDetails
LocalDate date,
List<BoothReservationDateDto> details
) {
public static BoothReservationDto of(BoothReservation boothReservation) {
public static BoothReservationDto of(BoothReservation boothReservation, List<BoothReservationDateDto> 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
);
}
}
Loading