Skip to content

Commit

Permalink
[Feat]: 리뷰 패키지 이동 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
bayy1216 committed Sep 3, 2024
1 parent a64fb9c commit a261b5e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,6 @@ public VerificationCreate(String content, String imageUrl) {
}
}

@Getter
public static class ReviewCreate extends SelfValidating<ReviewCreate> {

@NotBlank(message = "내용은 필수입니다.")
private final String content;

@NotNull(message = "평점은 필수입니다.")
@Min(1)
@Max(5)
private final Integer rating;

@Builder
public ReviewCreate(String content, Integer rating) {
this.content = content;
this.rating = rating;
this.validateSelf();
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.haedal.zzansuni.common.controller.PagingRequest;
import org.haedal.zzansuni.common.controller.PagingResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.userchallenge.controller.ChallengeReq;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewModel.ChallengeReviewWithUserInfo;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewService;
import org.haedal.zzansuni.common.controller.PagingRequest;
import org.haedal.zzansuni.common.controller.PagingResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.global.jwt.JwtUser;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -67,7 +66,7 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.InfoWithChallenge>> getChal
public ApiResponse<Long> challengeReviewCreate(
@PathVariable Long challengeId,
@AuthenticationPrincipal JwtUser jwtUser,
@RequestBody ChallengeReq.ReviewCreate request
@RequestBody ChallengeReviewReq.Create request
) {
Long response = challengeReviewService.createReview(request.toCommand(), challengeId,
jwtUser.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.haedal.zzansuni.challengereview.controller;

import io.swagger.v3.oas.annotations.media.Schema;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewCommand;

public class ChallengeReviewReq {
public record Create(
String content,
@Schema(description = "평점", example = "5")
Integer rating
) {

public ChallengeReviewCommand.Create toCommand() {
return ChallengeReviewCommand.Create.builder()
.content(content)
.rating(rating)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package org.haedal.zzansuni.challengereview.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.haedal.zzansuni.common.domain.BaseTimeEntity;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCommand;
import org.haedal.zzansuni.userchallenge.domain.UserChallenge;

@Entity
Expand Down Expand Up @@ -40,7 +35,7 @@ public class ChallengeReview extends BaseTimeEntity {
@Column(nullable = false)
private Long challengeGroupId;

public static ChallengeReview create(UserChallenge userChallenge, ChallengeCommand.ReviewCreate command) {
public static ChallengeReview create(UserChallenge userChallenge, ChallengeReviewCommand.Create command) {
Long challengeGroupId = userChallenge.getChallenge().getChallengeGroupId();
return ChallengeReview.builder()
.userChallenge(userChallenge)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.haedal.zzansuni.challengereview.domain;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import org.haedal.zzansuni.core.utils.SelfValidating;

public class ChallengeReviewCommand {
@Getter
public static class Create extends SelfValidating<Create> {

@NotBlank(message = "내용은 필수입니다.")
private final String content;

@NotNull(message = "평점은 필수입니다.")
@Min(1)
@Max(5)
private final Integer rating;

@Builder
public Create(String content, Integer rating) {
this.content = content;
this.rating = rating;
this.validateSelf();
}


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

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.haedal.zzansuni.challengegroup.domain.ChallengeCommand;
import org.haedal.zzansuni.userchallenge.domain.port.UserChallengeReader;
import org.haedal.zzansuni.userchallenge.domain.UserChallenge;
import org.springframework.data.domain.Page;
Expand All @@ -25,7 +24,7 @@ public class ChallengeReviewService {
* 챌린지 리뷰 작성하기
*/
@Transactional
public Long createReview(ChallengeCommand.ReviewCreate command, Long challengeId, Long userId) {
public Long createReview(ChallengeReviewCommand.Create command, Long challengeId, Long userId) {
UserChallenge userChallenge = userChallengeReader.findByUserIdAndChallengeId(userId,
challengeId).orElseThrow(() -> new IllegalStateException("해당 챌린지 참여 기록이 없습니다."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ public ChallengeCommand.Verificate toCommand(MultipartFile image) {

}

public record ReviewCreate(
String content,
@Schema(description = "평점", example = "5")
Integer rating
) {

public ChallengeCommand.ReviewCreate toCommand() {
return ChallengeCommand.ReviewCreate.builder()
.content(content)
.rating(rating)
.build();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.haedal.zzansuni.userchallenge.domain.application;

import java.time.LocalDate;

import org.haedal.zzansuni.challengegroup.domain.*;
import org.haedal.zzansuni.challengegroup.domain.port.ChallengeReader;
import org.haedal.zzansuni.challengereview.domain.ChallengeReview;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewModel;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewService;
import org.haedal.zzansuni.challengereview.domain.*;
import org.haedal.zzansuni.userchallenge.domain.*;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewReader;
import org.haedal.zzansuni.challengereview.domain.ChallengeReviewStore;
import org.haedal.zzansuni.userchallenge.domain.port.ChallengeVerificationReader;
import org.haedal.zzansuni.userchallenge.domain.port.UserChallengeReader;
import org.haedal.zzansuni.user.domain.User;
Expand Down Expand Up @@ -150,7 +145,7 @@ void getChallengeRecordDetail() {
void createReview() {
Long userId = 1L;
Long challengeId = 1L;
ChallengeCommand.ReviewCreate command = new ChallengeCommand.ReviewCreate(
ChallengeReviewCommand.Create command = new ChallengeReviewCommand.Create(
"Great challenge!", 5);

when(userChallengeReader.findByUserIdAndChallengeId(userId, challengeId)).thenReturn(
Expand Down

0 comments on commit a261b5e

Please sign in to comment.