diff --git a/src/main/java/etunicorn/SecurityInterceptor.java b/src/main/java/etunicorn/SecurityInterceptor.java index 8005753..d0ce6ab 100644 --- a/src/main/java/etunicorn/SecurityInterceptor.java +++ b/src/main/java/etunicorn/SecurityInterceptor.java @@ -55,14 +55,17 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter { Permission requiredPermission = permissionRepository.findByNom(annotation.value()); if (annotation.authentifie()) { + BaseController baseController = new BaseController(); + baseController.setRequest(request); + if (requiredPermission == null) { response.setStatus(HttpStatus.NOT_IMPLEMENTED.value()); - // TODO utiliser base controller + + ResponseEntity responseEntity = baseController.generateError(HttpStatus.NOT_IMPLEMENTED); + responseEntityToServletResponse(responseEntity, response); return false; } - BaseController baseController = new BaseController(); - baseController.setRequest(request); if (session == null) { ResponseEntity responseEntity = baseController.generateError(HttpStatus.UNAUTHORIZED); responseEntityToServletResponse(responseEntity, response); diff --git a/src/main/java/etunicorn/controller/PersonneController.java b/src/main/java/etunicorn/controller/PersonneController.java index 8680602..d8b2336 100644 --- a/src/main/java/etunicorn/controller/PersonneController.java +++ b/src/main/java/etunicorn/controller/PersonneController.java @@ -55,24 +55,27 @@ public class PersonneController extends BaseController implements etunicorn.gene return generateError(HttpStatus.BAD_REQUEST, "La date ou la carte doivent être au moins renseignés."); } if (updatePersonneRequest.getRole() != null) { - System.out.println("HELLO"); - LinkedHashMap roleMap = (LinkedHashMap) updatePersonneRequest.getRole(); - Role role = roleRepository.findByNom(roleMap.get("nom")); - if (role == null) { - return generateError(HttpStatus.NOT_FOUND, "Rôle inconnu"); - } - if (personne.getRole() != role) { - if (hasPermission("PERSONNE_ROLE")) { - personne.setRole(role); - } else { - return generateError(HttpStatus.FORBIDDEN, "Vous ne pouvez pas changer le rôle"); + if (updatePersonneRequest.getRole() instanceof LinkedHashMap) { + LinkedHashMap roleMap = (LinkedHashMap) updatePersonneRequest.getRole(); + Role role = roleRepository.findByNom(roleMap.get("nom")); + if (role == null) { + return generateError(HttpStatus.NOT_FOUND, "Rôle inconnu"); + } + if (personne.getRole() != role) { + if (hasPermission("PERSONNE_ROLE")) { + personne.setRole(role); + } else { + return generateError(HttpStatus.FORBIDDEN, "Vous ne pouvez pas changer le rôle"); + } } + } else { + return generateError(HttpStatus.BAD_REQUEST, "Le rôle est un objet"); } } try { this.personneRepository.save(personne); } catch (DataIntegrityViolationException e) { - return new ResponseEntity(HttpStatus.CONFLICT); + return generateError(HttpStatus.CONFLICT, "Un utilisateur avec la même carte ou le même login existe déjà"); } return new ResponseEntity(personne, HttpStatus.CREATED); } diff --git a/src/main/java/etunicorn/entity/Consommation.java b/src/main/java/etunicorn/entity/Consommation.java new file mode 100644 index 0000000..24b3bb8 --- /dev/null +++ b/src/main/java/etunicorn/entity/Consommation.java @@ -0,0 +1,47 @@ +package etunicorn.entity; + +import javax.persistence.*; + +/** + * etunicorn-server + * Copyright © 2017 Le Club Info Polytech Lille + * Tous droits réservés + */ +@Entity +public class Consommation { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @Column(unique = true) + private String nom; + + private float prix; + + public Consommation() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public float getPrix() { + return prix; + } + + public void setPrix(float prix) { + this.prix = prix; + } +} diff --git a/src/main/java/etunicorn/entity/Evenement.java b/src/main/java/etunicorn/entity/Evenement.java new file mode 100644 index 0000000..420a843 --- /dev/null +++ b/src/main/java/etunicorn/entity/Evenement.java @@ -0,0 +1,76 @@ +package etunicorn.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +/** + * etunicorn-server + * Copyright © 2017 Le Club Info Polytech Lille + * Tous droits réservés + */ +@Entity +public class Evenement { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @Column(unique = true) + private String nom; + + private float prix; + + private Date date; + + @ManyToMany(mappedBy = "participations") + private List participants; + + public Evenement(String nom) { + this.nom = nom; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public float getPrix() { + return prix; + } + + public void setPrix(float prix) { + this.prix = prix; + } + + @JsonFormat(pattern = "YYYY-MM-DD hh:mm:ss") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + @JsonIgnore + public List getParticipants() { + return participants; + } + + public void setParticipants(List participants) { + this.participants = participants; + } +} diff --git a/src/main/java/etunicorn/entity/Personne.java b/src/main/java/etunicorn/entity/Personne.java index 022e324..dd036f8 100644 --- a/src/main/java/etunicorn/entity/Personne.java +++ b/src/main/java/etunicorn/entity/Personne.java @@ -1,9 +1,11 @@ package etunicorn.entity; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; import javax.persistence.*; import java.util.Date; +import java.util.List; /** * etunicorn-server @@ -13,18 +15,30 @@ import java.util.Date; @Entity public class Personne { - - @ManyToOne - public Role role; @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; + @Column(unique = true) private String carte; + private Date naissance; + @Column(unique = true) private String login; + @ManyToOne + private Role role; + + @OneToMany(mappedBy = "participant") + private List operations; + + @OneToMany(mappedBy = "acteur") + private List realisees; + + @ManyToMany() + private List participations; + public Personne() { } @@ -80,4 +94,31 @@ public class Personne { public boolean hasPermission(Permission permission) { return role.hasPermission(permission); } + + @JsonIgnore + public List getOperations() { + return operations; + } + + public void setOperations(List operations) { + this.operations = operations; + } + + @JsonIgnore + public List getRealisees() { + return realisees; + } + + public void setRealisees(List realisees) { + this.realisees = realisees; + } + + @JsonIgnore + public List getParticipations() { + return participations; + } + + public void setParticipations(List participations) { + this.participations = participations; + } } diff --git a/src/main/java/etunicorn/entity/Role.java b/src/main/java/etunicorn/entity/Role.java index bbf26d5..9ef2f90 100644 --- a/src/main/java/etunicorn/entity/Role.java +++ b/src/main/java/etunicorn/entity/Role.java @@ -1,10 +1,8 @@ package etunicorn.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import java.util.ArrayList; +import com.fasterxml.jackson.annotation.JsonIgnore; + +import javax.persistence.*; import java.util.Collection; import java.util.List; @@ -19,8 +17,11 @@ public class Role { @Column(unique = true) private String nom = "etudiant"; - @OneToMany - private List permissions = new ArrayList<>(); + @ManyToMany + private List permissions; + + @OneToMany(mappedBy = "role") + private List membres; public Role() { } @@ -57,4 +58,13 @@ public class Role { public void delPermission(Permission permission) { this.permissions.remove(permission); } + + @JsonIgnore + public List getMembres() { + return membres; + } + + public void setMembres(List membres) { + this.membres = membres; + } } diff --git a/src/main/java/etunicorn/entity/Transaction.java b/src/main/java/etunicorn/entity/Transaction.java new file mode 100644 index 0000000..14527bd --- /dev/null +++ b/src/main/java/etunicorn/entity/Transaction.java @@ -0,0 +1,94 @@ +package etunicorn.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import javax.persistence.*; +import java.util.Date; + +/** + * etunicorn-server + * Copyright © 2017 Le Club Info Polytech Lille + * Tous droits réservés + */ +@Entity +public class Transaction { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private Date date; + + private float prix; + + @ManyToOne() + private Personne acteur; + + @ManyToOne() + private Personne participant; + + @ManyToOne + private Consommation consommation; + + @ManyToOne + private Evenement evenement; + + public Transaction() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @JsonFormat(pattern = "YYYY-MM-DD hh:mm:ss") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public float getPrix() { + return prix; + } + + public void setPrix(float prix) { + this.prix = prix; + } + + public Personne getActeur() { + return acteur; + } + + public void setActeur(Personne acteur) { + this.acteur = acteur; + } + + public Personne getParticipant() { + return participant; + } + + public void setParticipant(Personne participant) { + this.participant = participant; + } + + public Consommation getConsommation() { + return consommation; + } + + public void setConsommation(Consommation consommation) { + this.consommation = consommation; + } + + public Evenement getEvenement() { + return evenement; + } + + public void setEvenement(Evenement evenement) { + this.evenement = evenement; + } +} -- libgit2 0.21.2