Commit 4fd7a7fc4595c3d4eb7507f320660d9a4f209ce5
1 parent
4ceffe1e
/evenement
Showing
4 changed files
with
117 additions
and
3 deletions
Show diff stats
src/main/java/etunicorn/Application.java
... | ... | @@ -51,6 +51,11 @@ public class Application { |
51 | 51 | permissionRepository.save(new Permission("CONSO_GET")); |
52 | 52 | permissionRepository.save(new Permission("CONSO_LIST")); |
53 | 53 | permissionRepository.save(new Permission("CONSO_REMOVE")); |
54 | + permissionRepository.save(new Permission("EVNMT_ADD")); | |
55 | + permissionRepository.save(new Permission("EVNMT_EDIT")); | |
56 | + permissionRepository.save(new Permission("EVNMT_GET")); | |
57 | + permissionRepository.save(new Permission("EVNMT_LIST")); | |
58 | + permissionRepository.save(new Permission("EVNMT_REMOVE")); | |
54 | 59 | // ... |
55 | 60 | |
56 | 61 | //roleRepository.save(new Role("admin", (List<Permission>) permissionRepository.findAll())); | ... | ... |
src/main/java/etunicorn/controller/EvenementController.java
0 → 100644
... | ... | @@ -0,0 +1,109 @@ |
1 | +package etunicorn.controller; | |
2 | + | |
3 | +import etunicorn.RestrictedTo; | |
4 | +import etunicorn.entity.Evenement; | |
5 | +import etunicorn.generated.model.UpdateParticipeRequest; | |
6 | +import etunicorn.generated.model.UpdateReserveRequest; | |
7 | +import etunicorn.generated.model.UpdateEvenementByIdRequest; | |
8 | +import etunicorn.generated.model.UpdateEvenementRequest; | |
9 | +import etunicorn.repository.EvenementRepository; | |
10 | +import org.springframework.beans.factory.annotation.Autowired; | |
11 | +import org.springframework.http.HttpStatus; | |
12 | +import org.springframework.http.ResponseEntity; | |
13 | +import org.springframework.web.bind.annotation.PathVariable; | |
14 | +import org.springframework.web.bind.annotation.RequestBody; | |
15 | +import org.springframework.web.bind.annotation.RestController; | |
16 | + | |
17 | +import javax.validation.Valid; | |
18 | +import java.text.ParseException; | |
19 | +import java.text.SimpleDateFormat; | |
20 | + | |
21 | +/** | |
22 | + * etunicorn-server | |
23 | + * Copyright © 2017 Le Club Info Polytech Lille | |
24 | + * Tous droits réservés | |
25 | + */ | |
26 | +@RestController | |
27 | +public class EvenementController extends BaseController implements etunicorn.generated.EvenementController { | |
28 | + @Autowired | |
29 | + EvenementRepository evenementRepository; | |
30 | + | |
31 | + @Override | |
32 | + @RestrictedTo("EVNMT_LIST") | |
33 | + public ResponseEntity<?> getEvenement() { | |
34 | + return new ResponseEntity<Object>(this.evenementRepository.findAll(), HttpStatus.OK); | |
35 | + } | |
36 | + | |
37 | + private ResponseEntity<?> mergeEvenement(Evenement evenement, UpdateEvenementRequest updateEvenementRequest) { | |
38 | + if (updateEvenementRequest.getNom() != null) { | |
39 | + evenement.setNom(updateEvenementRequest.getNom()); | |
40 | + } | |
41 | + if (updateEvenementRequest.getPrix() != null) { | |
42 | + evenement.setPrix(updateEvenementRequest.getPrix()); | |
43 | + } | |
44 | + if (updateEvenementRequest.getDate() != null) { | |
45 | + SimpleDateFormat format = new SimpleDateFormat("Y-M-d H:m:s"); | |
46 | + try { | |
47 | + evenement.setDate(format.parse(updateEvenementRequest.getDate())); | |
48 | + } catch (ParseException e) { | |
49 | + return generateError(HttpStatus.BAD_REQUEST, e, "La date n'est pas au format " + format.toString()); | |
50 | + } | |
51 | + } | |
52 | + evenementRepository.save(evenement); | |
53 | + return new ResponseEntity(evenement, HttpStatus.CREATED); | |
54 | + } | |
55 | + | |
56 | + @Override | |
57 | + @RestrictedTo("EVNMT_ADD") | |
58 | + public ResponseEntity<?> updateEvenement(@Valid @RequestBody UpdateEvenementRequest updateEvenementRequest) { | |
59 | + Evenement evenement = new Evenement(); | |
60 | + return mergeEvenement(evenement, updateEvenementRequest); | |
61 | + } | |
62 | + | |
63 | + @Override | |
64 | + @RestrictedTo("EVNMT_EDIT") | |
65 | + public ResponseEntity<?> updateEvenementById(@PathVariable Long idEvenement, @Valid @RequestBody UpdateEvenementByIdRequest updateEvenementByIdRequest) { | |
66 | + Evenement evenement = evenementRepository.findById(idEvenement.intValue()); | |
67 | + if (evenement == null) { | |
68 | + return generateError(HttpStatus.NOT_FOUND, "Évènement inconnu"); | |
69 | + } | |
70 | + UpdateEvenementRequest updateEvenementRequest = new UpdateEvenementRequest(); | |
71 | + updateEvenementRequest.setNom(updateEvenementByIdRequest.getNom()); | |
72 | + updateEvenementRequest.setPrix(updateEvenementByIdRequest.getPrix()); | |
73 | + updateEvenementRequest.setDate(updateEvenementByIdRequest.getDate()); | |
74 | + return mergeEvenement(evenement, updateEvenementRequest); | |
75 | + } | |
76 | + | |
77 | + @Override | |
78 | + @RestrictedTo("EVNMT_GET") | |
79 | + public ResponseEntity<?> getEvenementById(@PathVariable Long idEvenement) { | |
80 | + Evenement evenement = evenementRepository.findById(idEvenement.intValue()); | |
81 | + if (evenement == null) { | |
82 | + return generateError(HttpStatus.NOT_FOUND, "Évènement inconnu"); | |
83 | + } | |
84 | + return new ResponseEntity(evenement, HttpStatus.OK); | |
85 | + } | |
86 | + | |
87 | + @Override | |
88 | + @RestrictedTo("EVNMT_REMOVE") | |
89 | + public ResponseEntity<?> deleteEvenementById(@PathVariable Long idEvenement) { | |
90 | + Evenement evenement = evenementRepository.findById(idEvenement.intValue()); | |
91 | + if (evenement == null) { | |
92 | + return generateError(HttpStatus.NOT_FOUND, "Évènement inconnu"); | |
93 | + } | |
94 | + evenementRepository.delete(evenement); | |
95 | + return null; | |
96 | + } | |
97 | + | |
98 | + @Override | |
99 | + @RestrictedTo("EVNMT_PARTICIPE") | |
100 | + public ResponseEntity<?> updateParticipe(@PathVariable Long idEvenement, @Valid @RequestBody UpdateParticipeRequest updateParticipeRequest) { | |
101 | + return null; | |
102 | + } | |
103 | + | |
104 | + @Override | |
105 | + @RestrictedTo("EVNMT_RESERVE") | |
106 | + public ResponseEntity<?> updateReserve(@PathVariable Long idEvenement, @Valid @RequestBody UpdateReserveRequest updateReserveRequest) { | |
107 | + return null; | |
108 | + } | |
109 | +} | ... | ... |
src/main/java/etunicorn/controller/PersonneController.java
... | ... | @@ -44,7 +44,7 @@ public class PersonneController extends BaseController implements etunicorn.gene |
44 | 44 | |
45 | 45 | private ResponseEntity<?> mergePersonne(Personne personne, UpdatePersonneRequest updatePersonneRequest) { |
46 | 46 | if (updatePersonneRequest.getNaissance() != null) { |
47 | - SimpleDateFormat format = new SimpleDateFormat("y-M-d"); | |
47 | + SimpleDateFormat format = new SimpleDateFormat("Y-M-d"); | |
48 | 48 | try { |
49 | 49 | personne.setNaissance(format.parse(updatePersonneRequest.getNaissance())); |
50 | 50 | } catch (ParseException e) { | ... | ... |
src/main/java/etunicorn/entity/Evenement.java