Commit f07049b1 authored by Alexandre Ducarne's avatar Alexandre Ducarne

Expose all services

parent 9aaaba98
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Consultation;
import com.RESTAPI.RESTAPI.Repositories.ConsultationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(path="/consultation")
public class ConsultationController {
@Autowired
private ConsultationRepository consultationRepository;
@PutMapping(path = "/")
public @ResponseBody
Consultation create(@RequestBody Consultation consultation)
{
return consultation.getSujet() != null ? consultationRepository.save(consultation) : new Consultation();
}
@GetMapping(path = "/")
public @ResponseBody
Iterable<Consultation> getAll()
{
return consultationRepository.findAll();
}
}
\ No newline at end of file
...@@ -25,4 +25,11 @@ public class PropositionController { ...@@ -25,4 +25,11 @@ public class PropositionController {
{ {
return propositionRepository.findAll(); return propositionRepository.findAll();
} }
@GetMapping(path = "/{id}")
public @ResponseBody
Proposition getById(@PathVariable int id)
{
return propositionRepository.findById(id).get();
}
} }
\ No newline at end of file
package com.RESTAPI.RESTAPI.Controllers; package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Proposition;
import com.RESTAPI.RESTAPI.Entities.Vote; import com.RESTAPI.RESTAPI.Entities.Vote;
import com.RESTAPI.RESTAPI.Enums.ChoixVote;
import com.RESTAPI.RESTAPI.Repositories.ConsultationRepository; import com.RESTAPI.RESTAPI.Repositories.ConsultationRepository;
import com.RESTAPI.RESTAPI.Repositories.PropositionRepository; import com.RESTAPI.RESTAPI.Repositories.PropositionRepository;
import com.RESTAPI.RESTAPI.Repositories.VoteRepository; import com.RESTAPI.RESTAPI.Repositories.VoteRepository;
...@@ -22,7 +24,31 @@ public class VoteController { ...@@ -22,7 +24,31 @@ public class VoteController {
@PutMapping(path="/") @PutMapping(path="/")
public Vote vote(@RequestBody Vote vote) { public Vote vote(@RequestBody Vote vote) {
handleChoix(vote.getChoix(), vote.getProposition().getId());
return voteRepository.save(vote); return voteRepository.save(vote);
} }
private void handleChoix(ChoixVote choix, int id) {
Proposition p = propositionRepository.findById(id).get();
switch (choix){
case POUR:
p.setScorePour(p.getScorePour() + 1);
propositionRepository.save(p);
break;
case MAISPOUR:
p.setScoreMais(p.getScoreMais() + 1);
propositionRepository.save(p);
break;
case NEUTRE:
p.setScoreNeutre(p.getScoreNeutre() + 1);
propositionRepository.save(p);
break;
case NON:
p.setScoreNon(p.getScoreNon() + 1);
propositionRepository.save(p);
break;
}
}
} }
\ No newline at end of file
...@@ -15,4 +15,9 @@ public class Proposition { ...@@ -15,4 +15,9 @@ public class Proposition {
private String nom; private String nom;
@ManyToOne @ManyToOne
private Sujet sujet; private Sujet sujet;
private int scorePour;
private int scoreMais;
private int scoreNeutre;
private int scoreNon;
} }
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import com.RESTAPI.RESTAPI.Enums.StatusSujet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
@Entity @Entity
...@@ -18,5 +16,6 @@ public class Sujet { ...@@ -18,5 +16,6 @@ public class Sujet {
private Integer id; private Integer id;
private String nom; private String nom;
private Date dateFinPhase; private Date dateFinPhase;
private String status; @Enumerated(EnumType.STRING)
private StatusSujet status;
} }
...@@ -21,6 +21,7 @@ public class User { ...@@ -21,6 +21,7 @@ public class User {
private String type; private String type;
private Date dateNaissance; private Date dateNaissance;
private Integer telephone; private Integer telephone;
@Enumerated(EnumType.STRING)
private TypeUtilisateur typeUtilisateur; private TypeUtilisateur typeUtilisateur;
@OneToOne @OneToOne
private Compte compte; private Compte compte;
......
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import com.RESTAPI.RESTAPI.Enums.ChoixVote;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -19,7 +20,8 @@ public class Vote { ...@@ -19,7 +20,8 @@ public class Vote {
@ManyToOne @ManyToOne
Proposition proposition; Proposition proposition;
String choix; @Enumerated(EnumType.STRING)
ChoixVote choix;
String commentaire; String commentaire;
} }
package com.RESTAPI.RESTAPI.Enums;
public enum ChoixVote
{
POUR,
MAISPOUR,
NEUTRE,
NON
}
package com.RESTAPI.RESTAPI.Enums;
public enum StatusSujet
{
EN_CREATION,
ACTIF,
CLOS
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment