Latest commit on 10/02/2025

This commit is contained in:
2025-02-10 11:27:45 +01:00
parent 4f755a5b51
commit d6d448eab8
360 changed files with 2845 additions and 1971 deletions

View File

@@ -0,0 +1,136 @@
package io.gmss.fiscad.controllers.decoupage;
import io.gmss.fiscad.entities.decoupage.Arrondissement;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.ArrondissementService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "api/arrondissement", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "bearer")
@Tag(name = "Arrondissement")
@CrossOrigin(origins = "*")
public class ArrondissementController {
private final ArrondissementService arrondissementService;
public ArrondissementController(ArrondissementService arrondissementService) {
this.arrondissementService = arrondissementService;
}
@Operation(
description = "Cette ressource permet de créer un nouvel arrondissement",
summary = "Arrondissement",
responses = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(description = "Success", responseCode = "200"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(description = "Unauthorized / Invalid Token", responseCode = "403")}
)
@PostMapping("/create")
public ResponseEntity<?> createArrondissement(@RequestBody @Valid @Validated Arrondissement arrondissement) {
try{
arrondissement = arrondissementService.createArrondissement(arrondissement);
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissement, "Arrondissement créé avec succès."),
HttpStatus.OK
);
}catch (Exception e){
return new ResponseEntity<>(
new ApiResponse<>(false, e.getMessage()),
HttpStatus.OK
);
}
}
@Operation(
description = "Cette ressource permet de modifier un arrondissement",
summary = "Arrondissement",
responses = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(description = "Success", responseCode = "200"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(description = "Unauthorized / Invalid Token", responseCode = "403")}
)
@PutMapping("/update/{id}")
public ResponseEntity<?> updateArrondissement(@PathVariable Long id, @RequestBody Arrondissement arrondissement) {
try{
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissementService.updateArrondissement(id, arrondissement), "Arrondissement mis à jour avec succès."),
HttpStatus.OK
);
}catch (Exception e){
return new ResponseEntity<>(
new ApiResponse<>(false, e.getMessage()),
HttpStatus.OK
);
}
}
@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deleteArrondissement(@PathVariable Long id) {
try{
arrondissementService.deleteArrondissement(id);
return new ResponseEntity<>(
new ApiResponse<>(true,"Arrondissement supprimée avec succès."),
HttpStatus.OK
);
}catch (Exception e){
return new ResponseEntity<>(
new ApiResponse<>(false, e.getMessage()),
HttpStatus.OK
);
}
}
@GetMapping("/all")
public ResponseEntity<?> getAllArrondissementList() {
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissementService.getArrondissementList(), "Liste des arrondissements chargée avec succès."),
HttpStatus.OK
);
}
@GetMapping("/all-paged")
public ResponseEntity<?> getAllArrondissementPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissementService.getArrondissementList(pageable), "Liste des arrondissements chargée avec succès."),
HttpStatus.OK
);
}
@GetMapping("/id/{id}")
public ResponseEntity<?> getArrondissementById(@PathVariable Long id) {
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissementService.getArrondissementById(id), "Arrondissement trouvé avec succès."),
HttpStatus.OK
);
}
@GetMapping("/commune/{communeId}")
public ResponseEntity<?> getArrondissementByCommune(@PathVariable Long communeId) {
try{
return new ResponseEntity<>(
new ApiResponse<>(true, arrondissementService.getArrondissementByComune(communeId), "Liste des arrondissements par commune chargée avec succès."),
HttpStatus.OK
);
}catch (NotFoundException e){
return new ResponseEntity<>(
new ApiResponse<>(false, e.getMessage()),
HttpStatus.OK
);
}
}
}