Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;
import com.threestar.trainus.domain.profile.dto.ImageUpdateRequestDto;
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
import com.threestar.trainus.domain.profile.dto.IntroUpdateRequestDto;
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListResponseDto;
import com.threestar.trainus.domain.profile.dto.ProfileCreatedLessonListWrapperDto;
import com.threestar.trainus.domain.profile.dto.ProfileDetailResponseDto;
import com.threestar.trainus.domain.profile.mapper.ProfileLessonMapper;
import com.threestar.trainus.domain.profile.service.ProfileFacadeService;
import com.threestar.trainus.domain.profile.service.ProfileLessonService;
import com.threestar.trainus.global.annotation.LoginUser;
import com.threestar.trainus.global.dto.PageRequestDto;
import com.threestar.trainus.global.unit.BaseResponse;
import com.threestar.trainus.global.unit.PagedResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -30,6 +39,7 @@
public class ProfileController {

private final ProfileFacadeService facadeService;
private final ProfileLessonService profileLessonService;

@GetMapping("{userId}")
@Operation(summary = "유저 프로필 상세 조회 api")
Expand Down Expand Up @@ -59,4 +69,22 @@ public ResponseEntity<BaseResponse<IntroUpdateResponseDto>> updateProfileIntro(
IntroUpdateResponseDto response = facadeService.updateProfileIntro(loginUserId, requestDto);
return BaseResponse.ok("프로필 자기소개 수정이 완료되었습니다.", response, HttpStatus.OK);
}

@GetMapping("/{userId}/created-lessons")
@Operation(summary = "프로필유저의 개설한 레슨 목록 조회 api",
description = "특정 유저가 개설한 레슨 목록을 조회 -> 누구나 조회가능")
public ResponseEntity<PagedResponse<ProfileCreatedLessonListWrapperDto>> getUserCreatedLessons(
@PathVariable Long userId,
@Valid @ModelAttribute PageRequestDto pageRequestDto,
@RequestParam(required = false) LessonStatus status
) {
// 개설한 레슨 목록 조회
ProfileCreatedLessonListResponseDto responseDto = profileLessonService
.getUserCreatedLessons(userId, pageRequestDto.getPage(), pageRequestDto.getLimit(), status);

ProfileCreatedLessonListWrapperDto wrapperDto = ProfileLessonMapper
.toProfileCreatedLessonListWrapperDto(responseDto);

return PagedResponse.ok("개설한 레슨 목록 조회 완료.", wrapperDto, responseDto.count(), HttpStatus.OK);
}
}
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,
Copy link
Collaborator

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으로 재설계할지 팀원들과 얘기해보는 것도
좋을듯합니다.

String addressDetail
) {
}
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
) {
}
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
) {
}
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());
}
}
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()
);
}
}
Loading