Skip to content
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

Issue/#101 #102

Merged
merged 5 commits into from
Sep 26, 2024
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,2 @@
ALTER TABLE challenge_review ADD COLUMN difficulty BIGINT NOT NULL;
ALTER TABLE challenge_review ADD COLUMN achievement BIGINT NOT NULL;
kwonssshyeon marked this conversation as resolved.
Show resolved Hide resolved
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
Loading