Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/HanaFun/HanaFun_BE into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Do760 committed Jul 5, 2024
2 parents 13fea51 + c0fc571 commit 3b96239
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public ResponseEntity<ApiResponse> lessonDetail(@PathVariable Long lessonId) {

// 클래스 상세보기
@GetMapping("/lesson/{lessonId}")
public ResponseEntity<ApiResponse> lessonInfo(@PathVariable Long lessonId) {
LessonInfoResDto lessonInfoResDto = lessonService.lessonInfo(lessonId);
public ResponseEntity<ApiResponse> lessonInfo(@AuthenticationPrincipal Long userId, @PathVariable Long lessonId) {
LessonInfoResDto lessonInfoResDto = lessonService.lessonInfo(userId, lessonId);
return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonInfoResDto));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class FullLessonResDto {
private String title;
private int price;
private String hostName;
private int applicantSum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class LessonInfoResDto {
private String materials;
private int capacity;
private String categoryName;
private boolean isHostMe;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface LessonService {
List<OpenedLessonsResDto> openedLessons(Long userId);

// 클래스 상세보기
LessonInfoResDto lessonInfo(Long lessonId);
LessonInfoResDto lessonInfo(Long userId, Long lessonId);

// 클래스 등록하기
void createLesson(Long userId, CreateLessonReqDto createLessonReqDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.hanaro.hanafun.lesson.service.LessonService;
import com.hanaro.hanafun.lessondate.domain.LessonDateEntity;
import com.hanaro.hanafun.lessondate.domain.LessonDateRepository;
import com.hanaro.hanafun.user.domain.UserEntity;
import com.hanaro.hanafun.user.domain.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -55,9 +57,17 @@ public List<OpenedLessonsResDto> openedLessons(Long userId) {
// 클래스 상세보기
@Transactional
@Override
public LessonInfoResDto lessonInfo(Long lessonId) {
public LessonInfoResDto lessonInfo(Long userId, Long lessonId) {
LessonEntity lesson = lessonRepository.findById(lessonId).orElseThrow(() -> new LessonNotFoundException());

// 해당 클래스의 호스트가 로그인한 유저인지 확인
boolean isHostMe;
if(userId.equals(lesson.getHostEntity().getUserEntity().getUserId())) {
isHostMe = true;
} else {
isHostMe = false;
}

LessonInfoResDto lessonInfoResDto = LessonInfoResDto.builder()
.lessonId(lessonId)
.image(lesson.getImage())
Expand All @@ -68,6 +78,7 @@ public LessonInfoResDto lessonInfo(Long lessonId) {
.materials(lesson.getMaterials())
.capacity(lesson.getCapacity())
.categoryName(lesson.getCategoryEntity().getCategoryName())
.isHostMe(isHostMe)
.build();

return lessonInfoResDto;
Expand Down Expand Up @@ -182,6 +193,7 @@ public List<FullLessonResDto> searchLessonList(List<LessonEntity> lessonlist){
.title(lesson.getTitle())
.price(lesson.getPrice())
.hostName(lesson.getHostEntity().getUserEntity().getUsername())
.applicantSum(lesson.getApplicantSum())
.build();
return fullLessonResDto;
}).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.hanaro.hanafun.reservation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BookLessonReqDto {
private Long lessondateId;
private int applicant; // 예약 수량
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.hanaro.hanafun.reservation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CancelLessonReqDto {
private Long reservationId;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.hanaro.hanafun.reservation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class LessonDateDetailReqDto {
private Long lessondateId;
}
4 changes: 2 additions & 2 deletions src/test/java/com/hanaro/hanafun/LessonServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void lessonInfoTest_Success() {
when(lessonRepository.findById(lessonId1)).thenReturn(Optional.of(lesson1));

// When
LessonInfoResDto result = lessonService.lessonInfo(lessonId1);
LessonInfoResDto result = lessonService.lessonInfo(userId1, lessonId1);

// Then
assertEquals(lessonId1, result.getLessonId());
Expand All @@ -164,7 +164,7 @@ void lessonInfoTest_Fail() {

// When, Then
assertThrows(LessonNotFoundException.class, () -> {
lessonService.lessonInfo(lessonId1);
lessonService.lessonInfo(userId1, lessonId1);
});
}

Expand Down
Loading

0 comments on commit 3b96239

Please sign in to comment.