From a494367ec93a85d1e01e4f6f88fa68f9c833196d Mon Sep 17 00:00:00 2001 From: Nine-JH Date: Tue, 23 Jan 2024 07:21:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20=ED=9A=8C=EC=9B=90=EC=9D=80=20?= =?UTF-8?q?=ED=88=AC=ED=91=9C=ED=95=98=EC=A7=80=20=EB=AA=BB=ED=95=9C=20?= =?UTF-8?q?=ED=88=AC=ED=91=9C=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=A0=20=EC=88=98=20=EC=9E=88=EC=96=B4=EC=95=BC=20?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit motivation: - 회원이 메인페이지에서 본인이 투표하지 못한 목록을 조회할 수 있어야 한다는 추가된 요구사항을 받았습니다. modification: - 해당 기능 추가 note: - 간단한 URL로 설정을 했는데 나중에 쿼리 파라미터들로 조회 URL들을 합칠 예정입니다. Close #163 --- .../vote/controller/VoteController.java | 5 +++++ .../vote/controller/VoteControllerImpl.java | 5 +++++ .../vote/repository/VoteRepository.java | 7 +++++++ .../service/dto/response/VotesResponse.java | 5 +++++ .../service/service/VoteInfoQueryService.java | 21 +++++++++++++++++-- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fc/be/app/domain/vote/controller/VoteController.java b/app/src/main/java/fc/be/app/domain/vote/controller/VoteController.java index 9cb92c92..93d16b18 100644 --- a/app/src/main/java/fc/be/app/domain/vote/controller/VoteController.java +++ b/app/src/main/java/fc/be/app/domain/vote/controller/VoteController.java @@ -80,4 +80,9 @@ ApiResponse deleteVote( @PathVariable Long voteId, @AuthenticationPrincipal UserPrincipal userPrincipal ); + + @GetMapping("/notVoted") + ApiResponse notVotedList( + @AuthenticationPrincipal UserPrincipal userPrincipal + ); } diff --git a/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java b/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java index c4c5b1be..4c781ce1 100644 --- a/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java +++ b/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java @@ -105,6 +105,11 @@ public ApiResponse deleteVote( return ApiResponse.ok(); } + @GetMapping("/notVoted") + public ApiResponse notVotedList(UserPrincipal userPrincipal) { + return ApiResponse.ok(voteInfoQueryService.findMemberVotes(userPrincipal.id())); + } + @PostMapping("/{voteId}/candidates/{candidateId}") public ApiResponse voting( @PathVariable Long voteId, diff --git a/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepository.java b/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepository.java index e0b7f591..4d6c2926 100644 --- a/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepository.java +++ b/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepository.java @@ -2,6 +2,13 @@ import fc.be.app.domain.vote.entity.Vote; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface VoteRepository extends JpaRepository, VoteRepositoryCustom { + + @Query(value = "select v from Vote v where v.space.id in (select jm.space.id from JoinedMember jm where jm.member.id = :memberId) and v.space.id not in (" + + "select vrm.spaceId from VoteResultMember vrm where vrm.memberId = :memberId)", nativeQuery = true) + List findMemberVotes(Long memberId); } diff --git a/app/src/main/java/fc/be/app/domain/vote/service/dto/response/VotesResponse.java b/app/src/main/java/fc/be/app/domain/vote/service/dto/response/VotesResponse.java index 56afbf52..ddaef51e 100644 --- a/app/src/main/java/fc/be/app/domain/vote/service/dto/response/VotesResponse.java +++ b/app/src/main/java/fc/be/app/domain/vote/service/dto/response/VotesResponse.java @@ -3,6 +3,7 @@ import fc.be.app.domain.space.vo.VoteStatus; import fc.be.app.domain.vote.service.dto.response.vo.MemberProfile; +import java.util.Collections; import java.util.List; public record VotesResponse( @@ -22,5 +23,9 @@ public record VotesResponseElement( public record ViewResultVoteIds( List voteIds ) { + + public static ViewResultVoteIds emptyIds() { + return new ViewResultVoteIds(Collections.emptyList()); + } } } diff --git a/app/src/main/java/fc/be/app/domain/vote/service/service/VoteInfoQueryService.java b/app/src/main/java/fc/be/app/domain/vote/service/service/VoteInfoQueryService.java index 49fd37c9..994b5f81 100644 --- a/app/src/main/java/fc/be/app/domain/vote/service/service/VoteInfoQueryService.java +++ b/app/src/main/java/fc/be/app/domain/vote/service/service/VoteInfoQueryService.java @@ -28,7 +28,7 @@ import static fc.be.app.domain.space.exception.SpaceErrorCode.SPACE_NOT_FOUND; import static fc.be.app.domain.vote.exception.VoteErrorCode.VOTE_NOT_FOUND; import static fc.be.app.domain.vote.repository.VoteRepositoryCustom.SearchCondition; -import static fc.be.app.domain.vote.service.dto.response.VoteResultResponse.*; +import static fc.be.app.domain.vote.service.dto.response.VoteResultResponse.CandidateResultResponse; import static fc.be.app.domain.vote.service.dto.response.VotesResponse.ViewResultVoteIds; import static fc.be.app.domain.vote.service.dto.response.VotesResponse.VotesResponseElement; @@ -52,7 +52,6 @@ public VoteInfoQueryService(VoteRepository voteRepository, this.voteResultMemberRepository = voteResultMemberRepository; } - @Transactional(readOnly = true) public VotesResponse searchVotes(Long memberId, SearchCondition searchCondition) { Space space = spaceRepository.findById(searchCondition.getSpaceId()) .orElseThrow(() -> new SpaceException(SPACE_NOT_FOUND)); @@ -83,6 +82,24 @@ public VotesResponse searchVotes(Long memberId, SearchCondition searchCondition) new ViewResultVoteIds(resultIds)); } + public VotesResponse findMemberVotes(Long memberId) { + List votesNotMemberVoted = voteRepository.findMemberVotes(memberId); + + return new VotesResponse(votesNotMemberVoted + .stream() + .map(vote -> new VotesResponseElement( + vote.getId(), + vote.getTitle(), + vote.getStatus(), + MemberProfile.of(vote.getOwner()), + vote.getVotedMembers() + .stream() + .map(votedMember -> MemberProfile.of(votedMember.getMember())) + .toList())) + .toList(), + ViewResultVoteIds.emptyIds() + ); + } public VoteDetailResponse findByVoteId(Long voteId, Long memberId) { Vote vote = getByVoteId(voteId); From ba64a05c01e8eda52d099bfa501b02ebed357c1a Mon Sep 17 00:00:00 2001 From: Denny-Ko Date: Wed, 24 Jan 2024 15:13:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Fix]=20AuthenticationPrincipal=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fc/be/app/domain/vote/controller/VoteControllerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java b/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java index 2efca789..14094561 100644 --- a/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java +++ b/app/src/main/java/fc/be/app/domain/vote/controller/VoteControllerImpl.java @@ -108,7 +108,7 @@ public ApiResponse deleteVote( } @GetMapping("/notVoted") - public ApiResponse notVotedList(UserPrincipal userPrincipal) { + public ApiResponse notVotedList(@AuthenticationPrincipal UserPrincipal userPrincipal) { return ApiResponse.ok(voteInfoQueryService.findMemberVotes(userPrincipal.id())); } From 4acd3cafb9c2406f1cf7e01b4fdf63a3f167b0df Mon Sep 17 00:00:00 2001 From: Denny-Ko Date: Wed, 24 Jan 2024 15:16:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Fix]=20ModelAttribute=20=EA=B0=92=20bindin?= =?UTF-8?q?g=20=EC=95=88=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fc/be/app/domain/vote/repository/VoteRepositoryCustom.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepositoryCustom.java b/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepositoryCustom.java index 91647223..a72fde8a 100644 --- a/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepositoryCustom.java +++ b/app/src/main/java/fc/be/app/domain/vote/repository/VoteRepositoryCustom.java @@ -4,6 +4,7 @@ import fc.be.app.domain.vote.service.dto.request.VoteStatusOption; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.List; @@ -13,6 +14,7 @@ public interface VoteRepositoryCustom { @NoArgsConstructor @Getter + @Setter class SearchCondition { private Long spaceId; private VoteStatusOption voteStatusOption;