Skip to content

Commit 600c622

Browse files
committed
Sockets Handlers
1 parent 0df5caf commit 600c622

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

Vote/src/main/java/com/websocket/voteApp/Vote/DTO/Response/CandidateResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ public class CandidateResponse {
1616
private String partyName;
1717

1818
private Long pollId;
19+
20+
private Long countVote;
21+
1922
}

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

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

Vote/src/main/java/com/websocket/voteApp/Vote/Mappers/CandidateMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
public interface CandidateMapper {
1010
Candidate toCandidate(CandidateResponse candidateResponse);
1111
@Mapping(source = "poll.id", target = "pollId")
12+
@Mapping(source = "voteCount", target = "countVote")
1213
CandidateResponse toCandidateResponse(Candidate candidate);
1314
}

Vote/src/main/java/com/websocket/voteApp/Vote/Models/Candidate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Candidate {
1919

2020
private String name;
2121
private String partyName;
22-
22+
private int voteCount;
2323
@ManyToOne
2424
@JoinColumn(name = "poll_id")
2525
private Poll poll;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ public VoteResponse saveVote(Long userId, VoteRequest request) {
5252
.timestamp(LocalDateTime.now())
5353
.poll(poll)
5454
.build();
55-
VoteResponse votesa = voteMapper.toVoteResponse(voteRepository.save(vote));
56-
votesa.setVoteCount(voteRepository.countVotesByCandidateIdAndPollId(request.getIdCandidate(), request.getPollId()));
57-
return votesa;
55+
voteRepository.save(vote);
56+
long voteCount = voteRepository.countVotesByCandidateIdAndPollId(request.getIdCandidate(), request.getPollId());
57+
candidate.setVoteCount((int) voteCount);
58+
candidateRepository.save(candidate);
59+
return voteMapper.toVoteResponse(vote);
5860
}
5961

6062
@Override

0 commit comments

Comments
 (0)