Skip to content

Commit 9a65e91

Browse files
committed
Sockets Handlers
1 parent 600c622 commit 9a65e91

File tree

10 files changed

+11
-17
lines changed

10 files changed

+11
-17
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class CandidateResponse {
1414
private Long id;
1515
private String name;
1616
private String partyName;
17+
private Integer voteCount;
1718

1819
private Long pollId;
19-
20-
private Long countVote;
21-
2220
}

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

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

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-
private int voteCount;
22+
2323
@ManyToOne
2424
@JoinColumn(name = "poll_id")
2525
private Poll poll;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.stereotype.Repository;
1010

1111
import java.util.List;
12+
import java.util.Map;
1213

1314
@Repository
1415
public interface VoteRepository extends JpaRepository<Vote, Long> {
@@ -20,4 +21,5 @@ public interface VoteRepository extends JpaRepository<Vote, Long> {
2021

2122
@Query("SELECT COUNT(v) FROM Vote v WHERE v.candidate.id = :candidateId AND v.poll.id = :pollId")
2223
long countVotesByCandidateIdAndPollId(@Param("candidateId") Long candidateId, @Param("pollId") Long pollId);
24+
2325
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ public VoteResponse saveVote(Long userId, VoteRequest request) {
5252
.timestamp(LocalDateTime.now())
5353
.poll(poll)
5454
.build();
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);
55+
return voteMapper.toVoteResponse(voteRepository.save(vote));
6056
}
6157

6258
@Override

Vote/src/main/resources/application.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
spring.application.name=vote-app
2-
spring.datasource.url=${DB_URL}
3-
spring.datasource.username=${DB_USER_NAME}
4-
spring.datasource.password=${DB_PASSWORD}
2+
spring.datasource.url=jdbc:postgresql://localhost:5432/votingsystem
3+
spring.datasource.username=postgres
4+
spring.datasource.password=aciga200
55

66
spring.jpa.hibernate.ddl-auto=update
77
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
8-
spring.jpa.show-sql=true
98

109

1110
#spring.jpa.defer-datasource-initialization=true
Binary file not shown.

Vote/target/generated-sources/annotations/com/websocket/voteApp/Vote/Mappers/CandidateMapperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@Generated(
1010
value = "org.mapstruct.ap.MappingProcessor",
11-
date = "2024-08-18T15:18:44-0600",
11+
date = "2024-08-18T16:38:37-0600",
1212
comments = "version: 1.5.0.Final, compiler: javac, environment: Java 22.0.1 (Oracle Corporation)"
1313
)
1414
@Component

Vote/target/generated-sources/annotations/com/websocket/voteApp/Vote/Mappers/PollMapperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@Generated(
1414
value = "org.mapstruct.ap.MappingProcessor",
15-
date = "2024-08-18T15:18:44-0600",
15+
date = "2024-08-18T16:38:37-0600",
1616
comments = "version: 1.5.0.Final, compiler: javac, environment: Java 22.0.1 (Oracle Corporation)"
1717
)
1818
@Component

Vote/target/generated-sources/annotations/com/websocket/voteApp/Vote/Mappers/VoteMapperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@Generated(
1111
value = "org.mapstruct.ap.MappingProcessor",
12-
date = "2024-08-18T16:01:53-0600",
12+
date = "2024-08-18T16:38:36-0600",
1313
comments = "version: 1.5.0.Final, compiler: javac, environment: Java 22.0.1 (Oracle Corporation)"
1414
)
1515
@Component

0 commit comments

Comments
 (0)