From 476d86251eef464d958198da8ab748b788bf6e5a Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:45:27 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20PostRepository=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=B2=AD=EC=9B=90=20=EA=B8=80=20=EA=B0=9C=EC=88=98,=20?= =?UTF-8?q?=EB=8F=99=EC=9D=98=ED=95=9C=20=EC=B2=AD=EC=9B=90=20=EA=B8=80=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20JPQ?= =?UTF-8?q?L=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/repository/post/PostRepository.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/com/dku/council/domain/post/repository/post/PostRepository.java b/src/main/java/com/dku/council/domain/post/repository/post/PostRepository.java index a46fbdf1..be247d74 100644 --- a/src/main/java/com/dku/council/domain/post/repository/post/PostRepository.java +++ b/src/main/java/com/dku/council/domain/post/repository/post/PostRepository.java @@ -46,4 +46,21 @@ public interface PostRepository extends JpaRepository { "and p.status='ACTIVE'") Long countAllByUserId(@Param("userId") Long userId); + /** + * user 가 작성한 청원 게시글의 총 개수를 가져옵니다. + */ + @Query("select count(*) from Post p " + + "where p.user.id=:userId and " + + "TYPE(p) IN (Petition) and " + + "p.status='ACTIVE' ") + Long countAllPetitionByUserId(@Param("userId") Long userId); + + /** + * user 가 동의한 청원 게시글의 총 개수를 가져옵니다. + */ + @Query("select count(*) from Post p " + + "join PetitionStatistic as ps on p.id = ps.petition.id " + + "where ps.user.id=:userId and " + + "p.status='ACTIVE' ") + Long countAllAgreedPetitionByUserId(Long userId); } \ No newline at end of file From 9fb4c95088aaf38a12954003c79886b93a79f9eb Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:45:49 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EB=8F=99=EC=9D=98=ED=95=9C=20?= =?UTF-8?q?=EC=B2=AD=EC=9B=90=20=EA=B8=80=EC=9D=84=20Page=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20JPQL=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/repository/post/PetitionRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/dku/council/domain/post/repository/post/PetitionRepository.java b/src/main/java/com/dku/council/domain/post/repository/post/PetitionRepository.java index 3563dacd..4e913c7e 100644 --- a/src/main/java/com/dku/council/domain/post/repository/post/PetitionRepository.java +++ b/src/main/java/com/dku/council/domain/post/repository/post/PetitionRepository.java @@ -29,4 +29,8 @@ public interface PetitionRepository extends GenericPostRepository{ @Query("select p from Petition p where p.user.id=:userId and p.status='ACTIVE'") Page findAllByUserId(@Param("userId") Long userId, Pageable pageable); + @Query("select p from Petition p " + + "join fetch PetitionStatistic ps on p.id = ps.petition.id " + + "where ps.user.id=:userId and p.status='ACTIVE' ") + Page findAllAgreedByUserId (@Param("userId") Long userId, Pageable pageable); } \ No newline at end of file From 9785370188eed33c662d353678f3b3610c692e45 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:46:05 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=97=90=20=EB=82=B4=EA=B0=80=20=EC=93=B4=20?= =?UTF-8?q?=EC=B2=AD=EC=9B=90=20=EA=B8=80,=20=EB=8F=99=EC=9D=98=ED=95=9C?= =?UTF-8?q?=20=EC=B2=AD=EC=9B=90=20=EA=B8=80=20=EA=B0=9C=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/model/dto/response/ResponseUserInfoDto.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/dku/council/domain/user/model/dto/response/ResponseUserInfoDto.java b/src/main/java/com/dku/council/domain/user/model/dto/response/ResponseUserInfoDto.java index 2b987edc..26b5c047 100644 --- a/src/main/java/com/dku/council/domain/user/model/dto/response/ResponseUserInfoDto.java +++ b/src/main/java/com/dku/council/domain/user/model/dto/response/ResponseUserInfoDto.java @@ -19,5 +19,7 @@ public class ResponseUserInfoDto { private final Long writePostCount; private final Long commentedPostCount; private final Long likedPostCount; + private final Long petitionCount; + private final Long agreedPetitionCount; private final boolean admin; } From f43d01baeccd067729dca5a767119465faf0627c Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:46:23 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EB=8F=99?= =?UTF-8?q?=EC=9D=98=ED=95=9C=20=EC=B2=AD=EC=9B=90=20=EA=B8=80=20=EC=B0=BE?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/post/PetitionService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/dku/council/domain/post/service/post/PetitionService.java b/src/main/java/com/dku/council/domain/post/service/post/PetitionService.java index 26e41e45..302631d4 100644 --- a/src/main/java/com/dku/council/domain/post/service/post/PetitionService.java +++ b/src/main/java/com/dku/council/domain/post/service/post/PetitionService.java @@ -132,4 +132,13 @@ public Page listMyPosts(Long userId, Pageable pageable, i return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId())); }); } + + @Transactional(readOnly = true) + public Page listMyAgreedPosts(Long userId, Pageable pageable, int bodySize) { + return repository.findAllAgreedByUserId(userId, pageable) + .map(post -> { + SummarizedGenericPostDto dto = postService.makeListDto(bodySize, post); + return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId())); + }); + } } From 6c296d65c9210c9ef75fb4b493bb894698fa55f0 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:46:40 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=97=90=20=EC=B2=AD=EC=9B=90=20=EA=B8=80=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98,=20=EB=8F=99=EC=9D=98=ED=95=9C=20=EC=B2=AD?= =?UTF-8?q?=EC=9B=90=20=EA=B8=80=20=EA=B0=9C=EC=88=98=20dto=EC=97=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dku/council/domain/user/service/UserInfoService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dku/council/domain/user/service/UserInfoService.java b/src/main/java/com/dku/council/domain/user/service/UserInfoService.java index 9688d402..ec3b18ba 100644 --- a/src/main/java/com/dku/council/domain/user/service/UserInfoService.java +++ b/src/main/java/com/dku/council/domain/user/service/UserInfoService.java @@ -41,12 +41,14 @@ public ResponseUserInfoDto getFullUserInfo(Long userId) { Long writePostCount = postRepository.countAllByUserId(userId); Long commentedPostCount = commentRepository.countAllCommentedByUserId(userId); Long likedPostCount = likeService.getCountOfLikedElements(userId, LikeTarget.POST); + Long petitionCount = postRepository.countAllPetitionByUserId(userId); + Long agreedPetitionCount = postRepository.countAllAgreedPetitionByUserId(userId); return new ResponseUserInfoDto(user.getStudentId(), user.getName(), user.getNickname(), user.getAge(), user.getGender(), year, major.getName(), major.getDepartment(), phoneNumber, writePostCount, commentedPostCount, likedPostCount, - user.getUserRole().isAdmin()); + petitionCount, agreedPetitionCount, user.getUserRole().isAdmin()); } @Transactional(readOnly = true) From 453e20bcea04192cfb0e6002d7206e5b6d3bd932 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 26 Dec 2023 16:47:06 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EB=8F=99?= =?UTF-8?q?=EC=9D=98=ED=95=9C=20=EC=B2=AD=EC=9B=90=20=EA=B8=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EB=8A=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PetitionController.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/dku/council/domain/post/controller/PetitionController.java b/src/main/java/com/dku/council/domain/post/controller/PetitionController.java index 3d3836aa..2046115f 100644 --- a/src/main/java/com/dku/council/domain/post/controller/PetitionController.java +++ b/src/main/java/com/dku/council/domain/post/controller/PetitionController.java @@ -70,6 +70,19 @@ public ResponsePage listMyPosts(AppAuthentication auth, return new ResponsePage<>(posts); } + /** + * 내가 동의한 글 조회 + */ + @GetMapping("/my/agreed") + @UserAuth + public ResponsePage listMyAgreedPosts(AppAuthentication auth, + @ParameterObject Pageable pageable, + @RequestParam(defaultValue = "50") int bodySize) { + Page posts = + petitionService.listMyAgreedPosts(auth.getUserId(), pageable, bodySize); + return new ResponsePage<>(posts); + } + /** * 게시글 등록 *