Skip to content

Commit

Permalink
Merge pull request #444 from kkkapuq/feature/#440_fix_review_reaction
Browse files Browse the repository at this point in the history
�Refactor : 리뷰 반응 수정
  • Loading branch information
kkkapuq authored Apr 29, 2024
2 parents 05f5847 + f55adaa commit 1eb9deb
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ReviewServiceImpl implements ReviewService {
private final ImageStore imageStore;

private static final int minReactionType = 1;
private static final int maxReactionType = 5;
private static final int maxReactionType = 4;

@Transactional
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public ReviewDto toDto(UserDto userDto, GymDto gymDto) {
0,
0,
0,
0,
userDto,
gymDto,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public ReviewDto toDto(ReviewDto reviewDto) {
content,
reviewDto.images(),
score,
reviewDto.interestCount(),
reviewDto.likeCount(),
reviewDto.helpCount(),
reviewDto.thumbCount(),
reviewDto.angryCount(),
reviewDto.wantToGoCount(),
reviewDto.helpedCount(),
reviewDto.greatCount(),
reviewDto.funnyCount(),
reviewDto.userDto(),
reviewDto.gymDto(),
reviewDto.createdAt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public record ReviewsResponse(
String content,
List<String> images,
float score,
String description,
String difficulty,
List<ReviewReactionCount> reviewReactionCount,
String myReaction,
Writer writer,
Expand All @@ -30,12 +28,11 @@ public static ReviewsResponse of(ReviewDto reviewDto, Long loginId, int myReacti
.id()
.equals(loginId);

List<ReviewReactionCount> reviewReactionCount = java.util.List.of(
new ReviewReactionCount("thumb", reviewDto.thumbCount()),
new ReviewReactionCount("interest", reviewDto.interestCount()),
new ReviewReactionCount("help", reviewDto.helpCount()),
new ReviewReactionCount("like", reviewDto.likeCount()),
new ReviewReactionCount("angry", reviewDto.angryCount())
List<ReviewReactionCount> reviewReactionCount = List.of(
new ReviewReactionCount("wantToGo", reviewDto.wantToGoCount()),
new ReviewReactionCount("helped", reviewDto.helpedCount()),
new ReviewReactionCount("great", reviewDto.greatCount()),
new ReviewReactionCount("funny", reviewDto.funnyCount())
);

Writer writer = new Writer(reviewDto.userDto()
Expand All @@ -51,8 +48,6 @@ public static ReviewsResponse of(ReviewDto reviewDto, Long loginId, int myReacti
reviewDto.content(),
reviewDto.images(),
reviewDto.score(),
reviewDto.description(),
reviewDto.difficulty().getDescription(),
reviewReactionCount,
myReactionType,
writer,
Expand All @@ -64,11 +59,10 @@ public static ReviewsResponse of(ReviewDto reviewDto, Long loginId, int myReacti

private static String mapReactionType(int reaction) {
return switch (reaction) {
case NumberConstants.THUMB_REACTION -> "thumb";
case NumberConstants.INTERREST_REACTION -> "interest";
case NumberConstants.HELP_REACTION -> "help";
case NumberConstants.LIKE_REACTION -> "like";
case NumberConstants.ANGRY_REACTION -> "angry";
case NumberConstants.REACTION_WANT_TO_GO -> "wantToGo";
case NumberConstants.REACTION_HELPED -> "helped";
case NumberConstants.REACTION_GREAT -> "great";
case NumberConstants.REACTION_FUNNY -> "funny";
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public record MyReviewResponse(
public static MyReviewResponse of(ReviewDto reviewDto, int myReaction) {

List<MyReviewResponse.ReviewReactionCount> reviewReactionCount = List.of(
new MyReviewResponse.ReviewReactionCount("thumb", reviewDto.thumbCount()),
new MyReviewResponse.ReviewReactionCount("interest", reviewDto.interestCount()),
new MyReviewResponse.ReviewReactionCount("help", reviewDto.helpCount()),
new MyReviewResponse.ReviewReactionCount("like", reviewDto.likeCount()),
new MyReviewResponse.ReviewReactionCount("angry", reviewDto.angryCount())
new MyReviewResponse.ReviewReactionCount("wantToGo", reviewDto.wantToGoCount()),
new MyReviewResponse.ReviewReactionCount("helped", reviewDto.helpedCount()),
new MyReviewResponse.ReviewReactionCount("great", reviewDto.greatCount()),
new MyReviewResponse.ReviewReactionCount("funny", reviewDto.funnyCount())
);

String myReactionType = mapReactionType(myReaction);
Expand All @@ -56,11 +55,10 @@ public static MyReviewResponse of(ReviewDto reviewDto, int myReaction) {

private static String mapReactionType(int reaction) {
return switch (reaction) {
case NumberConstants.THUMB_REACTION -> "thumb";
case NumberConstants.INTERREST_REACTION -> "interest";
case NumberConstants.HELP_REACTION -> "help";
case NumberConstants.LIKE_REACTION -> "like";
case NumberConstants.ANGRY_REACTION -> "angry";
case NumberConstants.REACTION_WANT_TO_GO -> "wantToGo";
case NumberConstants.REACTION_HELPED -> "helped";
case NumberConstants.REACTION_GREAT -> "great";
case NumberConstants.REACTION_FUNNY -> "funny";
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ private NumberConstants() {
public static final int HOT_POSTS_BOUNDARY = 3;
// Review Reaction
public static final int NOT_REACTION = 0;
public static final int THUMB_REACTION = 1;
public static final int INTERREST_REACTION = 2;
public static final int HELP_REACTION = 3;
public static final int LIKE_REACTION = 4;
public static final int ANGRY_REACTION = 5;
public static final int REACTION_WANT_TO_GO = 1;
public static final int REACTION_HELPED = 2;
public static final int REACTION_GREAT = 3;
public static final int REACTION_FUNNY = 4;
// Maximum Number of Crew Participation
public static final int MAXIMUM_CREW_PARTICIPATION = 5;
// Maximum Number of User Profile Images from Thumbnail of Meetings List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ public record ReviewDto(
String content,
List<String> images,
float score,
int interestCount,
int likeCount,
int helpCount,
int thumbCount,
int angryCount,
int wantToGoCount,
int helpedCount,
int greatCount,
int funnyCount,
UserDto userDto,
GymDto gymDto,
LocalDateTime createdAt,
Expand All @@ -32,11 +31,10 @@ public static ReviewDto of(
String content,
List<String> images,
float score,
int interestCount,
int likeCount,
int helpCount,
int thumbCount,
int angryCount,
int wantToGoCount,
int helpedCount,
int greatCount,
int funnyCount,
UserDto userDto,
GymDto gymDto,
LocalDateTime createdAt,
Expand All @@ -49,11 +47,10 @@ public static ReviewDto of(
content,
images,
score,
interestCount,
likeCount,
helpCount,
thumbCount,
angryCount,
wantToGoCount,
helpedCount,
greatCount,
funnyCount,
userDto,
gymDto,
createdAt,
Expand All @@ -69,11 +66,10 @@ public static ReviewDto from(Review entity) {
entity.getContent(),
entity.getImages(),
entity.getScore(),
entity.getInterestCount(),
entity.getLikeCount(),
entity.getHelpCount(),
entity.getThumbCount(),
entity.getAngryCount(),
entity.getWantToGoCount(),
entity.getHelpedCount(),
entity.getGreatCount(),
entity.getFunnyCount(),
UserDto.from(entity.getUser()),
GymDto.from(entity.getGym()),
entity.getCreatedAt(),
Expand All @@ -89,11 +85,10 @@ public static ReviewDto from(Review entity, List<String> imgUrls, String profile
entity.getContent(),
imgUrls,
entity.getScore(),
entity.getInterestCount(),
entity.getLikeCount(),
entity.getHelpCount(),
entity.getThumbCount(),
entity.getAngryCount(),
entity.getWantToGoCount(),
entity.getHelpedCount(),
entity.getGreatCount(),
entity.getFunnyCount(),
UserDto.from(entity.getUser(), profileImgUrl),
GymDto.from(entity.getGym()),
entity.getCreatedAt(),
Expand All @@ -109,11 +104,10 @@ public Review toEntity() {
content,
images,
score,
interestCount,
likeCount,
helpCount,
thumbCount,
angryCount,
wantToGoCount,
helpedCount,
greatCount,
funnyCount,
userDto.toEntity(),
gymDto.toEntity(),
createdAt,
Expand All @@ -129,11 +123,10 @@ public Review toEntity(List<String> images) {
content,
images,
score,
interestCount,
likeCount,
helpCount,
thumbCount,
angryCount,
wantToGoCount,
helpedCount,
greatCount,
funnyCount,
userDto.toEntity(),
gymDto.toEntity(),
createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,17 @@ public class Review extends AuditingField {
@Column(name = "score", nullable = false)
private float score;

@Column(name = "interest_count", nullable = false)
private int interestCount;
@Column(name = "want_to_go_count", nullable = false)
private int wantToGoCount;

@Column(name = "like_count", nullable = false)
private int likeCount;
@Column(name = "helped_count", nullable = false)
private int helpedCount;

@Column(name = "help_count", nullable = false)
private int helpCount;
@Column(name = "great_count", nullable = false)
private int greatCount;

@Column(name = "thumb_count", nullable = false)
private int thumbCount;

@Column(name = "angry_count", nullable = false)
private int angryCount;
@Column(name = "funny_count", nullable = false)
private int funnyCount;

@ManyToOne(optional = false)
@JoinColumn(name = "user_id", nullable = false)
Expand All @@ -76,11 +73,10 @@ public Review(
String content,
List<String> images,
float score,
int interestCount,
int likeCount,
int helpCount,
int thumbCount,
int angryCount,
int wantToGoCount,
int helpedCount,
int greatCount,
int funnyCount,
User user,
Gym gym,
LocalDateTime createdAt,
Expand All @@ -92,11 +88,10 @@ public Review(
this.content = content;
this.images = images;
this.score = score;
this.interestCount = interestCount;
this.likeCount = likeCount;
this.helpCount = helpCount;
this.thumbCount = thumbCount;
this.angryCount = angryCount;
this.wantToGoCount = wantToGoCount;
this.helpedCount = helpedCount;
this.greatCount = greatCount;
this.funnyCount = funnyCount;
this.user = user;
this.gym = gym;
this.createdAt = createdAt;
Expand All @@ -110,11 +105,10 @@ public static Review of(
String content,
List<String> images,
float score,
int interestCount,
int likeCount,
int helpCount,
int thumbCount,
int angryCount,
int wantToGoCount,
int helpedCount,
int greatCount,
int funnyCount,
User user,
Gym gym,
LocalDateTime createdAt,
Expand All @@ -127,11 +121,10 @@ public static Review of(
content,
images,
score,
interestCount,
likeCount,
helpCount,
thumbCount,
angryCount,
wantToGoCount,
helpedCount,
greatCount,
funnyCount,
user,
gym,
createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {

@Modifying
@Query("update review r set " +
"r.thumbCount = CASE WHEN :reactionType = 1 THEN r.thumbCount + 1 ELSE r.thumbCount END, " +
"r.interestCount = CASE WHEN :reactionType = 2 THEN r.interestCount + 1 ELSE r.interestCount END, " +
"r.helpCount = CASE WHEN :reactionType = 3 THEN r.helpCount + 1 ELSE r.helpCount END, " +
"r.likeCount = CASE WHEN :reactionType = 4 THEN r.likeCount + 1 ELSE r.likeCount END, " +
"r.angryCount = CASE WHEN :reactionType = 5 THEN r.angryCount + 1 ELSE r.angryCount END " +
"r.wantToGoCount = CASE WHEN :reactionType = 1 THEN r.wantToGoCount + 1 ELSE r.wantToGoCount END, " +
"r.helpedCount = CASE WHEN :reactionType = 2 THEN r.helpedCount + 1 ELSE r.helpedCount END, " +
"r.greatCount = CASE WHEN :reactionType = 3 THEN r.greatCount + 1 ELSE r.greatCount END, " +
"r.funnyCount = CASE WHEN :reactionType = 4 THEN r.funnyCount + 1 ELSE r.funnyCount END " +
"where r.id = :reviewId")
void increaseReactionCount(@Param("reviewId") Long reviewId, @Param("reactionType") int reactionType);

@Modifying
@Query("update review r set " +
"r.thumbCount = CASE WHEN :reactionType = 1 THEN r.thumbCount - 1 ELSE r.thumbCount END, " +
"r.interestCount = CASE WHEN :reactionType = 2 THEN r.interestCount - 1 ELSE r.interestCount END, " +
"r.helpCount = CASE WHEN :reactionType = 3 THEN r.helpCount - 1 ELSE r.helpCount END, " +
"r.likeCount = CASE WHEN :reactionType = 4 THEN r.likeCount - 1 ELSE r.likeCount END, " +
"r.angryCount = CASE WHEN :reactionType = 5 THEN r.angryCount - 1 ELSE r.angryCount END " +
"r.wantToGoCount = CASE WHEN :reactionType = 1 THEN r.wantToGoCount - 1 ELSE r.wantToGoCount END, " +
"r.helpedCount = CASE WHEN :reactionType = 2 THEN r.helpedCount - 1 ELSE r.helpedCount END, " +
"r.greatCount = CASE WHEN :reactionType = 3 THEN r.greatCount - 1 ELSE r.greatCount END, " +
"r.funnyCount = CASE WHEN :reactionType = 4 THEN r.funnyCount - 1 ELSE r.funnyCount END " +
"where r.id = :reviewId")
void decreaseReactionCount(@Param("reviewId") Long reviewId, @Param("reactionType") int reactionType);

@Modifying
@Query("update review r set " +
"r.thumbCount = CASE WHEN :oldReactionType = 1 THEN r.thumbCount - 1 WHEN :newReactionType = 1 THEN r.thumbCount + 1 ELSE r.thumbCount END, " +
"r.interestCount = CASE WHEN :oldReactionType = 2 THEN r.interestCount - 1 WHEN :newReactionType = 2 THEN r.interestCount + 1 ELSE r.interestCount END, " +
"r.helpCount = CASE WHEN :oldReactionType = 3 THEN r.helpCount - 1 WHEN :newReactionType = 3 THEN r.helpCount + 1 ELSE r.helpCount END, " +
"r.likeCount = CASE WHEN :oldReactionType = 4 THEN r.likeCount - 1 WHEN :newReactionType = 4 THEN r.likeCount + 1 ELSE r.likeCount END, " +
"r.angryCount = CASE WHEN :oldReactionType = 5 THEN r.angryCount - 1 WHEN :newReactionType = 5 THEN r.angryCount + 1 ELSE r.angryCount END " +
"r.wantToGoCount = CASE WHEN :oldReactionType = 1 THEN r.wantToGoCount - 1 WHEN :newReactionType = 1 THEN r.wantToGoCount + 1 ELSE r.wantToGoCount END, " +
"r.helpedCount = CASE WHEN :oldReactionType = 2 THEN r.helpedCount - 1 WHEN :newReactionType = 2 THEN r.helpedCount + 1 ELSE r.helpedCount END, " +
"r.greatCount = CASE WHEN :oldReactionType = 3 THEN r.greatCount - 1 WHEN :newReactionType = 3 THEN r.greatCount + 1 ELSE r.greatCount END, " +
"r.funnyCount = CASE WHEN :oldReactionType = 4 THEN r.funnyCount - 1 WHEN :newReactionType = 4 THEN r.funnyCount + 1 ELSE r.funnyCount END " +
"where r.id = :reviewId")
void updateReactionCount(@Param("reviewId") Long reviewId, @Param("oldReactionType") int oldReactionType, @Param("newReactionType") int newReactionType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE `review`
DROP COLUMN angry_count,
CHANGE interest_count want_to_go_count INT NOT NULL COMMENT '반응: 가고싶어요 누른 수' DEFAULT 0,
CHANGE like_count helped_count INT NOT NULL COMMENT '반응: 도움돼요 누른 수' DEFAULT 0,
CHANGE help_count great_count INT NOT NULL COMMENT '반응: 멋져요 누른 수' DEFAULT 0,
CHANGE thumb_count funny_count INT NOT NULL COMMENT '반응: 재밌어요 누른 수' DEFAULT 0;
Loading

0 comments on commit 1eb9deb

Please sign in to comment.