Skip to content

Commit

Permalink
Merge pull request #68 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 76822d0 + ad5af80 commit ffdc7fc
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public ResponseEntity<String> 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);
}

// 클래스 전체 조회 (클래스 탐색)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Getter
public class CreateLessonReqDto {
private Long userId;
private Long categoryId;
private String title;
private String location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface LessonService {
LessonInfoResDto lessonInfo(Long lessonId);

// 클래스 등록하기
void createLesson(CreateLessonReqDto createLessonReqDto);
void createLesson(Long userId, CreateLessonReqDto createLessonReqDto);

// 클래스 전체 조회 (클래스 탐색)
List<FullLessonResDto> fullLesson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 추가
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +19,11 @@ public class LessonDateController {

// 클래스 예약 가능 날짜 출력
@GetMapping("/lesson/date-select")
public ResponseEntity<ApiResponse> availableDate(@RequestBody AvailableDateReqDto availableDateReqDto) {
public ResponseEntity<ApiResponse> availableDate(@RequestParam Long lessonId) {
AvailableDateReqDto availableDateReqDto = AvailableDateReqDto.builder()
.lessonId(lessonId)
.build();

List<AvailableDateResDto> availableDateResDtoList = lessonDateService.availableDate(availableDateReqDto);
return ResponseEntity.ok(new ApiResponse<>(true, "ok", availableDateResDtoList));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public ResponseEntity<ApiResponse> lessonDateDetail(@RequestBody LessonDateDetai

// 클래스 예약하기 (결제 제외)
@PostMapping("/check")
public ResponseEntity<ApiResponse> bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) {
BookLessonResDto bookLessonResDto = reservationService.bookLesson(bookLessonReqDto);
public ResponseEntity<ApiResponse> bookLesson(@AuthenticationPrincipal Long userId, @RequestBody BookLessonReqDto bookLessonReqDto) {
BookLessonResDto bookLessonResDto = reservationService.bookLesson(userId, bookLessonReqDto);
return ResponseEntity.ok(new ApiResponse<>(true, "ok", bookLessonResDto));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@Getter
public class BookLessonReqDto {
private Long lessondateId;
private Long userId;
private int applicant; // 예약 수량
private Long accountId;
private String password; // 계좌 비밀번호 확인
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -184,16 +184,15 @@ public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) {
}

// 해당 날짜에 예약 이미 있는지 확인
Optional<ReservationEntity> existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId(
bookLessonReqDto.getUserId(), bookLessonReqDto.getLessondateId());
Optional<ReservationEntity> existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId(userId, bookLessonReqDto.getLessondateId());
if (existingReservation.isPresent()) {
return BookLessonResDto.builder()
.message("이미 예약이 존재합니다.")
.build();
}

// 예약 추가
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)
Expand Down

0 comments on commit ffdc7fc

Please sign in to comment.