-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from uju-in/LIME-67--review-like-feat
[LIME-67] 리뷰 좋아요 기능 추가
- Loading branch information
Showing
20 changed files
with
458 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...-api/src/main/java/com/programmers/lime/domains/review/application/ReviewLikeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.programmers.lime.domains.review.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.programmers.lime.domains.review.implementation.ReviewLikeAppender; | ||
import com.programmers.lime.domains.review.implementation.ReviewLikeRemover; | ||
import com.programmers.lime.domains.review.implementation.ReviewLikeValidator; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewLikeService { | ||
|
||
private final ReviewLikeAppender reviewLikeAppender; | ||
private final ReviewLikeRemover reviewLikeRemover; | ||
private final ReviewLikeValidator reviewLikeValidator; | ||
|
||
public void like( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
reviewLikeValidator.validateReviewLike(memberId, reviewId); | ||
reviewLikeAppender.append(memberId, reviewId); | ||
} | ||
|
||
public void unlike( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
reviewLikeValidator.validateReviewUnlike(memberId, reviewId); | ||
reviewLikeRemover.deleteByMemberIdAndReviewId(memberId, reviewId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lime-domain/src/main/java/com/programmers/lime/domains/review/domain/ReviewLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.programmers.lime.domains.review.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Table(name = "review_likes") | ||
public class ReviewLike { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "member_id") | ||
private Long memberId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "review_id") | ||
private Review review; | ||
|
||
public ReviewLike( | ||
final Long memberId, | ||
final Review review | ||
) { | ||
this.memberId = memberId; | ||
this.review = review; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../src/main/java/com/programmers/lime/domains/review/implementation/ReviewLikeAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.programmers.lime.domains.review.implementation; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.lime.domains.review.domain.Review; | ||
import com.programmers.lime.domains.review.domain.ReviewLike; | ||
import com.programmers.lime.domains.review.repository.ReviewLikeRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ReviewLikeAppender { | ||
|
||
private final ReviewLikeRepository reviewLikeRepository; | ||
|
||
private final ReviewReader reviewReader; | ||
|
||
public void append( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
Review review = reviewReader.read(reviewId); | ||
|
||
ReviewLike reviewLike = new ReviewLike( | ||
memberId, | ||
review | ||
); | ||
|
||
reviewLikeRepository.save(reviewLike); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...in/src/main/java/com/programmers/lime/domains/review/implementation/ReviewLikeReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.programmers.lime.domains.review.implementation; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.programmers.lime.domains.review.repository.ReviewLikeRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ReviewLikeReader { | ||
|
||
private final ReviewLikeRepository reviewLikeRepository; | ||
|
||
public boolean alreadyLiked( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
if (memberId == null) { | ||
return false; | ||
} | ||
|
||
return reviewLikeRepository.existsByMemberIdAndReviewId(memberId, reviewId); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...n/src/main/java/com/programmers/lime/domains/review/implementation/ReviewLikeRemover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.programmers.lime.domains.review.implementation; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.programmers.lime.domains.review.domain.Review; | ||
import com.programmers.lime.domains.review.repository.ReviewLikeRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ReviewLikeRemover { | ||
|
||
private final ReviewReader reviewReader; | ||
private final ReviewLikeRepository reviewLikeRepository; | ||
|
||
@Transactional | ||
public void deleteByMemberIdAndReviewId( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
Review review = reviewReader.read(reviewId); | ||
reviewLikeRepository.deleteReviewLikeByMemberIdAndReview(memberId, review); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...src/main/java/com/programmers/lime/domains/review/implementation/ReviewLikeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.programmers.lime.domains.review.implementation; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.lime.error.BusinessException; | ||
import com.programmers.lime.error.ErrorCode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ReviewLikeValidator { | ||
|
||
private final ReviewLikeReader reviewLikeReader; | ||
|
||
public void validateReviewLike( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
if (reviewLikeReader.alreadyLiked(memberId, reviewId)) { | ||
throw new BusinessException(ErrorCode.ALREADY_REVIEW_LIKED); | ||
} | ||
} | ||
|
||
public void validateReviewUnlike( | ||
final Long memberId, | ||
final Long reviewId | ||
) { | ||
if (!reviewLikeReader.alreadyLiked(memberId, reviewId)) { | ||
throw new BusinessException(ErrorCode.NOT_REVIEW_LIKED); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
lime-domain/src/main/java/com/programmers/lime/domains/review/model/ReviewImageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.programmers.lime.domains.review.model; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ReviewImageInfo( | ||
Long reviewId, | ||
List<String> imageUrls | ||
) { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
lime-domain/src/main/java/com/programmers/lime/domains/review/model/ReviewInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.programmers.lime.domains.review.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ReviewInfo( | ||
|
||
Long reviewId, | ||
|
||
int rate, | ||
|
||
String content, | ||
|
||
Long likeCount, | ||
|
||
LocalDateTime createdAt, | ||
|
||
LocalDateTime updatedAt | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...in/src/main/java/com/programmers/lime/domains/review/repository/ReviewLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.programmers.lime.domains.review.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.programmers.lime.domains.review.domain.Review; | ||
import com.programmers.lime.domains.review.domain.ReviewLike; | ||
|
||
public interface ReviewLikeRepository extends JpaRepository<ReviewLike, Long> { | ||
|
||
void deleteReviewLikeByMemberIdAndReview( | ||
final Long memberId, | ||
final Review review | ||
); | ||
|
||
boolean existsByMemberIdAndReviewId( | ||
final Long memberId, | ||
final Long reviewId | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.