diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index a707dcb..91b1a80 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -60,8 +60,8 @@ public ResponseEntity uploadImage(@RequestParam("file") MultipartFile fi // 클래스 등록하기 @PostMapping("/lesson/create") - public void createLesson(@RequestBody CreateLessonReqDto createLessonReqDto) { - lessonService.createLesson(createLessonReqDto); + public void createLesson(@AuthenticationPrincipal Long userId, @RequestBody CreateLessonReqDto createLessonReqDto) { + lessonService.createLesson(userId, createLessonReqDto); } // 클래스 전체 조회 (클래스 탐색) diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java index 207c653..12ab0c1 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java @@ -6,7 +6,6 @@ @Getter public class CreateLessonReqDto { - private Long userId; private Long categoryId; private String title; private String location; diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index 38d58ba..7f7efae 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -16,7 +16,7 @@ public interface LessonService { LessonInfoResDto lessonInfo(Long lessonId); // 클래스 등록하기 - void createLesson(CreateLessonReqDto createLessonReqDto); + void createLesson(Long userId, CreateLessonReqDto createLessonReqDto); // 클래스 전체 조회 (클래스 탐색) List fullLesson(); diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index 300e735..7d8e331 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -79,8 +79,8 @@ public LessonInfoResDto lessonInfo(Long lessonId) { // 클래스 등록하기 @Transactional @Override - public void createLesson(CreateLessonReqDto createLessonReqDto) { - HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(createLessonReqDto.getUserId()); + public void createLesson(Long userId, CreateLessonReqDto createLessonReqDto) { + HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(userId); CategoryEntity category = categoryRepository.findById(createLessonReqDto.getCategoryId()).orElseThrow(() -> new CategoryNotFoundException()); // Lesson 추가 diff --git a/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java index 2cfdfc1..62f1af2 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java @@ -7,7 +7,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -19,7 +19,11 @@ public class LessonDateController { // 클래스 예약 가능 날짜 출력 @GetMapping("/lesson/date-select") - public ResponseEntity availableDate(@RequestBody AvailableDateReqDto availableDateReqDto) { + public ResponseEntity availableDate(@RequestParam Long lessonId) { + AvailableDateReqDto availableDateReqDto = AvailableDateReqDto.builder() + .lessonId(lessonId) + .build(); + List availableDateResDtoList = lessonDateService.availableDate(availableDateReqDto); return ResponseEntity.ok(new ApiResponse<>(true, "ok", availableDateResDtoList)); } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java index be291bd..865db2d 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java @@ -1,7 +1,9 @@ package com.hanaro.hanafun.lessondate.dto.request; +import lombok.Builder; import lombok.Getter; +@Builder @Getter public class AvailableDateReqDto { private Long lessonId; diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 1d4040f..475314f 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -54,8 +54,8 @@ public ResponseEntity lessonDateDetail(@RequestBody LessonDateDetai // 클래스 예약하기 (결제 제외) @PostMapping("/check") - public ResponseEntity bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) { - BookLessonResDto bookLessonResDto = reservationService.bookLesson(bookLessonReqDto); + public ResponseEntity bookLesson(@AuthenticationPrincipal Long userId, @RequestBody BookLessonReqDto bookLessonReqDto) { + BookLessonResDto bookLessonResDto = reservationService.bookLesson(userId, bookLessonReqDto); return ResponseEntity.ok(new ApiResponse<>(true, "ok", bookLessonResDto)); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java index 271d8a9..7688d89 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java @@ -5,7 +5,6 @@ @Getter public class BookLessonReqDto { private Long lessondateId; - private Long userId; private int applicant; // 예약 수량 private Long accountId; private String password; // 계좌 비밀번호 확인 diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 43c42d8..f8a8b93 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -19,7 +19,7 @@ public interface ReservationService { LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); // 클래스 예약하기 (결제 제외) - BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto); + BookLessonResDto bookLesson(Long userId, BookLessonReqDto bookLessonReqDto); // 클래스 취소하기 (환불 제외) void cancelLesson(CancelLessonReqDto cancelLessonReqDto); diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 3eba127..bdd040c 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -165,7 +165,7 @@ public LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDate // 클래스 예약하기 (결제 제외) @Transactional @Override - public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { + public BookLessonResDto bookLesson(Long userId, BookLessonReqDto bookLessonReqDto) { // 계좌 비밀번호 확인 AccountEntity account = accountRepository.findById(bookLessonReqDto.getAccountId()).orElseThrow(() -> new AccountNotFoundException()); if (!account.getPassword().equals(bookLessonReqDto.getPassword())) { @@ -184,8 +184,7 @@ public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { } // 해당 날짜에 예약 이미 있는지 확인 - Optional existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId( - bookLessonReqDto.getUserId(), bookLessonReqDto.getLessondateId()); + Optional existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId(userId, bookLessonReqDto.getLessondateId()); if (existingReservation.isPresent()) { return BookLessonResDto.builder() .message("이미 예약이 존재합니다.") @@ -193,7 +192,7 @@ public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { } // 예약 추가 - UserEntity user = userRepository.findUserEntityByUserId(bookLessonReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); + UserEntity user = userRepository.findUserEntityByUserId(userId).orElseThrow(() -> new UserNotFoundException()); ReservationEntity reservation = ReservationEntity.builder() .userEntity(user) .lessonDateEntity(lessonDate)