@Override public void removeVotes(String username) { User user = userPersistence.findByUsername(username); votingPersistence.removeVotes(user); String auditMessage = "%s hat sein Voting widerrufen"; auditPersistence.createAudit(username, String.format(auditMessage, username)); }
@Override public VotesOfUserResponseModel getVotesOfUser(String username) { User user = userPersistence.findByUsername(username); List<Vote> votes = votingPersistence.findLatestVotesForUser(user); return new VotesOfUserResponseModel(votes); }
@Override public void save(String username, List<Vote> votes) { Event event = eventPersistence.findLatestVoting(); Date timestamp = new Date(); for (Vote vote : votes) { User user = userPersistence.findByUsername(username); Location location = locationPersistence.findById(vote.getLocation().getId()); Vote loadedVote = votingPersistence.findLatestVote(user, location); if (loadedVote != null) { loadedVote.setCurrent(false); votingPersistence.save(loadedVote); } Integer newVoteValue = vote.getVote(); if (newVoteValue == null) { newVoteValue = 0; } Vote voteToSave = new Vote(); voteToSave.setLocation(location); voteToSave.setUser(user); voteToSave.setDate(timestamp); voteToSave.setVote(newVoteValue); voteToSave.setCurrent(true); String auditMessage = "%s hat sein Voting für %s auf %d gesetzt"; if (voteToSave.getVote() > 0) { auditPersistence.createAudit( username, String.format(auditMessage, username, location.getName(), voteToSave.getVote())); } voteToSave.setEvent(event); votingPersistence.save(voteToSave); } }
@Override public List<Vote> getVotesOfUserForEvent(String username, Event event) { User user = userPersistence.findByUsername(username); return votingPersistence.findLatestVotesForUserAndEvent(user, event); }