-
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 #143 from TravelLaboratory/feature/application-lay…
…er-test Application/Service - Comment, Review 테스트 작성 및 comment, review의 update 시 id만 반환하는 걸 관련된 수정된 응답값들도 전부 보내도록 수정
- Loading branch information
Showing
43 changed files
with
1,276 additions
and
262 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/site/travellaboratory/be/article/application/port/ArticleRepository.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,12 @@ | ||
package site.travellaboratory.be.article.application.port; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import site.travellaboratory.be.article.domain.Article; | ||
import site.travellaboratory.be.article.domain.enums.ArticleStatus; | ||
|
||
public interface ArticleRepository { | ||
|
||
Optional<Article> findByIdAndStatusIn(final Long articleId, List<ArticleStatus> Status); | ||
Article save(Article article); | ||
} |
2 changes: 1 addition & 1 deletion
2
...ticle/application/ArticleLikeService.java → ...plication/service/ArticleLikeService.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
2 changes: 1 addition & 1 deletion
2
...cle/application/ArticleReaderService.java → ...ication/service/ArticleReaderService.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
2 changes: 1 addition & 1 deletion
2
...cle/application/ArticleWriterService.java → ...ication/service/ArticleWriterService.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
2 changes: 1 addition & 1 deletion
2
...chedule/ArticleScheduleReaderService.java → ...chedule/ArticleScheduleReaderService.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
2 changes: 1 addition & 1 deletion
2
...chedule/ArticleScheduleWriterService.java → ...chedule/ArticleScheduleWriterService.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
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
28 changes: 28 additions & 0 deletions
28
...vellaboratory/be/article/infrastructure/persistence/repository/ArticleRepositoryImpl.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,28 @@ | ||
package site.travellaboratory.be.article.infrastructure.persistence.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import site.travellaboratory.be.article.application.port.ArticleRepository; | ||
import site.travellaboratory.be.article.domain.Article; | ||
import site.travellaboratory.be.article.domain.enums.ArticleStatus; | ||
import site.travellaboratory.be.article.infrastructure.persistence.entity.ArticleEntity; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ArticleRepositoryImpl implements ArticleRepository { | ||
|
||
private final ArticleJpaRepository articleJpaRepository; | ||
|
||
@Override | ||
public Optional<Article> findByIdAndStatusIn(Long articleId, List<ArticleStatus> Status) { | ||
return articleJpaRepository.findByIdAndStatusIn(articleId, Status) | ||
.map(ArticleEntity::toModel); | ||
} | ||
|
||
@Override | ||
public Article save(Article article) { | ||
return articleJpaRepository.save(ArticleEntity.from(article)).toModel(); | ||
} | ||
} |
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
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
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
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
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
87 changes: 0 additions & 87 deletions
87
src/main/java/site/travellaboratory/be/comment/application/CommentWriterService.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/main/java/site/travellaboratory/be/comment/application/port/CommentRepository.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,12 @@ | ||
package site.travellaboratory.be.comment.application.port; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import site.travellaboratory.be.comment.domain.Comment; | ||
import site.travellaboratory.be.comment.domain.enums.CommentStatus; | ||
|
||
public interface CommentRepository { | ||
Optional<Comment> findByIdAndStatusIn(Long commentId, List<CommentStatus> status); | ||
|
||
Comment save(Comment comment); | ||
} |
2 changes: 1 addition & 1 deletion
2
...mment/application/CommentLikeService.java → ...plication/service/CommentLikeService.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
2 changes: 1 addition & 1 deletion
2
...ent/application/CommentReaderService.java → ...ication/service/CommentReaderService.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
73 changes: 73 additions & 0 deletions
73
src/main/java/site/travellaboratory/be/comment/application/service/CommentWriterService.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,73 @@ | ||
package site.travellaboratory.be.comment.application.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import site.travellaboratory.be.comment.application.port.CommentRepository; | ||
import site.travellaboratory.be.comment.domain.Comment; | ||
import site.travellaboratory.be.comment.domain.enums.CommentStatus; | ||
import site.travellaboratory.be.comment.domain.request.CommentSaveRequest; | ||
import site.travellaboratory.be.comment.domain.request.CommentUpdateRequest; | ||
import site.travellaboratory.be.common.exception.BeApplicationException; | ||
import site.travellaboratory.be.common.exception.ErrorCodes; | ||
import site.travellaboratory.be.review.application.port.ReviewRepository; | ||
import site.travellaboratory.be.review.domain.Review; | ||
import site.travellaboratory.be.review.domain.enums.ReviewStatus; | ||
import site.travellaboratory.be.user.application.port.UserRepository; | ||
import site.travellaboratory.be.user.domain.User; | ||
import site.travellaboratory.be.user.domain.enums.UserStatus; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CommentWriterService { | ||
|
||
private final CommentRepository commentRepository; | ||
private final ReviewRepository reviewRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public Comment save(Long userId, CommentSaveRequest request) { | ||
Review review = getReviewById(request.reviewId()); | ||
User user = getUserById(userId); | ||
|
||
Comment saveComment = Comment.create(user, review, request); | ||
return commentRepository.save(saveComment); | ||
} | ||
|
||
@Transactional | ||
public Comment update(Long userId, Long commentId, CommentUpdateRequest request) { | ||
Comment comment = getCommentById(commentId); | ||
User user = getUserById(userId); | ||
|
||
Comment updateComment = comment.withUpdatedReplyContent(user, request); | ||
return commentRepository.save(updateComment); | ||
} | ||
|
||
@Transactional | ||
public Comment delete(final Long userId, final Long commentId) { | ||
Comment comment = getCommentById(commentId); | ||
User user = getUserById(userId); | ||
|
||
Comment deletedComment = comment.withInactiveStatus(user); | ||
return commentRepository.save(deletedComment); | ||
} | ||
|
||
private Review getReviewById(Long reviewId) { | ||
return reviewRepository.findByIdAndStatusIn(reviewId, List.of(ReviewStatus.ACTIVE, ReviewStatus.PRIVATE)) | ||
.orElseThrow(() -> new BeApplicationException(ErrorCodes.COMMENT_INVALID_REVIEW_ID, | ||
HttpStatus.NOT_FOUND)); | ||
} | ||
|
||
private User getUserById(Long userId) { | ||
return userRepository.getByIdAndStatus(userId, UserStatus.ACTIVE); | ||
} | ||
|
||
private Comment getCommentById(Long commentId) { | ||
return commentRepository.findByIdAndStatusIn(commentId, | ||
List.of(CommentStatus.ACTIVE)) | ||
.orElseThrow(() -> new BeApplicationException(ErrorCodes.COMMENT_INVALID_COMMENT_ID, | ||
HttpStatus.NOT_FOUND)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...vellaboratory/be/comment/infrastructure/persistence/repository/CommentRepositoryImpl.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 site.travellaboratory.be.comment.infrastructure.persistence.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import site.travellaboratory.be.comment.application.port.CommentRepository; | ||
import site.travellaboratory.be.comment.domain.Comment; | ||
import site.travellaboratory.be.comment.domain.enums.CommentStatus; | ||
import site.travellaboratory.be.comment.infrastructure.persistence.entity.CommentEntity; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CommentRepositoryImpl implements CommentRepository { | ||
|
||
private final CommentJpaRepository commentJpaRepository; | ||
|
||
@Override | ||
public Optional<Comment> findByIdAndStatusIn(Long commentId, List<CommentStatus> status) { | ||
return commentJpaRepository.findByIdAndStatusIn(commentId, status).map(CommentEntity::toModel); | ||
} | ||
|
||
@Override | ||
public Comment save(Comment comment) { | ||
return commentJpaRepository.save(CommentEntity.from(comment)).toModel(); | ||
} | ||
} |
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
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.