Commit 3c4951b989e23e9fd48011800498715a296242fe
1 parent
687a7fa3
Date & Avancement autres entités
Showing
7 changed files
with
107 additions
and
7 deletions
Show diff stats
src/main/java/etunicorn/controller/ConsommationController.java
0 → 100644
... | ... | @@ -0,0 +1,55 @@ |
1 | +package etunicorn.controller; | |
2 | + | |
3 | +import etunicorn.entity.Consommation; | |
4 | +import etunicorn.generated.model.UpdateConsommationByIdRequest; | |
5 | +import etunicorn.generated.model.UpdateConsommationRequest; | |
6 | +import etunicorn.repository.ConsommationRepository; | |
7 | +import org.springframework.beans.factory.annotation.Autowired; | |
8 | +import org.springframework.http.HttpStatus; | |
9 | +import org.springframework.http.ResponseEntity; | |
10 | +import org.springframework.web.bind.annotation.PathVariable; | |
11 | +import org.springframework.web.bind.annotation.RequestBody; | |
12 | +import org.springframework.web.bind.annotation.RestController; | |
13 | + | |
14 | +import javax.validation.Valid; | |
15 | + | |
16 | +/** | |
17 | + * etunicorn-server | |
18 | + * Copyright © 2017 Le Club Info Polytech Lille | |
19 | + * Tous droits réservés | |
20 | + */ | |
21 | +@RestController | |
22 | +public class ConsommationController extends BaseController implements etunicorn.generated.ConsommationController { | |
23 | + @Autowired | |
24 | + ConsommationRepository consommationRepository; | |
25 | + | |
26 | + @Override | |
27 | + public ResponseEntity<?> getConsommation() { | |
28 | + return new ResponseEntity<Object>(this.consommationRepository.findAll(), HttpStatus.OK); | |
29 | + } | |
30 | + | |
31 | + private ResponseEntity<?> mergeConsommation(Consommation consommation, UpdateConsommationRequest updateConsommationRequest) { | |
32 | + // if (updateConsommationRequest.get) | |
33 | + return null; | |
34 | + } | |
35 | + | |
36 | + @Override | |
37 | + public ResponseEntity<?> updateConsommation(@Valid @RequestBody UpdateConsommationRequest updateConsommationRequest) { | |
38 | + return null; | |
39 | + } | |
40 | + | |
41 | + @Override | |
42 | + public ResponseEntity<?> updateConsommationById(@PathVariable Long consommationId, @Valid @RequestBody UpdateConsommationByIdRequest updateConsommationByIdRequest) { | |
43 | + return null; | |
44 | + } | |
45 | + | |
46 | + @Override | |
47 | + public ResponseEntity<?> getConsommationById(@PathVariable Long consommationId) { | |
48 | + return null; | |
49 | + } | |
50 | + | |
51 | + @Override | |
52 | + public ResponseEntity<?> deleteConsommationById(@PathVariable Long consommationId) { | |
53 | + return null; | |
54 | + } | |
55 | +} | ... | ... |
src/main/java/etunicorn/controller/PersonneController.java
... | ... | @@ -43,12 +43,12 @@ public class PersonneController extends BaseController implements etunicorn.gene |
43 | 43 | } |
44 | 44 | |
45 | 45 | private ResponseEntity<?> mergePersonne(Personne personne, UpdatePersonneRequest updatePersonneRequest) { |
46 | - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | |
47 | 46 | if (updatePersonneRequest.getNaissance() != null) { |
47 | + SimpleDateFormat format = new SimpleDateFormat("y-M-d"); | |
48 | 48 | try { |
49 | 49 | personne.setNaissance(format.parse(updatePersonneRequest.getNaissance())); |
50 | 50 | } catch (ParseException e) { |
51 | - e.printStackTrace(); | |
51 | + return generateError(HttpStatus.BAD_REQUEST, e, "La date n'est pas au format " + format.toString()); | |
52 | 52 | } |
53 | 53 | } |
54 | 54 | if (updatePersonneRequest.getCarte() != null) { |
... | ... | @@ -57,9 +57,6 @@ public class PersonneController extends BaseController implements etunicorn.gene |
57 | 57 | if (updatePersonneRequest.getLogin() != null) { |
58 | 58 | personne.setLogin(updatePersonneRequest.getLogin()); |
59 | 59 | } |
60 | - if (personne.getCarte() == null && personne.getLogin() == null) { | |
61 | - return generateError(HttpStatus.BAD_REQUEST, "La date ou la carte doivent être au moins renseignés."); | |
62 | - } | |
63 | 60 | if (updatePersonneRequest.getRole() != null) { |
64 | 61 | if (updatePersonneRequest.getRole() instanceof LinkedHashMap) { |
65 | 62 | LinkedHashMap<String, String> roleMap = (LinkedHashMap<String, String>) updatePersonneRequest.getRole(); |
... | ... | @@ -78,6 +75,14 @@ public class PersonneController extends BaseController implements etunicorn.gene |
78 | 75 | return generateError(HttpStatus.BAD_REQUEST, "Le rôle est un objet"); |
79 | 76 | } |
80 | 77 | } |
78 | + | |
79 | + if (personne.getCarte() == null && personne.getLogin() == null) { | |
80 | + return generateError(HttpStatus.BAD_REQUEST, "Le login ou la carte doivent être au moins renseignés."); | |
81 | + } | |
82 | + if (personne.getRole() == null) { | |
83 | + personne.setRole(roleRepository.findByNom("etudiant")); | |
84 | + } | |
85 | + | |
81 | 86 | try { |
82 | 87 | this.personneRepository.save(personne); |
83 | 88 | } catch (DataIntegrityViolationException e) { |
... | ... | @@ -122,6 +127,7 @@ public class PersonneController extends BaseController implements etunicorn.gene |
122 | 127 | @RestrictedTo("PERSONNE_REMOVE") |
123 | 128 | public ResponseEntity<?> deletePersonneById(@PathVariable BigDecimal idPersonne) { |
124 | 129 | Personne personne = personneRepository.findById(idPersonne.intValueExact()); |
130 | + | |
125 | 131 | if (personne == null) { |
126 | 132 | return new ResponseEntity<Object>(HttpStatus.NOT_FOUND); |
127 | 133 | } | ... | ... |
src/main/java/etunicorn/entity/Evenement.java
src/main/java/etunicorn/entity/Personne.java
src/main/java/etunicorn/repository/ConsommationRepository.java
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +package etunicorn.repository; | |
2 | + | |
3 | +import etunicorn.entity.Consommation; | |
4 | +import org.springframework.data.repository.CrudRepository; | |
5 | + | |
6 | +/** | |
7 | + * etunicorn-server | |
8 | + * Copyright © 2017 Le Club Info Polytech Lille | |
9 | + * Tous droits réservés | |
10 | + */ | |
11 | +public interface ConsommationRepository extends CrudRepository<Consommation, Long> { | |
12 | + Consommation findById(int id); | |
13 | +} | ... | ... |
src/main/java/etunicorn/repository/EvenementRepository.java
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +package etunicorn.repository; | |
2 | + | |
3 | +import etunicorn.entity.Evenement; | |
4 | +import org.springframework.data.repository.CrudRepository; | |
5 | + | |
6 | +/** | |
7 | + * etunicorn-server | |
8 | + * Copyright © 2017 Le Club Info Polytech Lille | |
9 | + * Tous droits réservés | |
10 | + */ | |
11 | +public interface EvenementRepository extends CrudRepository<Evenement, Long> { | |
12 | + Evenement findById(int id); | |
13 | +} | ... | ... |
src/main/java/etunicorn/repository/TransactionRepository.java
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +package etunicorn.repository; | |
2 | + | |
3 | +import etunicorn.entity.Transaction; | |
4 | +import org.springframework.data.repository.CrudRepository; | |
5 | + | |
6 | +/** | |
7 | + * etunicorn-server | |
8 | + * Copyright © 2017 Le Club Info Polytech Lille | |
9 | + * Tous droits réservés | |
10 | + */ | |
11 | +public interface TransactionRepository extends CrudRepository<Transaction, Long> { | |
12 | + Transaction findById(int id); | |
13 | +} | ... | ... |