Skip to content

Commit

Permalink
Merge pull request #29 from TG-WinG/feature/blog
Browse files Browse the repository at this point in the history
Feature/blog
  • Loading branch information
wwingyou authored Nov 16, 2024
2 parents da5903e + 850963f commit 4e82fb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.springframework.data.jpa.repository.JpaRepository;

import kr.tgwing.tech.blog.entity.LikeHistory;
import kr.tgwing.tech.blog.entity.Post;

/**
* LikeHistoryRepository
*/
public interface LikeHistoryRepository extends JpaRepository<LikeHistory, LikeHistory.Key> {

void deleteAllByPost(Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class PostServiceImpl implements PostService {
private final LikeHistoryRepository likeHistoryRepository;

@Override
@Transactional(readOnly = true)
public PostDetail getPost(Long postId, String userStudentNumber) {
User user = getUserEntity(userStudentNumber);
Post post = getPostEntity(postId);
Expand Down Expand Up @@ -119,12 +120,15 @@ public void deletePost(Long postId, String writerStudentNumber) {

// 해당 URL을 요청한 사람이 공지 작성자인 경우에만 삭제 가능
if(post.getWriter().equals(postWriter)) {
likeHistoryRepository.deleteAllByPost(post);
postRepository.deleteById(postId);
} else {
throw new UserIsNotPostWriterException(); }
throw new UserIsNotPostWriterException();
}
}

@Override
@Transactional(readOnly = true)
public Page<PostOverview> getPostOverviews(PostQuery query, String userStudentNumber, Pageable pageable) {
User user = getUserEntity(userStudentNumber);
Specification<Post> spec = PostSpecifications.hasTitleLike(query.getKeyword())
Expand All @@ -147,6 +151,7 @@ public Page<PostOverview> getPostOverviews(PostQuery query, String userStudentNu
}

@Override
@Transactional(readOnly = true)
public PostOverview getPostOverview(Long postId, String userStudentNumber) {
Post post = getPostEntity(postId);
User user = getUserEntity(userStudentNumber);
Expand Down Expand Up @@ -201,6 +206,7 @@ public void deleteComment(Long postId, Long commentId, String writerStudentNumbe
}

@Override
@Transactional(readOnly = true)
public Page<CommentView> getComments(Long postId, Pageable pageable) {
Post post = postRepository.findById(postId)
.orElseThrow(PostNotFoundException::new);
Expand Down Expand Up @@ -260,6 +266,7 @@ public void deleteReply(Long postId, Long commentId, Long replyId, String writer
}

@Override
@Transactional(readOnly = true)
public Page<ReplyView> getReplies(Long postId, Long commentId, Pageable pageable) {
Comment comment = commentRepository.findById(commentId)
.orElseThrow(CommentNotFoundException::new);
Expand Down

0 comments on commit 4e82fb9

Please sign in to comment.