Skip to content

Commit 0df5caf

Browse files
committed
Sockets Handlers
1 parent a732111 commit 0df5caf

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Vote/src/main/java/com/websocket/voteApp/Vote/DTO/VoteResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public class VoteResponse {
1616
String candidateName;
1717
String candidatePartyName;
1818
LocalDateTime timestamp;
19+
private long voteCount;
20+
1921
}

Vote/src/main/java/com/websocket/voteApp/Vote/Repository/VoteRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.data.domain.Pageable;
66
import org.springframework.data.jpa.repository.JpaRepository;
77
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.data.repository.query.Param;
89
import org.springframework.stereotype.Repository;
910

1011
import java.util.List;
@@ -16,4 +17,7 @@ public interface VoteRepository extends JpaRepository<Vote, Long> {
1617

1718

1819
Page<Vote> getVotesByPollId(Long pollId, Pageable pageable);
20+
21+
@Query("SELECT COUNT(v) FROM Vote v WHERE v.candidate.id = :candidateId AND v.poll.id = :pollId")
22+
long countVotesByCandidateIdAndPollId(@Param("candidateId") Long candidateId, @Param("pollId") Long pollId);
1923
}

Vote/src/main/java/com/websocket/voteApp/Vote/Service/Impl/VoteServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public VoteResponse saveVote(Long userId, VoteRequest request) {
5252
.timestamp(LocalDateTime.now())
5353
.poll(poll)
5454
.build();
55-
return voteMapper.toVoteResponse(voteRepository.save(vote));
55+
VoteResponse votesa = voteMapper.toVoteResponse(voteRepository.save(vote));
56+
votesa.setVoteCount(voteRepository.countVotesByCandidateIdAndPollId(request.getIdCandidate(), request.getPollId()));
57+
return votesa;
5658
}
5759

5860
@Override

0 commit comments

Comments
 (0)