70%
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.pmu.betengine.controller;
|
||||
|
||||
import com.pmu.betengine.model.TPE;
|
||||
import com.pmu.betengine.model.dto.TPEDTO;
|
||||
import com.pmu.betengine.model.dto.TPERequestDTO;
|
||||
import com.pmu.betengine.model.statut.StatutTPE;
|
||||
@@ -18,6 +19,7 @@ import java.util.Map;
|
||||
@RequestMapping("/api/v1/tpes")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Tag(name = "Gestion des TPE", description = "Endpoints relatifs à l'objet TPE")
|
||||
|
||||
public class TPEController {
|
||||
|
||||
private final TPEService tpeService;
|
||||
@@ -27,94 +29,84 @@ public class TPEController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<TPEDTO>> getAllTPEs() {
|
||||
public ResponseEntity<List<TPE>> getAllTPEs() {
|
||||
return ResponseEntity.ok(tpeService.getAllTPEs());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<TPEDTO> getTPEById(@PathVariable Long id) {
|
||||
public ResponseEntity<TPE> getTPEById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(tpeService.getTPEById(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "Enregistrer Un TPE",
|
||||
description = "Méthode permettant d'enregistrer un TPE")
|
||||
public ResponseEntity<TPEDTO> createTPE(@Valid @RequestBody TPERequestDTO requestDTO) {
|
||||
return new ResponseEntity<>(tpeService.createTPE(requestDTO), HttpStatus.CREATED);
|
||||
public ResponseEntity<TPE> createTPE(@RequestBody TPE tpe) {
|
||||
return new ResponseEntity<>(tpeService.createTPE(tpe), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "Modifier Un TPE",
|
||||
description = "Méthode permettant de modifier un TPE")
|
||||
public ResponseEntity<TPEDTO> updateTPE(@PathVariable Long id, @Valid @RequestBody TPERequestDTO requestDTO) {
|
||||
return ResponseEntity.ok(tpeService.updateTPE(id, requestDTO));
|
||||
public ResponseEntity<TPE> updateTPE(@PathVariable Long id, @RequestBody TPE tpe) {
|
||||
return ResponseEntity.ok(tpeService.updateTPE(id, tpe));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "Supprimer Un TPE",
|
||||
description = "Méthode permettant de supprimer un TPE")
|
||||
public ResponseEntity<Void> deleteTPE(@PathVariable Long id) {
|
||||
tpeService.deleteTPE(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/statut")
|
||||
@Operation(summary = "Modifier le Statut d'un TPE",
|
||||
description = "Méthode permettant de modifier le statut d'un TPE")
|
||||
public ResponseEntity<TPEDTO> updateStatut(@PathVariable Long id, @RequestBody Map<String, String> request) {
|
||||
public ResponseEntity<TPE> updateStatut(@PathVariable Long id, @RequestBody Map<String, String> request) {
|
||||
String statutStr = request.get("statut");
|
||||
try {
|
||||
StatutTPE statut = StatutTPE.valueOf(statutStr.toUpperCase());
|
||||
return ResponseEntity.ok(tpeService.updateStatut(id, statut));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("Statut invalide: " + statutStr);
|
||||
}
|
||||
StatutTPE statut = StatutTPE.valueOf(statutStr.toUpperCase());
|
||||
return ResponseEntity.ok(tpeService.updateStatut(id, statut));
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/assigner")
|
||||
@Operation(summary = "Assigner Un TPE",
|
||||
description = "Méthode permettant d'd'assigner un TPE")
|
||||
public ResponseEntity<TPEDTO> assignerTPE(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(tpeService.assignerTPE(id));
|
||||
// @PatchMapping("/{id}/assigner")
|
||||
// public ResponseEntity<TPE> assignerTPE(@PathVariable Long id, @RequestParam Long agentId) {
|
||||
// return ResponseEntity.ok(tpeService.assignerTPE(id, agentId));
|
||||
// }
|
||||
@PatchMapping("/assigner")
|
||||
@Operation(summary = "Assigner Un TPE", description = "Assigner un TPE à un Agent")
|
||||
public ResponseEntity<TPE> assignerTPE(@RequestBody Map<String, Long> request) {
|
||||
Long tpeId = request.get("tpeId");
|
||||
Long agentId = request.get("agentId");
|
||||
return ResponseEntity.ok(tpeService.assignerTPE(tpeId, agentId));
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/liberer")
|
||||
@Operation(summary = "Libérer Un TPE",
|
||||
description = "Méthode permettant de libérer un TPE")
|
||||
public ResponseEntity<TPEDTO> libererTPE(@PathVariable Long id) {
|
||||
|
||||
@PatchMapping("/liberer/{id}")
|
||||
public ResponseEntity<TPE> libererTPE(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(tpeService.libererTPE(id));
|
||||
}
|
||||
|
||||
@GetMapping("/statut/{statut}")
|
||||
@Operation(summary = "Lister les TPE par statut",
|
||||
description = "Méthode permettant d'obtenir les TPE du statut en parametre")
|
||||
public ResponseEntity<List<TPEDTO>> getTPEsByStatut(@PathVariable StatutTPE statut) {
|
||||
public ResponseEntity<List<TPE>> getTPEsByStatut(@PathVariable StatutTPE statut) {
|
||||
return ResponseEntity.ok(tpeService.getTPEsByStatut(statut));
|
||||
}
|
||||
|
||||
@GetMapping("/disponibles")
|
||||
@Operation(summary = "Lister les TPE Disponibles",
|
||||
description = "Méthode permettant de lister les TPE disponibles")
|
||||
public ResponseEntity<List<TPEDTO>> getTPEsDisponibles() {
|
||||
public ResponseEntity<List<TPE>> getTPEsDisponibles() {
|
||||
return ResponseEntity.ok(tpeService.getTPEsDisponibles());
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<TPEDTO>> searchTPEs(@RequestParam String q) {
|
||||
public ResponseEntity<List<TPE>> searchTPEs(@RequestParam String q) {
|
||||
return ResponseEntity.ok(tpeService.searchTPEs(q));
|
||||
}
|
||||
|
||||
@GetMapping("/stats/count-by-statut")
|
||||
public ResponseEntity<Map<StatutTPE, Long>> getCountByStatut() {
|
||||
Map<StatutTPE, Long> stats = Map.of(
|
||||
return ResponseEntity.ok(Map.of(
|
||||
StatutTPE.VALIDE, tpeService.countTPEsByStatut(StatutTPE.VALIDE),
|
||||
StatutTPE.INVALIDE, tpeService.countTPEsByStatut(StatutTPE.INVALIDE),
|
||||
StatutTPE.EN_PANNE, tpeService.countTPEsByStatut(StatutTPE.EN_PANNE),
|
||||
StatutTPE.BLOQUE, tpeService.countTPEsByStatut(StatutTPE.BLOQUE),
|
||||
StatutTPE.DISPONIBLE, tpeService.countTPEsByStatut(StatutTPE.DISPONIBLE),
|
||||
StatutTPE.AFFECTE, tpeService.countTPEsByStatut(StatutTPE.AFFECTE),
|
||||
StatutTPE.EN_PANNE, tpeService.countTPEsByStatut(StatutTPE.EN_PANNE),
|
||||
StatutTPE.EN_MAINTENANCE, tpeService.countTPEsByStatut(StatutTPE.EN_MAINTENANCE),
|
||||
StatutTPE.HORS_SERVICE, tpeService.countTPEsByStatut(StatutTPE.HORS_SERVICE),
|
||||
StatutTPE.VOLE, tpeService.countTPEsByStatut(StatutTPE.VOLE)
|
||||
);
|
||||
return ResponseEntity.ok(stats);
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("/stats/assignes")
|
||||
@@ -122,3 +114,4 @@ public class TPEController {
|
||||
return ResponseEntity.ok(tpeService.countTPEsAssignes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user