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 @@ -16,11 +16,11 @@
import com.threestar.trainus.domain.comment.dto.CommentPageResponseDto;
import com.threestar.trainus.domain.comment.dto.CommentResponseDto;
import com.threestar.trainus.domain.comment.service.CommentService;
import com.threestar.trainus.global.annotation.LoginUser;
import com.threestar.trainus.global.unit.BaseResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

Expand All @@ -37,8 +37,7 @@ public class CommentController {
@PostMapping("/{lessonId}")
@Operation(summary = "댓글 작성", description = "레슨 ID에 해당되는 댓글을 작성합니다.")
public ResponseEntity<BaseResponse<CommentResponseDto>> createComment(@PathVariable Long lessonId,
@Valid @RequestBody CommentCreateRequestDto request, HttpSession session) {
Long userId = (Long)session.getAttribute("LOGIN_USER");
@Valid @RequestBody CommentCreateRequestDto request, @LoginUser Long userId) {
CommentResponseDto comment = commentService.createComment(request, lessonId, userId);
return BaseResponse.ok("댓글 등록 완료되었습니다", comment, HttpStatus.CREATED);
}
Expand All @@ -56,9 +55,8 @@ public ResponseEntity<BaseResponse<CommentPageResponseDto>> readAll(@PathVariabl

@DeleteMapping("/{commentId}")
@Operation(summary = "댓글 삭제", description = "댓글 ID에 해당되는 댓글을 삭제합니다.")
public ResponseEntity<Void> deleteComment(@PathVariable Long commentId, HttpSession session) {
Long userId = (Long)session.getAttribute("LOGIN_USER");
public ResponseEntity<BaseResponse<Void>> deleteComment(@PathVariable Long commentId, @LoginUser Long userId) {
commentService.delete(commentId, userId);
return ResponseEntity.noContent().build();
return BaseResponse.okOnlyStatus(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.Getter;

@Data
@Getter
public class CommentCreateRequestDto {
@NotBlank(message = "댓글 내용은 필수입니다")
@Size(max = 255, message = "댓글은 255자 이내여야 합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import com.threestar.trainus.domain.comment.mapper.CommentMapper;
import com.threestar.trainus.domain.comment.repository.CommentRepository;
import com.threestar.trainus.domain.lesson.admin.entity.Lesson;
import com.threestar.trainus.domain.lesson.admin.repository.LessonRepository;
import com.threestar.trainus.domain.lesson.admin.service.AdminLessonService;
import com.threestar.trainus.domain.user.entity.User;
import com.threestar.trainus.domain.user.repository.UserRepository;
import com.threestar.trainus.global.exception.domain.ErrorCode;
import com.threestar.trainus.global.exception.handler.BusinessException;
import com.threestar.trainus.domain.user.service.UserService;
import com.threestar.trainus.global.utils.PageLimitCalculator;

import lombok.RequiredArgsConstructor;
Expand All @@ -25,16 +23,14 @@
@RequiredArgsConstructor
public class CommentService {

private final UserRepository userRepository;
private final LessonRepository lessonRepository;
private final AdminLessonService adminLessonService;
private final CommentRepository commentRepository;
private final UserService userService;

@Transactional
public CommentResponseDto createComment(CommentCreateRequestDto request, Long lessonId, Long userId) {
Lesson findLesson = lessonRepository.findById(lessonId)
.orElseThrow(() -> new BusinessException(ErrorCode.LESSON_NOT_FOUND));
User findUser = userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
Lesson findLesson = adminLessonService.findLessonById(lessonId);
User findUser = userService.getUserById(userId);
Comment parent = findParent(request);

Comment newComment = Comment.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@ public class CouponResponseDto {
private LocalDateTime expirationDate;
private OwnedStatus ownedStatus;
private Integer quantity;
private String category;
private CouponCategory category;
private LocalDateTime openTime;

public CouponResponseDto(Long couponId, String couponName, String discountPrice,
Integer minOrderPrice, LocalDateTime expirationDate,
String ownedStatus, Integer quantity, CouponCategory category,
LocalDateTime openTime) {
this.couponId = couponId;
this.couponName = couponName;
this.discountPrice = discountPrice;
this.minOrderPrice = minOrderPrice;
this.expirationDate = expirationDate;
this.ownedStatus = OwnedStatus.valueOf(ownedStatus);
this.quantity = quantity;
this.category = category.name();
this.openTime = openTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.threestar.trainus.domain.coupon.user.entity.CouponStatus;

import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,6 +16,6 @@ public class CreateUserCouponResponseDto {
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
private LocalDateTime expirationDate;
private String status;
private CouponStatus status;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDateTime;

import com.threestar.trainus.domain.coupon.user.entity.CouponStatus;

import lombok.Builder;
import lombok.Getter;

Expand All @@ -13,6 +15,6 @@ public class UserCouponResponseDto {
private String discountPrice;
private Integer minOrderPrice;
private LocalDateTime expirationDate;
private String status;
private CouponStatus status;
private LocalDateTime useDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Coupon extends BaseDateEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Builder.Default
@OneToMany(mappedBy = "coupon")
private List<UserCoupon> userCoupons = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -29,7 +28,6 @@
}
)
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UserCoupon extends BaseDateEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static CouponResponseDto toDto(Coupon coupon, boolean owned) {
.expirationDate(coupon.getExpirationDate())
.ownedStatus(owned ? OwnedStatus.OWNED : OwnedStatus.NOT_OWNED)
.quantity(coupon.getQuantity())
.category(coupon.getCategory().name())
.category(coupon.getCategory())
.openTime(coupon.getOpenAt())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static CreateUserCouponResponseDto toCreateUserCouponResponseDto(UserCoup
.userId(userCoupon.getUser().getId())
.createdAt(userCoupon.getCreatedAt())
.expirationDate(userCoupon.getExpirationDate())
.status(userCoupon.getStatus().name())
.status(userCoupon.getStatus())
.build();
}

Expand All @@ -30,7 +30,7 @@ public static UserCouponResponseDto toUserCouponResponseDto(UserCoupon userCoupo
.discountPrice(coupon.getDiscountPrice())
.minOrderPrice(coupon.getMinOrderPrice())
.expirationDate(coupon.getExpirationDate())
.status(coupon.getStatus().name())
.status(coupon.getStatus())
.useDate(userCoupon.getUseDate())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public interface CouponRepository extends JpaRepository<Coupon, Long> {
@Query("""
SELECT new com.threestar.trainus.domain.coupon.user.dto.CouponResponseDto(
c.id, c.name, c.discountPrice, c.minOrderPrice, c.expirationDate,
CASE WHEN uc.id IS NOT NULL THEN "OWNED" ELSE "NOT_OWNED" END,
CASE WHEN uc.id IS NOT NULL THEN com.threestar.trainus.domain.coupon.user.entity.OwnedStatus.OWNED
ELSE com.threestar.trainus.domain.coupon.user.entity.OwnedStatus.NOT_OWNED END,
c.quantity, c.category, c.openAt
)
FROM Coupon c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -21,15 +22,14 @@
import com.threestar.trainus.domain.lesson.admin.entity.ApplicationAction;
import com.threestar.trainus.domain.lesson.admin.service.AdminLessonService;
import com.threestar.trainus.global.annotation.LoginUser;
import com.threestar.trainus.global.dto.PageRequestDto;
import com.threestar.trainus.global.exception.domain.ErrorCode;
import com.threestar.trainus.global.exception.handler.BusinessException;
import com.threestar.trainus.global.unit.BaseResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;

/**
Expand Down Expand Up @@ -71,16 +71,13 @@ public ResponseEntity<BaseResponse<Void>> deleteLesson(
@Operation(summary = "레슨 신청자 목록 조회 api", description = "레슨 신청자의 목록을 조회 가능함.")
public ResponseEntity<BaseResponse<LessonApplicationListResponseDto>> getLessonApplications(
@PathVariable Long lessonId,
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@Max(value = 100, message = "limit는 100 이하여야 합니다.") int limit,
@Valid @ModelAttribute PageRequestDto pageRequestDto,
@RequestParam(defaultValue = "ALL") String status,
@LoginUser Long loginUserId) {

// 신청자 목록 조회
LessonApplicationListResponseDto responseDto = adminLessonService
.getLessonApplications(lessonId, page, limit, status, loginUserId);
.getLessonApplications(lessonId, pageRequestDto.getPage(), pageRequestDto.getLimit(), status, loginUserId);

return BaseResponse.ok("레슨 신청자 목록 조회 완료.", responseDto, HttpStatus.OK);
}
Expand All @@ -106,15 +103,12 @@ public ResponseEntity<BaseResponse<ApplicationProcessResponseDto>> processLesson
@Operation(summary = "레슨 참가자 목록 조회 api", description = "")
public ResponseEntity<BaseResponse<ParticipantListResponseDto>> getLessonParticipants(
@PathVariable Long lessonId,
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@Max(value = 100, message = "limit는 100 이하여야 합니다.") int limit,
@Valid @ModelAttribute PageRequestDto pageRequestDto,
@LoginUser Long loginUserId) {

// 참가자 목록 조회
ParticipantListResponseDto responseDto = adminLessonService
.getLessonParticipants(lessonId, page, limit, loginUserId);
.getLessonParticipants(lessonId, pageRequestDto.getPage(), pageRequestDto.getLimit(), loginUserId);

return BaseResponse.ok("레슨 참가자 목록 조회 완료.", responseDto, HttpStatus.OK);
}
Expand All @@ -124,10 +118,7 @@ public ResponseEntity<BaseResponse<ParticipantListResponseDto>> getLessonPartici
@Operation(summary = "강사가 개설한 레슨 목록 조회 api", description = "")
public ResponseEntity<BaseResponse<CreatedLessonListResponseDto>> getCreatedLessons(
@PathVariable Long userId,
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@Max(value = 100, message = "limit는 100 이하여야 합니다.") int limit,
@Valid @ModelAttribute PageRequestDto pageRequestDto,
@RequestParam(required = false) String status,
@LoginUser Long loginUserId) {

Expand All @@ -138,7 +129,7 @@ public ResponseEntity<BaseResponse<CreatedLessonListResponseDto>> getCreatedLess

// 개설한 레슨 목록 조회
CreatedLessonListResponseDto responseDto = adminLessonService
.getCreatedLessons(userId, page, limit, status);
.getCreatedLessons(userId, pageRequestDto.getPage(), pageRequestDto.getLimit(), status);

return BaseResponse.ok("개설한 레슨 목록 조회 완료.", responseDto, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDateTime;

import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;

import lombok.Builder;

/**
Expand All @@ -14,7 +16,7 @@ public record CreatedLessonDto(
Integer maxParticipants,
Integer currentParticipants,
Integer price,
String status,
LessonStatus status,
LocalDateTime startAt,
LocalDateTime endAt,
Boolean openRun,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import com.threestar.trainus.domain.lesson.admin.entity.Category;
import com.threestar.trainus.domain.lesson.admin.entity.LessonStatus;

import lombok.Builder;

Expand All @@ -24,7 +25,7 @@ public record LessonResponseDto(
String district,
String dong,
String addressDetail,
String status,
LessonStatus status,
LocalDateTime createdAt,
List<String> lessonImages
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static CreatedLessonDto toCreatedLessonDto(Lesson lesson) {
.maxParticipants(lesson.getMaxParticipants())
.currentParticipants(lesson.getParticipantCount())
.price(lesson.getPrice())
.status(lesson.getStatus().name())
.status(lesson.getStatus())
.startAt(lesson.getStartAt())
.endAt(lesson.getEndAt())
.openRun(lesson.getOpenRun())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static LessonResponseDto toResponseDto(Lesson lesson, List<LessonImage> l
.district(lesson.getDistrict())
.dong(lesson.getDong())
.addressDetail(lesson.getAddressDetail())
.status(lesson.getStatus().name()) // enum이름 반환
.status(lesson.getStatus())
.createdAt(lesson.getCreatedAt())
.lessonImages(imageUrls) // 이미지 URL 목록
.build();
Expand All @@ -80,11 +80,11 @@ public static LessonDetailResponseDto toLessonDetailDto(
.profileImage(profile.getProfileImage())
.reviewCount(reviewCount)
.rating(rating)
.category(lesson.getCategory().name())
.category(lesson.getCategory())
.price(lesson.getPrice())
.maxParticipants(lesson.getMaxParticipants())
.currentParticipants(lesson.getParticipantCount())
.status(lesson.getStatus().name())
.status(lesson.getStatus())
.startAt(lesson.getStartAt())
.endAt(lesson.getEndAt())
.openTime(lesson.getOpenTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public interface LessonImageRepository extends JpaRepository<LessonImage, Long> {

List<LessonImage> findByLesson(Lesson lesson);

List<LessonImage> findAllByLessonId(Long id);
}

Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class AdminLessonService {
// 새로운 레슨을 생성하는 메서드
public LessonResponseDto createLesson(LessonCreateRequestDto requestDto, Long userId) {
// User 조회
//TODO: 공통메소드
User user = userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
User user = userService.getUserById(userId);

validateLessonTimes(requestDto.startAt(), requestDto.endAt());

Expand Down Expand Up @@ -119,10 +117,7 @@ private List<LessonImage> saveLessonImages(Lesson lesson, List<String> imageUrls
@Transactional
public void deleteLesson(Long lessonId, Long userId) {
// User 존재 확인
//TODO: 공통메소드
User user = userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));

User user = userService.getUserById(userId);
//레슨 조회
Lesson lesson = findLessonById(lessonId);

Expand Down
Loading