Devided Candidates in PossibleCandidates and Candidates
CHANGED: VotingController:
- added implementation of PossibleCandidateRepository 'possibleCandidateRepository'
- 'VerifyName' added checking for candidatesubmit_status
- 'VerifyName' changed Candidate to PossibleCandidate
- 'VerifyName' changed CandidateWrapper to PossibleCandidateWrapper
- added method 'candidateSaving'
ADDED: PossibleCandidate:
- added entity PossibleCandidate
CHANGED: Voter
- removed 'vote_status' from parameterized constructor
- added candidatesubmit_status
- added getter for candidatesubmit_status
CHANGED: Candidate
- added 'Category category' to parameterized constructor
ADDED: PossibleCandidateWrapper
- added method 'addPossibleCandidate'
- added getters/setters
REMOVED: CandidateWrapper
ADDED: PossibleCandidateRepository:
- added method 'findByNameAndCategoryID' (!!! Not working)
- added method 'findById'
CHANGED: TableAction:
- added needed elements to parameter lists because of changes in the entitys voter, candidate and possibleCandidate
- added method 'logPossibleCandidates'
CHANGED: addingCandidates.html:
- changed the pointer to list according to the changes in 'VotingController.VerifyName'
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.controller;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
||||
import com.github.cato447.AbizeitungVotingSystem.helper.CandidateWrapper;
|
||||
import com.github.cato447.AbizeitungVotingSystem.helper.PossibleCandidateWrapper;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CategoryRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.PossibleCandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.VoterRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.table.TableAction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,6 +47,9 @@ public class VotingController {
|
||||
@Autowired
|
||||
CategoryRepository categoryRepository;
|
||||
|
||||
@Autowired
|
||||
PossibleCandidateRepository possibleCandidateRepository;
|
||||
|
||||
@Autowired
|
||||
JavaMailSender emailSender;
|
||||
|
||||
@@ -64,7 +68,7 @@ public class VotingController {
|
||||
}
|
||||
|
||||
if (candidateRepository.findAll().size() == 0) {
|
||||
tableAction.setUpCandidates(candidateRepository);
|
||||
tableAction.setUpCandidates(candidateRepository, categoryRepository);
|
||||
LOGGER.info("Candidates successfully set up");
|
||||
}
|
||||
}
|
||||
@@ -96,9 +100,13 @@ public class VotingController {
|
||||
if (name.strip().toLowerCase().matches("[a-z]+\\.[a-z]+@adolfinum+\\.de$")) {
|
||||
try {
|
||||
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
||||
LOGGER.warn(voter.getEmail());
|
||||
if (voter.getVote_status()) {
|
||||
LOGGER.warn(name + " has already voted");
|
||||
return "errors/alreadyVoted.html";
|
||||
} else if (voter.getCandidatesubmit_status()) {
|
||||
LOGGER.warn(name + " has already submitted its candidates");
|
||||
return "errors/alreadysubmittedcandidates.html";
|
||||
} else {
|
||||
if(candidatesAdded) {
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
@@ -108,15 +116,13 @@ public class VotingController {
|
||||
LOGGER.info(name + " is voting now");
|
||||
return "voting.html";
|
||||
} else {
|
||||
CandidateWrapper candidates = new CandidateWrapper();
|
||||
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
|
||||
for (int i = 0; i < categories.size(); i++){
|
||||
candidates.addCandidate(new Candidate());
|
||||
possibleCandidates.addPossibleCandidate(new PossibleCandidate());
|
||||
}
|
||||
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("form", candidates);
|
||||
model.addAttribute("form", possibleCandidates);
|
||||
LOGGER.info(name + " is submitting candidates");
|
||||
return "addingCandidates.html";
|
||||
}
|
||||
@@ -131,8 +137,22 @@ public class VotingController {
|
||||
}
|
||||
|
||||
@RequestMapping("/saveCandidates")
|
||||
public String candidateSaving(@ModelAttribute CandidateWrapper candidates){
|
||||
LOGGER.info(tableAction.logCandidates(candidates.getCandidates(), categoryRepository));
|
||||
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates){
|
||||
LOGGER.info(tableAction.logPossibleCandidates(possibleCandidates.getPossibleCandidates(), categoryRepository));
|
||||
LinkedList<PossibleCandidate> posCandidates = possibleCandidates.getPossibleCandidates();
|
||||
long index = 1;
|
||||
for (PossibleCandidate posCandidate : posCandidates){
|
||||
if (posCandidate.getName() != "") {
|
||||
if (possibleCandidateRepository.findByName(posCandidate.getName()) != null) {
|
||||
PossibleCandidate p = possibleCandidateRepository.findByName(posCandidate.getName());
|
||||
p.setVotes(p.getVotes() + 1);
|
||||
} else {
|
||||
PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get());
|
||||
possibleCandidateRepository.save(possibleCandidate);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return "candidateAddingSuccessful.html";
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ public class Candidate implements Comparable<Candidate>{
|
||||
super();
|
||||
}
|
||||
|
||||
public Candidate(String name) {
|
||||
public Candidate(String name, Category category) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.votes = 0;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Id
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "possibleCandidates")
|
||||
public class PossibleCandidate{
|
||||
|
||||
public PossibleCandidate() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PossibleCandidate(String name, Category category) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
this.votes = 1;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String name;
|
||||
private int votes;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "category_id")
|
||||
private Category category;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Category getCategory() {return category;}
|
||||
|
||||
public int getVotes() {
|
||||
return votes;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public void setVotes(int votes) {
|
||||
this.votes = votes;
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,10 @@ public class Voter {
|
||||
super();
|
||||
}
|
||||
|
||||
public Voter(String email, boolean vote_status) {
|
||||
public Voter(String email) {
|
||||
this.email = email;
|
||||
this.vote_status= vote_status;
|
||||
this.vote_status = false;
|
||||
this.candidatesubmit_status = false;
|
||||
}
|
||||
|
||||
@Id
|
||||
@@ -20,6 +21,7 @@ public class Voter {
|
||||
private Long id;
|
||||
private String email;
|
||||
private Boolean vote_status;
|
||||
private Boolean candidatesubmit_status;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -33,6 +35,10 @@ public class Voter {
|
||||
return vote_status;
|
||||
}
|
||||
|
||||
public Boolean getCandidatesubmit_status() {
|
||||
return candidatesubmit_status;
|
||||
}
|
||||
|
||||
public void vote(){
|
||||
vote_status = true;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.helper;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public class CandidateWrapper {
|
||||
|
||||
private LinkedList<Candidate> candidates;
|
||||
|
||||
public CandidateWrapper(){
|
||||
candidates = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void addCandidate(Candidate candidate){
|
||||
this.candidates.add(candidate);
|
||||
}
|
||||
|
||||
public LinkedList<Candidate> getCandidates() {
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.helper;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public class PossibleCandidateWrapper {
|
||||
|
||||
private LinkedList<PossibleCandidate> possibleCandidates;
|
||||
|
||||
public PossibleCandidateWrapper(){
|
||||
possibleCandidates = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void addPossibleCandidate(PossibleCandidate possibleCandidate){
|
||||
this.possibleCandidates.add(possibleCandidate);
|
||||
}
|
||||
|
||||
public LinkedList<PossibleCandidate> getPossibleCandidates() {
|
||||
return possibleCandidates;
|
||||
}
|
||||
|
||||
public void setPossibleCandidates(LinkedList<PossibleCandidate> possibleCandidates) {
|
||||
this.possibleCandidates = possibleCandidates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PossibleCandidateRepository extends JpaRepository<PossibleCandidate, Integer> {
|
||||
|
||||
public PossibleCandidate findByNameAndCategoryID(String name, Long category_id);
|
||||
Optional<PossibleCandidate> findById(Long id);
|
||||
|
||||
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package com.github.cato447.AbizeitungVotingSystem.table;
|
||||
import com.github.cato447.AbizeitungVotingSystem.controller.VotingController;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CategoryRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.PossibleCandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.VoterRepository;
|
||||
|
||||
import java.io.File;
|
||||
@@ -18,11 +20,16 @@ public class TableAction {
|
||||
|
||||
}
|
||||
|
||||
public void addCandidate(String name, CandidateRepository candidateRepository){
|
||||
Candidate candidate = new Candidate(name);
|
||||
public void addCandidate(String name, long category_id, CategoryRepository categoryRepository,CandidateRepository candidateRepository){
|
||||
Candidate candidate = new Candidate(name, categoryRepository.findById(category_id).get());
|
||||
candidateRepository.save(candidate);
|
||||
}
|
||||
|
||||
public void addPossibleCandidate(String name, long category_id, CategoryRepository categoryRepository, PossibleCandidateRepository possibleCandidateRepository){
|
||||
PossibleCandidate possibleCandidate = new PossibleCandidate(name, categoryRepository.findById(category_id).get());
|
||||
possibleCandidateRepository.save(possibleCandidate);
|
||||
}
|
||||
|
||||
public void updateVotingStatus(String email, VoterRepository voterRepository){
|
||||
Voter voter = voterRepository.findByEmail(email);
|
||||
voter.vote();
|
||||
@@ -43,7 +50,7 @@ public class TableAction {
|
||||
ArrayList<Voter> voters = new ArrayList<Voter>();
|
||||
while (myReader.hasNextLine()) {
|
||||
String email = myReader.nextLine();
|
||||
Voter voter = new Voter(email, false);
|
||||
Voter voter = new Voter(email);
|
||||
voters.add(voter);
|
||||
}
|
||||
voterRepository.saveAll(voters);
|
||||
@@ -54,14 +61,14 @@ public class TableAction {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpCandidates(CandidateRepository candidateRepository){
|
||||
public void setUpCandidates(CandidateRepository candidateRepository, CategoryRepository categoryRepository){
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
Collections.addAll(names, "Greta Bentgens", "Laura König", "Aaron Glos", "Lukas Boy", "Frau Meyering"
|
||||
, "Frau Adams", "Herr Petering", "Frau Milde", "Frau Meyer");
|
||||
|
||||
ArrayList<Candidate> candidates = new ArrayList<>();
|
||||
for (String name: names) {
|
||||
Candidate candidate = new Candidate(name);
|
||||
Candidate candidate = new Candidate(name, categoryRepository.findById(20l).get());
|
||||
candidates.add(candidate);
|
||||
}
|
||||
candidateRepository.saveAll(candidates);
|
||||
@@ -138,6 +145,20 @@ public class TableAction {
|
||||
return formatAsTable(rows);
|
||||
}
|
||||
|
||||
public String logPossibleCandidates(LinkedList<PossibleCandidate> possibleCandidates, CategoryRepository categoryRepository){
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
List<String> headers = Arrays.asList("Id", "Name", "Votes", "Category_ID");
|
||||
rows.add(headers);
|
||||
long i = 1;
|
||||
for (PossibleCandidate possibleCandidate: possibleCandidates) {
|
||||
Category category = categoryRepository.findById(i).get();
|
||||
rows.add(Arrays.asList("" + i, possibleCandidate.getName(), "" + 0, "" + category.getId()));
|
||||
i++;
|
||||
}
|
||||
|
||||
return formatAsTable(rows);
|
||||
}
|
||||
|
||||
private String formatAsTable(List<List<String>> rows) {
|
||||
int[] maxLengths = new int[rows.get(0).size()];
|
||||
for (List<String> row : rows)
|
||||
|
||||
@@ -1,46 +1,36 @@
|
||||
Wer wird nie von zuhause ausziehen?
|
||||
Wer bekommt die meisten Punkte in Flensburg (Wackel)
|
||||
Wer ist der/die kreativste Zuspätkommer/in
|
||||
Mit wem wird man am ehesten in der Zukunft angeben zur Schule gegangen zu sein?
|
||||
Wer wohnt im Fittnessstudio?
|
||||
Wer ist der Adonis/Afrodite der Stufe?
|
||||
Wer landet am ehesten im Bundestag (Wackel)
|
||||
Wer landet als erstes in der Ausnüchterungszelle?
|
||||
Wer ist der coolste Leherer?
|
||||
Wer ist die coolste Lehrerin?
|
||||
Wer macht den besten Matheunterricht?
|
||||
Welcher Lehrer hat den Beruf verfehlt?
|
||||
Welcher Lehrer ist nie da?
|
||||
Wer hat das Internet erfunden?
|
||||
Wer sponsort Schollin?
|
||||
Wer hat nur ein Outfit?
|
||||
Wer könnte Modeln?
|
||||
Wer ist am engagiertesten?
|
||||
Wer hat das größte Ego? (Wackel)
|
||||
Wer wird Bundeskanzler? (Lehrer und Schüler)
|
||||
Wer wird eine Sekte gründen?
|
||||
Wer saß am längsten im Klassenschrank?
|
||||
Wer hat die gößte Sauklaue (Leherer)?
|
||||
Wer hat die größte Sauklaue (Schüler)?
|
||||
Wer gründet das nächste Google?
|
||||
Wer kommt am schnellsten in den Knast?
|
||||
Top 3-Pärchen?
|
||||
Top 3 Lehrergespanne?
|
||||
Wer ist der motiviertester Lehrer?
|
||||
Wer ist Google auf zwei Beinen(Leherer)?
|
||||
Wer ist Google auf zwei Beinen(Schüler)?
|
||||
Wer hat den besten Style (Mädchen)?
|
||||
Wer hat den besten Style (Jungs)?
|
||||
Wer währe ein gutes Pärchen (Lehrer)?
|
||||
Wer währe ein gutes Pärchen (Schüler)?
|
||||
Wer trinkt am meisten Kaffe?
|
||||
Tischflip
|
||||
Wer wird Harzer?
|
||||
Wer hat Wiedererkennungswert?
|
||||
Wen erkennt man an der Lache?
|
||||
Wer bringt die dümmsten Witze?
|
||||
Wer hat den meisten Schwachsinn erzählt?
|
||||
Welche Lehrer machen nie das, was die Schüler wollten?
|
||||
Welcher Kurs hat am meisten Kuchen gegessen?
|
||||
Welcher Kurs hat am meisten Kaffee getrunken?
|
||||
Wer hat die meisten peinlichen Momente gebracht?
|
||||
1. Wer wird nie von zuhause ausziehen? (Schüler)
|
||||
1. Wer ist der/die kreativste Zuspätkommer/in (Schüler)
|
||||
1. Mit wem wird man am ehesten in der Zukunft angeben zur Schule gegangen zu sein? (Schüler)
|
||||
1. Wer wohnt im Fittnessstudio? (Schüler)
|
||||
1. Wer ist der coolste Leherer?
|
||||
1. Wer ist die coolste Lehrerin?
|
||||
1. Wer macht den besten Matheunterricht?
|
||||
1. Welcher Lehrer hat den Beruf verfehlt?
|
||||
1. Welcher Lehrer ist nie da?
|
||||
1. Wer hat das Internet erfunden?
|
||||
1. Wer sponsort Schollin? (Schüler)
|
||||
1. Wer ist am engagiertesten? (Schüler)
|
||||
1. Wer wird Bundeskanzler? (Schüler)
|
||||
1. Wer hat das Kimpeltum gegründet? (Schüler)
|
||||
1. Wer saß am längsten im Klassenschrank? (Schüler)
|
||||
1. Wer hat die gößte Sauklaue? (Leherer)
|
||||
1. Wer gründet das nächste Google? (Schüler)
|
||||
1. Wer kommt am schnellsten in den Knast? (Schüler)
|
||||
1. Top 3-Pärchen? (Schüler)
|
||||
1. Top 3 Lehrergespanne? (Schüler)
|
||||
1. Wer ist der motiviertester Lehrer?
|
||||
1. Wer ist Google auf zwei Beinen(Schüler)?
|
||||
1. Wer hat den besten Style (Schüler)?
|
||||
1. Wer hat den besten Style (Lehrer)?
|
||||
1. Wer währe ein gutes Pärchen (Lehrer)?
|
||||
1. Wer trinkt am meisten Kaffe (Schüler)?
|
||||
1. Wer trinkt am meisten Kaffe (Lehrer)?
|
||||
1. Tischflip?
|
||||
1. Wer wird Harzer?
|
||||
1. Wer hat Wiedererkennungswert (Schüler)?
|
||||
1. Wen erkennt man an der Lache (Schüler)?
|
||||
1. Wer bringt die dümmsten Witze? (Lehrer)
|
||||
1. Wer hat den meisten Schwachsinn erzählt? (Lehrer)
|
||||
1. Welche Lehrer machen nie das, was die Schüler wollten? (Lehrer)
|
||||
1. Wer isst immer? (Lehrer)
|
||||
1. Wer hat die meisten peinlichen Momente gebracht?
|
||||
@@ -20,8 +20,7 @@
|
||||
<tbody>
|
||||
<tr th:each="category, itemStat : ${categories}">
|
||||
<td th:text="${category.name}"></td>
|
||||
<td><input th:field="*{candidates[__${itemStat.index}__].name}" /></td>
|
||||
</td>
|
||||
<td><input th:field="*{possibleCandidates[__${itemStat.index}__].name}" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user