Skip to content

Commit

Permalink
Merge pull request #70 from HanaFun/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yubin-im authored Jul 3, 2024
2 parents ffdc7fc + e430294 commit ae3cb09
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -48,7 +50,10 @@ public List<LessonDetailResDto> lessonDetail(Long lessonId) {
public List<AvailableDateResDto> availableDate(AvailableDateReqDto availableDateReqDto) {
List<LessonDateEntity> lessonDates = lessonDateRepository.findLessonDateEntitiesByLessonEntity_LessonId(availableDateReqDto.getLessonId());

LocalDate today = LocalDate.now();

List<AvailableDateResDto> availableDateResDtos = lessonDates.stream()
.filter(lessonDate -> lessonDate.getDate().isAfter(today) || lessonDate.getDate().isEqual(today))
.map(lessonDate -> {
LessonEntity lesson = lessonDate.getLessonEntity();
int quantityLeft = lesson.getCapacity() - lessonDate.getApplicant();
Expand All @@ -67,6 +72,7 @@ public List<AvailableDateResDto> availableDate(AvailableDateReqDto availableDate
.build();
})
.filter(Objects::nonNull)
.sorted(Comparator.comparing(AvailableDateResDto::getDate))
.collect(Collectors.toList());

return availableDateResDtos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ResponseEntity<ApiResponse> bookLesson(@AuthenticationPrincipal Long user

// 클래스 취소하기 (환불 제외)
@PostMapping("/cancel")
public void cancelLesson(@RequestBody CancelLessonReqDto cancelLessonReqDto) {
reservationService.cancelLesson(cancelLessonReqDto);
public CancelLessonResDto cancelLesson(@RequestBody CancelLessonReqDto cancelLessonReqDto) {
return reservationService.cancelLesson(cancelLessonReqDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hanaro.hanafun.reservation.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CancelLessonResDto {
private boolean isSuccess;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface ReservationService {
BookLessonResDto bookLesson(Long userId, BookLessonReqDto bookLessonReqDto);

// 클래스 취소하기 (환불 제외)
void cancelLesson(CancelLessonReqDto cancelLessonReqDto);
CancelLessonResDto cancelLesson(CancelLessonReqDto cancelLessonReqDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,24 @@ public BookLessonResDto bookLesson(Long userId, BookLessonReqDto bookLessonReqDt
lessonRepository.save(lesson);

return BookLessonResDto.builder()
.message("예약완료")
.message(String.valueOf(reservation.getReservationId()))
.build();
}

// 클래스 취소하기 (환불 제외)
@Transactional
@Override
public void cancelLesson(CancelLessonReqDto cancelLessonReqDto) {
ReservationEntity reservation = reservationRepository.findById(cancelLessonReqDto.getReservationId()).orElseThrow(() -> new ReservationNotFounException());
public CancelLessonResDto cancelLesson(CancelLessonReqDto cancelLessonReqDto) {
// 예약 조회
ReservationEntity reservation = reservationRepository.findById(cancelLessonReqDto.getReservationId()).orElse(null);

// 예약이 없는 경우
if (reservation == null) {
return CancelLessonResDto.builder()
.isSuccess(false)
.message("취소 실패: 예약을 찾을 수 없습니다.")
.build();
}

// 클래스 취소 (논리적 삭제)
reservation.updateIsDeleted(true);
Expand All @@ -232,5 +241,11 @@ public void cancelLesson(CancelLessonReqDto cancelLessonReqDto) {
LessonEntity lesson = lessonDate.getLessonEntity();
lesson.updateApplicantSum(lesson.getApplicantSum() - reservation.getApplicant());
lessonRepository.save(lesson);

// 취소 성공 response
return CancelLessonResDto.builder()
.isSuccess(true)
.message("취소 성공")
.build();
}
}

0 comments on commit ae3cb09

Please sign in to comment.