Skip to content

Commit 52fd9dd

Browse files
authored
feat : 프로필에서 해당 유저의 레슨 목록조회 기능 구현, mock데이터 추가 (#102)
* feat:profile에서 레슨조회 * feat:레슨목록조회프로필용
1 parent 5710915 commit 52fd9dd

File tree

7 files changed

+576
-234
lines changed

7 files changed

+576
-234
lines changed

src/main/java/com/threestar/trainus/domain/profile/controller/ProfileController.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
import org.springframework.http.HttpStatus;
44
import org.springframework.http.ResponseEntity;
55
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.ModelAttribute;
67
import org.springframework.web.bind.annotation.PatchMapping;
78
import org.springframework.web.bind.annotation.PathVariable;
89
import org.springframework.web.bind.annotation.RequestBody;
910
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestParam;
1012
import org.springframework.web.bind.annotation.RestController;
1113

14+
import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;
1215
import com.threestar.trainus.domain.profile.dto.ImageUpdateRequestDto;
1316
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
1417
import com.threestar.trainus.domain.profile.dto.IntroUpdateRequestDto;
1518
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
19+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto;
20+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListWrapperDto;
1621
import com.threestar.trainus.domain.profile.dto.ProfileDetailResponseDto;
22+
import com.threestar.trainus.domain.profile.mapper.ProfileLessonMapper;
1723
import com.threestar.trainus.domain.profile.service.ProfileFacadeService;
24+
import com.threestar.trainus.domain.profile.service.ProfileLessonService;
1825
import com.threestar.trainus.global.annotation.LoginUser;
26+
import com.threestar.trainus.global.dto.PageRequestDto;
1927
import com.threestar.trainus.global.unit.BaseResponse;
28+
import com.threestar.trainus.global.unit.PagedResponse;
2029

2130
import io.swagger.v3.oas.annotations.Operation;
2231
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -30,6 +39,7 @@
3039
public class ProfileController {
3140

3241
private final ProfileFacadeService facadeService;
42+
private final ProfileLessonService profileLessonService;
3343

3444
@GetMapping("{userId}")
3545
@Operation(summary = "유저 프로필 상세 조회 api")
@@ -59,4 +69,22 @@ public ResponseEntity<BaseResponse<IntroUpdateResponseDto>> updateProfileIntro(
5969
IntroUpdateResponseDto response = facadeService.updateProfileIntro(loginUserId, requestDto);
6070
return BaseResponse.ok("프로필 자기소개 수정이 완료되었습니다.", response, HttpStatus.OK);
6171
}
72+
73+
@GetMapping("/{userId}/created-lessons")
74+
@Operation(summary = "프로필유저의 개설한 레슨 목록 조회 api",
75+
description = "특정 유저가 개설한 레슨 목록을 조회 -> 누구나 조회가능")
76+
public ResponseEntity<PagedResponse<ProfileCreatedLessonListWrapperDto>> getUserCreatedLessons(
77+
@PathVariable Long userId,
78+
@Valid @ModelAttribute PageRequestDto pageRequestDto,
79+
@RequestParam(required = false) LessonStatus status
80+
) {
81+
// 개설한 레슨 목록 조회
82+
ProfileCreatedLessonListResponseDto responseDto = profileLessonService
83+
.getUserCreatedLessons(userId, pageRequestDto.getPage(), pageRequestDto.getLimit(), status);
84+
85+
ProfileCreatedLessonListWrapperDto wrapperDto = ProfileLessonMapper
86+
.toProfileCreatedLessonListWrapperDto(responseDto);
87+
88+
return PagedResponse.ok("개설한 레슨 목록 조회 완료.", wrapperDto, responseDto.count(), HttpStatus.OK);
89+
}
6290
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
import java.time.LocalDateTime;
4+
5+
import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;
6+
7+
import lombok.Builder;
8+
9+
/**
10+
* 프로필에서 보여줄 개설한 레슨 정보
11+
*/
12+
@Builder
13+
public record ProfileCreatedLessonDto(
14+
Long id,
15+
String lessonName,
16+
Integer maxParticipants,
17+
Integer currentParticipants,
18+
Integer price,
19+
LessonStatus status,
20+
LocalDateTime startAt,
21+
LocalDateTime endAt,
22+
Boolean openRun,
23+
String addressDetail
24+
) {
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
import java.util.List;
4+
5+
import lombok.Builder;
6+
7+
/**
8+
* 프로필에서 개설한 레슨 목록 응답
9+
*/
10+
@Builder
11+
public record ProfileCreatedLessonListResponseDto(
12+
List<ProfileCreatedLessonDto> lessons,
13+
Integer count
14+
) {
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
import java.util.List;
4+
5+
public record ProfileCreatedLessonListWrapperDto(
6+
List<ProfileCreatedLessonDto> lessons
7+
) {
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.threestar.trainus.domain.profile.mapper;
2+
3+
import java.util.List;
4+
5+
import com.threestar.trainus.domain.lesson.admin.entity.Lesson;
6+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonDto;
7+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto;
8+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListWrapperDto;
9+
10+
import lombok.AccessLevel;
11+
import lombok.NoArgsConstructor;
12+
13+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
14+
public class ProfileLessonMapper {
15+
16+
// Lesson 엔티티를 ProfileCreatedLessonDto로 변환
17+
public static ProfileCreatedLessonDto toProfileCreatedLessonDto(Lesson lesson) {
18+
return ProfileCreatedLessonDto.builder()
19+
.id(lesson.getId())
20+
.lessonName(lesson.getLessonName())
21+
.maxParticipants(lesson.getMaxParticipants())
22+
.currentParticipants(lesson.getParticipantCount())
23+
.price(lesson.getPrice())
24+
.status(lesson.getStatus())
25+
.startAt(lesson.getStartAt())
26+
.endAt(lesson.getEndAt())
27+
.openRun(lesson.getOpenRun())
28+
.addressDetail(lesson.getAddressDetail())
29+
.build();
30+
}
31+
32+
// 개설한 레슨 목록과 총 레슨의 수를 응답 DTO로 변환
33+
public static ProfileCreatedLessonListResponseDto toProfileCreatedLessonListResponseDto(
34+
List<Lesson> lessons, Long totalCount) {
35+
36+
// 각 레슨을 DTO로 변환
37+
List<ProfileCreatedLessonDto> lessonDtos = lessons.stream()
38+
.map(ProfileLessonMapper::toProfileCreatedLessonDto)
39+
.toList();
40+
41+
return ProfileCreatedLessonListResponseDto.builder()
42+
.lessons(lessonDtos)
43+
.count(totalCount.intValue())
44+
.build();
45+
}
46+
47+
public static ProfileCreatedLessonListWrapperDto toProfileCreatedLessonListWrapperDto(
48+
ProfileCreatedLessonListResponseDto responseDto) {
49+
return new ProfileCreatedLessonListWrapperDto(responseDto.lessons());
50+
}
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.threestar.trainus.domain.profile.service;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.PageRequest;
5+
import org.springframework.data.domain.Pageable;
6+
import org.springframework.data.domain.Sort;
7+
import org.springframework.stereotype.Service;
8+
import org.springframework.transaction.annotation.Transactional;
9+
10+
import com.threestar.trainus.domain.lesson.admin.entity.Lesson;
11+
import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;
12+
import com.threestar.trainus.domain.lesson.admin.repository.LessonRepository;
13+
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto;
14+
import com.threestar.trainus.domain.profile.mapper.ProfileLessonMapper;
15+
import com.threestar.trainus.domain.user.entity.User;
16+
import com.threestar.trainus.domain.user.repository.UserRepository;
17+
import com.threestar.trainus.domain.user.service.UserService;
18+
19+
import lombok.RequiredArgsConstructor;
20+
21+
@Service
22+
@RequiredArgsConstructor
23+
public class ProfileLessonService {
24+
25+
private final LessonRepository lessonRepository;
26+
private final UserRepository userRepository;
27+
private final UserService userService;
28+
29+
// 특정 유저가 개설한 레슨 목록 조회
30+
@Transactional(readOnly = true)
31+
public ProfileCreatedLessonListResponseDto getUserCreatedLessons(
32+
Long userId, int page, int limit, LessonStatus status) {
33+
34+
// User 존재 확인
35+
User user = userService.getUserById(userId);
36+
37+
// 페이징 설정 -> 내림차순!!
38+
Pageable pageable = PageRequest.of(page - 1, limit, Sort.by("createdAt").descending());
39+
40+
// 레슨 상태에 따른 조회
41+
Page<Lesson> lessonPage;
42+
if (status != null) {
43+
// 상태에 따라 조회 가능
44+
lessonPage = lessonRepository.findByLessonLeaderAndStatusAndDeletedAtIsNull(userId, status, pageable);
45+
} else {
46+
// 삭제되지 않은 레슨만 조회
47+
lessonPage = lessonRepository.findByLessonLeaderAndDeletedAtIsNull(userId, pageable);
48+
}
49+
50+
// DTO 변환
51+
return ProfileLessonMapper.toProfileCreatedLessonListResponseDto(
52+
lessonPage.getContent(),
53+
lessonPage.getTotalElements()
54+
);
55+
}
56+
}

0 commit comments

Comments
 (0)