118 lines
4.4 KiB
Java
118 lines
4.4 KiB
Java
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;
|
|
import com.pmu.betengine.service.TPEService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/tpes")
|
|
@CrossOrigin(origins = "*")
|
|
@Tag(name = "Gestion des TPE", description = "Endpoints relatifs à l'objet TPE")
|
|
|
|
public class TPEController {
|
|
|
|
private final TPEService tpeService;
|
|
|
|
public TPEController(TPEService tpeService) {
|
|
this.tpeService = tpeService;
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<List<TPE>> getAllTPEs() {
|
|
return ResponseEntity.ok(tpeService.getAllTPEs());
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<TPE> getTPEById(@PathVariable Long id) {
|
|
return ResponseEntity.ok(tpeService.getTPEById(id));
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<TPE> createTPE(@RequestBody TPE tpe) {
|
|
return new ResponseEntity<>(tpeService.createTPE(tpe), HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<TPE> updateTPE(@PathVariable Long id, @RequestBody TPE tpe) {
|
|
return ResponseEntity.ok(tpeService.updateTPE(id, tpe));
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<Void> deleteTPE(@PathVariable Long id) {
|
|
tpeService.deleteTPE(id);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
|
|
@PatchMapping("/{id}/statut")
|
|
public ResponseEntity<TPE> updateStatut(@PathVariable Long id, @RequestBody Map<String, String> request) {
|
|
String statutStr = request.get("statut");
|
|
StatutTPE statut = StatutTPE.valueOf(statutStr.toUpperCase());
|
|
return ResponseEntity.ok(tpeService.updateStatut(id, statut));
|
|
}
|
|
|
|
// @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("/liberer/{id}")
|
|
public ResponseEntity<TPE> libererTPE(@PathVariable Long id) {
|
|
return ResponseEntity.ok(tpeService.libererTPE(id));
|
|
}
|
|
|
|
@GetMapping("/statut/{statut}")
|
|
public ResponseEntity<List<TPE>> getTPEsByStatut(@PathVariable StatutTPE statut) {
|
|
return ResponseEntity.ok(tpeService.getTPEsByStatut(statut));
|
|
}
|
|
|
|
@GetMapping("/disponibles")
|
|
public ResponseEntity<List<TPE>> getTPEsDisponibles() {
|
|
return ResponseEntity.ok(tpeService.getTPEsDisponibles());
|
|
}
|
|
|
|
@GetMapping("/search")
|
|
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() {
|
|
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_MAINTENANCE, tpeService.countTPEsByStatut(StatutTPE.EN_MAINTENANCE),
|
|
StatutTPE.HORS_SERVICE, tpeService.countTPEsByStatut(StatutTPE.HORS_SERVICE),
|
|
StatutTPE.VOLE, tpeService.countTPEsByStatut(StatutTPE.VOLE)
|
|
));
|
|
}
|
|
|
|
@GetMapping("/stats/assignes")
|
|
public ResponseEntity<Long> getCountAssignes() {
|
|
return ResponseEntity.ok(tpeService.countTPEsAssignes());
|
|
}
|
|
}
|
|
|