Skip to content

Commit

Permalink
Merge pull request #102 from KNU-HAEDAL/issue/#101
Browse files Browse the repository at this point in the history
Issue/#101
  • Loading branch information
bayy1216 authored Sep 26, 2024
2 parents 13a49eb + 7fd153d commit b1f534d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ public class ChallengeReviewReq {
public record Create(
String content,
@Schema(description = "평점", example = "5")
Integer rating
Integer rating,
@Schema(description = "체감 난이도", example = "1")
Integer difficulty,
@Schema(description = "성취도", example = "1")
Integer achievement
) {

public ChallengeReviewCommand.Create toCommand() {
return ChallengeReviewCommand.Create.builder()
.content(content)
.rating(rating)
.difficulty(difficulty)
.achievement(achievement)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.haedal.zzansuni.challengereview.controller;

import java.time.LocalDateTime;
import java.util.Map;
import lombok.Builder;
import org.haedal.zzansuni.user.controller.UserRes;
Expand Down Expand Up @@ -40,7 +41,10 @@ public record InfoWithChallenge(
Integer challengeDifficulty,
UserRes.User user,
String content,
Integer rating
Integer rating,
Integer difficulty,
Integer achievement,
LocalDateTime createdAt
) {

public static InfoWithChallenge from(
Expand All @@ -53,6 +57,9 @@ public static InfoWithChallenge from(
.user(user)
.content(challengeReviewWithChallenge.content())
.rating(challengeReviewWithChallenge.rating())
.difficulty(challengeReviewWithChallenge.difficulty())
.achievement(challengeReviewWithChallenge.achievement())
.createdAt(challengeReviewWithChallenge.createdAt())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ public class ChallengeReview extends BaseTimeEntity {
@Column(nullable = false)
private Long challengeGroupId;

@Column(nullable = false)
private Integer difficulty;

@Column(nullable = false)
private Integer achievement;

public static ChallengeReview create(UserChallenge userChallenge, ChallengeReviewCommand.Create command) {
Long challengeGroupId = userChallenge.getChallenge().getChallengeGroupId();
return ChallengeReview.builder()
.userChallenge(userChallenge)
.content(command.getContent())
.rating(command.getRating())
.challengeGroupId(challengeGroupId)
.difficulty(command.getDifficulty())
.achievement(command.getAchievement())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ public static class Create extends SelfValidating<Create> {
@Max(5)
private final Integer rating;

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.haedal.zzansuni.challengereview.domain;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -42,7 +43,10 @@ public record ChallengeReviewWithChallenge(
Integer challengeDifficulty,
UserModel.Main user,
String content,
Integer rating
Integer rating,
Integer difficulty,
Integer achievement,
LocalDateTime createdAt
) {

public static ChallengeReviewWithChallenge from(ChallengeReview challengeReview) {
Expand All @@ -58,6 +62,9 @@ public static ChallengeReviewWithChallenge from(ChallengeReview challengeReview)
.user(userModel)
.content(challengeReview.getContent())
.rating(challengeReview.getRating())
.difficulty(challengeReview.getDifficulty())
.achievement(challengeReview.getAchievement())
.createdAt(challengeReview.getCreatedAt())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE challenge_review ADD COLUMN difficulty TINYINT DEFULT(1) NOT NULL;
ALTER TABLE challenge_review ADD COLUMN achievement TINYINT DEFULT(1) NOT NULL;

ALTER TABLE challenge_review ALTER COLUMN difficulty DROP DEFAULT;
ALTER TABLE challenge_review ALTER COLUMN achievement DROP DEFAULT;
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void getScoreModelByChallengeGroupId() {
.userChallenge(userChallenge)
.content("content")
.rating(i % 4 + 1)
.difficulty(1)
.achievement(1)
.build())
.toList();
// -> 1:3 / 2:3 / 3:3 / 4:2 / 5:0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void createReview() {
Long userId = 1L;
Long challengeId = 1L;
ChallengeReviewCommand.Create command = new ChallengeReviewCommand.Create(
"Great challenge!", 5);
"Great challenge!", 5,1,1);

when(userChallengeReader.findByUserIdAndChallengeId(userId, challengeId)).thenReturn(
Optional.of(userChallenge));
Expand Down

0 comments on commit b1f534d

Please sign in to comment.