initial
This commit is contained in:
124
src/main/java/com/pmu/betengine/controller/TPEController.java
Normal file
124
src/main/java/com/pmu/betengine/controller/TPEController.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.pmu.betengine.controller;
|
||||
|
||||
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<TPEDTO>> getAllTPEs() {
|
||||
return ResponseEntity.ok(tpeService.getAllTPEs());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<TPEDTO> 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);
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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}/liberer")
|
||||
@Operation(summary = "Libérer Un TPE",
|
||||
description = "Méthode permettant de libérer un TPE")
|
||||
public ResponseEntity<TPEDTO> 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) {
|
||||
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() {
|
||||
return ResponseEntity.ok(tpeService.getTPEsDisponibles());
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<TPEDTO>> 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(
|
||||
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")
|
||||
public ResponseEntity<Long> getCountAssignes() {
|
||||
return ResponseEntity.ok(tpeService.countTPEsAssignes());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user