-
Notifications
You must be signed in to change notification settings - Fork 2
feat : 프로필에서 해당 유저의 레슨 목록조회 기능 구현, mock데이터 추가 #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/threestar/trainus/domain/profile/dto/ProfileCreatedLessonDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.threestar.trainus.domain.profile.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| /** | ||
| * 프로필에서 보여줄 개설한 레슨 정보 | ||
| */ | ||
| @Builder | ||
| public record ProfileCreatedLessonDto( | ||
| Long id, | ||
| String lessonName, | ||
| Integer maxParticipants, | ||
| Integer currentParticipants, | ||
| Integer price, | ||
| LessonStatus status, | ||
| LocalDateTime startAt, | ||
| LocalDateTime endAt, | ||
| Boolean openRun, | ||
| String addressDetail | ||
| ) { | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...in/java/com/threestar/trainus/domain/profile/dto/ProfileCreatedLessonListResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.threestar.trainus.domain.profile.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| /** | ||
| * 프로필에서 개설한 레슨 목록 응답 | ||
| */ | ||
| @Builder | ||
| public record ProfileCreatedLessonListResponseDto( | ||
| List<ProfileCreatedLessonDto> lessons, | ||
| Integer count | ||
| ) { | ||
| } |
8 changes: 8 additions & 0 deletions
8
...ain/java/com/threestar/trainus/domain/profile/dto/ProfileCreatedLessonListWrapperDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.threestar.trainus.domain.profile.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record ProfileCreatedLessonListWrapperDto( | ||
| List<ProfileCreatedLessonDto> lessons | ||
| ) { | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/threestar/trainus/domain/profile/mapper/ProfileLessonMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.threestar.trainus.domain.profile.mapper; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.threestar.trainus.domain.lesson.admin.entity.Lesson; | ||
| import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonDto; | ||
| import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto; | ||
| import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListWrapperDto; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class ProfileLessonMapper { | ||
|
|
||
| // Lesson 엔티티를 ProfileCreatedLessonDto로 변환 | ||
| public static ProfileCreatedLessonDto toProfileCreatedLessonDto(Lesson lesson) { | ||
| return ProfileCreatedLessonDto.builder() | ||
| .id(lesson.getId()) | ||
| .lessonName(lesson.getLessonName()) | ||
| .maxParticipants(lesson.getMaxParticipants()) | ||
| .currentParticipants(lesson.getParticipantCount()) | ||
| .price(lesson.getPrice()) | ||
| .status(lesson.getStatus()) | ||
| .startAt(lesson.getStartAt()) | ||
| .endAt(lesson.getEndAt()) | ||
| .openRun(lesson.getOpenRun()) | ||
| .addressDetail(lesson.getAddressDetail()) | ||
| .build(); | ||
| } | ||
|
|
||
| // 개설한 레슨 목록과 총 레슨의 수를 응답 DTO로 변환 | ||
| public static ProfileCreatedLessonListResponseDto toProfileCreatedLessonListResponseDto( | ||
| List<Lesson> lessons, Long totalCount) { | ||
|
|
||
| // 각 레슨을 DTO로 변환 | ||
| List<ProfileCreatedLessonDto> lessonDtos = lessons.stream() | ||
| .map(ProfileLessonMapper::toProfileCreatedLessonDto) | ||
| .toList(); | ||
|
|
||
| return ProfileCreatedLessonListResponseDto.builder() | ||
| .lessons(lessonDtos) | ||
| .count(totalCount.intValue()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static ProfileCreatedLessonListWrapperDto toProfileCreatedLessonListWrapperDto( | ||
| ProfileCreatedLessonListResponseDto responseDto) { | ||
| return new ProfileCreatedLessonListWrapperDto(responseDto.lessons()); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/threestar/trainus/domain/profile/service/ProfileLessonService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.threestar.trainus.domain.profile.service; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.threestar.trainus.domain.lesson.admin.entity.Lesson; | ||
| import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus; | ||
| import com.threestar.trainus.domain.lesson.admin.repository.LessonRepository; | ||
| import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto; | ||
| import com.threestar.trainus.domain.profile.mapper.ProfileLessonMapper; | ||
| import com.threestar.trainus.domain.user.entity.User; | ||
| import com.threestar.trainus.domain.user.repository.UserRepository; | ||
| import com.threestar.trainus.domain.user.service.UserService; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ProfileLessonService { | ||
|
|
||
| private final LessonRepository lessonRepository; | ||
| private final UserRepository userRepository; | ||
| private final UserService userService; | ||
|
|
||
| // 특정 유저가 개설한 레슨 목록 조회 | ||
| @Transactional(readOnly = true) | ||
| public ProfileCreatedLessonListResponseDto getUserCreatedLessons( | ||
| Long userId, int page, int limit, LessonStatus status) { | ||
|
|
||
| // User 존재 확인 | ||
| User user = userService.getUserById(userId); | ||
|
|
||
| // 페이징 설정 -> 내림차순!! | ||
| Pageable pageable = PageRequest.of(page - 1, limit, Sort.by("createdAt").descending()); | ||
|
|
||
| // 레슨 상태에 따른 조회 | ||
| Page<Lesson> lessonPage; | ||
| if (status != null) { | ||
| // 상태에 따라 조회 가능 | ||
| lessonPage = lessonRepository.findByLessonLeaderAndStatusAndDeletedAtIsNull(userId, status, pageable); | ||
| } else { | ||
| // 삭제되지 않은 레슨만 조회 | ||
| lessonPage = lessonRepository.findByLessonLeaderAndDeletedAtIsNull(userId, pageable); | ||
| } | ||
|
|
||
| // DTO 변환 | ||
| return ProfileLessonMapper.toProfileCreatedLessonListResponseDto( | ||
| lessonPage.getContent(), | ||
| lessonPage.getTotalElements() | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CouponCategory는 선착순을 Enum사용하여 관리하고있는데 레슨erd에는 boolean으로 설계를 했네용.
선착순 레슨, 일반 레슨 또 추가로 확장될만한 사안이 있을지 고려해보고 enum으로 재설계할지 팀원들과 얘기해보는 것도
좋을듯합니다.