From 91f12c400fd150ee99a1bcde56ed6c9f346aa3bf Mon Sep 17 00:00:00 2001 From: Mingyu Song <100754581+mikekks@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:41:07 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A1=B0=ED=9A=8C=EC=88=98=20=EC=A6=9D?= =?UTF-8?q?=EA=B0=80=20=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20(#454)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 조회수 증가 로직 추가 * feat: 조회수 증가 로직 구현 --- .../org/sopt/makers/crew/main/entity/post/Post.java | 4 ++++ .../crew/main/post/v2/service/PostV2ServiceImpl.java | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/org/sopt/makers/crew/main/entity/post/Post.java b/main/src/main/java/org/sopt/makers/crew/main/entity/post/Post.java index 88e2befd..7a9fd2be 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/entity/post/Post.java +++ b/main/src/main/java/org/sopt/makers/crew/main/entity/post/Post.java @@ -150,6 +150,10 @@ public void decreaseLikeCount() { this.likeCount--; } + public void increaseViewCount() { + this.viewCount++; + } + public void isWriter(Integer userId) { if (!this.userId.equals(userId)) { throw new ForbiddenException(FORBIDDEN_EXCEPTION.getErrorCode()); diff --git a/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java b/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java index 03357acc..ebdde882 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java +++ b/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java @@ -166,13 +166,16 @@ public PostV2GetPostsResponseDto getPosts(PostGetPostsCommand queryCommand, Inte /** * 모임 게시글 단건 조회 * - * @throws 400 - * @apiNote 모임에 속한 유저만 작성 가능 + * @throws 400 모임이 존재하지 않은 경우 + * @apiNote 게시믈 조회 시, 조회수가 1 증가한다. */ @Override - @Transactional(readOnly = true) + @Transactional public PostDetailBaseDto getPost(Integer userId, Integer postId) { - return postRepository.findPost(userId, postId); + PostDetailBaseDto responseDto = postRepository.findPost(userId, postId); + Post post = postRepository.findByIdOrThrow(postId); + post.increaseViewCount(); + return responseDto; } @Override