Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/groupfour/chatapp/chatapp/poll/Poll.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

@Entity
public class Poll {


@Id
@GeneratedValue
@Column(name = "POLL_ID")
Expand All @@ -34,6 +32,7 @@ public class Poll {
@ManyToOne
private User pollCreator;


public void setPollId(Long pollId) {
this.pollId = pollId;
}
Expand All @@ -49,6 +48,7 @@ public void setChat(Chat chat) {
@ManyToOne
private Chat chat;


public Long getPollId() {
return pollId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ public Boolean delete(Long id) {
pollRepository.deleteById(id);
return true;
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/groupfour/chatapp/chatapp/poll/Vote.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Vote {
@JoinColumn(name = "OPTION_ID")
private Option option;

@ManyToOne
private Poll poll;

@OneToOne
private User voter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,31 @@
@RestController
public class VoteController {

private VoteRepository voteRepository;
private VoteService voteService;

@Autowired
public VoteController(VoteRepository voteRepository) {
this.voteRepository = voteRepository;
public VoteController(VoteService voteService) {
this.voteService = voteService;
}

@RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
@PostMapping(value = "/polls/{pollId}/votes")
public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
vote = voteRepository.save(vote);
vote = voteService.save(vote);
// Set the headers for the newly created resource
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(ServletUriComponentsBuilder.
fromCurrentRequest().path("/{id}").buildAndExpand(vote.getVoteId()).toUri());
fromCurrentRequest().path("/{id}").buildAndExpand(vote.getVoteId()).toUri());
return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
}

@RequestMapping(value="/polls/votes", method=RequestMethod.GET)
public Iterable<Vote> getAllVotes() {
return voteRepository.findAll();
return voteService.findAll();
}

@RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.GET)
public Iterable<Vote> getVote(@PathVariable Long pollId) {
return voteRepository.findVotesByPoll(pollId);
return voteService.findVotesByPoll(pollId);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
@Repository
public interface VoteRepository extends CrudRepository<Vote, Long> {
@Query(value = "SELECT v.* " +
"FROM Option o, Vote v " +
"FROM Chat o, Vote v " +
"WHERE o.POLL_ID = ?1 " +
"AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
public Iterable<Vote> findVotesByPoll(Long pollId);

public Iterable<Vote> findVotesBy();

Vote findVotesByPoll_PollId(Long id);
}

12 changes: 12 additions & 0 deletions src/main/java/com/groupfour/chatapp/chatapp/poll/VoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ public class VoteService {
public VoteService(VoteRepository voteRepository) {
this.voteRepository = voteRepository;
}

public Vote save(Vote vote){
return voteRepository.save(vote);
}

public Iterable<Vote> findAll() {
return null;
}

public Iterable<Vote> findVotesByPoll(Long pollId) {
return null;
}
}