Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #164 from Strong-Potato/feature/#163-member-can-ge…
Browse files Browse the repository at this point in the history
…t-not-voted-list

[Feat] 회원은 투표하지 못한 투표 목록을 조회할 수 있어야 한다.
  • Loading branch information
Dr-KoKo authored Jan 24, 2024
2 parents afa5e6c + 4acd3ca commit 5e024b8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public ApiResponse<Void> deleteVote(
return ApiResponse.ok();
}

@GetMapping("/notVoted")
public ApiResponse<VotesResponse> notVotedList(@AuthenticationPrincipal UserPrincipal userPrincipal) {
return ApiResponse.ok(voteInfoQueryService.findMemberVotes(userPrincipal.id()));
}

@DeleteMapping("/{voteId}/candidates")
public ApiResponse<Void> deleteCandidates(
@PathVariable Long voteId,
Expand All @@ -124,7 +129,7 @@ public ApiResponse<Void> resetVote(
voteManageService.resetVote(voteId, userPrincipal.id());
return ApiResponse.ok();
}

@PostMapping("/{voteId}/candidates/{candidateId}")
public ApiResponse<Void> voting(
@PathVariable Long voteId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vote, Long>, 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<Vote> findMemberVotes(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,6 +14,7 @@ public interface VoteRepositoryCustom {

@NoArgsConstructor
@Getter
@Setter
class SearchCondition {
private Long spaceId;
private VoteStatusOption voteStatusOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -22,5 +23,9 @@ public record VotesResponseElement(
public record ViewResultVoteIds(
List<Long> voteIds
) {

public static ViewResultVoteIds emptyIds() {
return new ViewResultVoteIds(Collections.emptyList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public VoteInfoQueryService(VoteRepository voteRepository,
this.voteManageService = voteManageService;
}

@Transactional(readOnly = true)
public VotesResponse searchVotes(Long memberId, SearchCondition searchCondition) {
Space space = spaceRepository.findById(searchCondition.getSpaceId())
.orElseThrow(() -> new SpaceException(SPACE_NOT_FOUND));
Expand Down Expand Up @@ -85,6 +84,24 @@ public VotesResponse searchVotes(Long memberId, SearchCondition searchCondition)
new ViewResultVoteIds(resultIds));
}

public VotesResponse findMemberVotes(Long memberId) {
List<Vote> 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);
Expand Down

0 comments on commit 5e024b8

Please sign in to comment.