All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
318 lines
17 KiB
Java
318 lines
17 KiB
Java
package io.gmss.fiscad.controllers.decoupage;
|
|
|
|
import io.gmss.fiscad.entities.decoupage.Secteur;
|
|
import io.gmss.fiscad.exceptions.*;
|
|
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
|
|
import io.gmss.fiscad.paylaods.ApiResponse;
|
|
import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb;
|
|
import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
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.security.access.prepost.PreAuthorize;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
|
|
|
@RestController
|
|
@RequestMapping(value = "api/secteur", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
//@SecurityRequirement(name = "bearer")
|
|
@Tag(name = "Secteur")
|
|
//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')")
|
|
public class SecteurController {
|
|
|
|
private final SecteurService secteurService;
|
|
private static final Logger logger = LoggerFactory.getLogger(SecteurController.class);
|
|
|
|
public SecteurController(SecteurService secteurService) {
|
|
this.secteurService = secteurService;
|
|
}
|
|
|
|
@Operation(
|
|
summary = "Créer un secteur",
|
|
description = "Permet de Créer un secteur"
|
|
)
|
|
@PostMapping("/create")
|
|
public ResponseEntity<?> createSecteur(@RequestBody @Valid @Validated SecteurPaylaodWeb secteurPaylaodWeb) {
|
|
try {
|
|
secteurPaylaodWeb = secteurService.createSecteur(secteurPaylaodWeb);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurPaylaodWeb, "Secteur créé avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
@Operation(
|
|
summary = "mettre à jour un secteur",
|
|
description = "Permet de modifier un secteur"
|
|
)
|
|
@PutMapping("/update/{id}")
|
|
public ResponseEntity<?> updateSecteur(@PathVariable Long id, @RequestBody SecteurPaylaodWeb secteurPayloadWeb) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.updateSecteur(id, secteurPayloadWeb), "Secteur mis à jour avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
@Operation(
|
|
summary = "supprimer un secteur",
|
|
description = "Permet de supprimer un secteur"
|
|
)
|
|
@DeleteMapping("/delete/{id}")
|
|
public ResponseEntity<?> deleteSecteurr(@PathVariable Long id) {
|
|
try {
|
|
secteurService.deleteSecteur(id);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, "Secteur supprimée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs",
|
|
description = "Permet de récuperer l'ensemble des secteurs"
|
|
)
|
|
@GetMapping("/all")
|
|
public ResponseEntity<?> getAllSecteurList() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurList(), "Liste des secteurs chargée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs avec pagination",
|
|
description = "Permet de récuperer l'ensemble des secteurs avec pagination"
|
|
)
|
|
@GetMapping("/all-paged")
|
|
public ResponseEntity<?> getAllSecteurPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
|
|
try {
|
|
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurList(pageable), "Liste des secteurs chargée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
@Operation(
|
|
summary = "recuperer un secteurs par son ID ",
|
|
description = "Permet de récuperer le secteur ayant l'ID fournie en path"
|
|
)
|
|
@GetMapping("/id/{id}")
|
|
public ResponseEntity<?> getSecteurById(@PathVariable Long id) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurById(id), "Secteur trouvée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs d'une structure",
|
|
description = "Permet de récuperer l'ensemble des secteurs de la structure dont l'ID est fourni en path"
|
|
)
|
|
@GetMapping("/by-structure-id/{structureId}")
|
|
public ResponseEntity<?> getSecteurByStructureId(@PathVariable Long structureId) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurListByStructureId(structureId), "Secteur trouvée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs d'une structure",
|
|
description = "Permet de récuperer l'ensemble des secteurs de la structure dont l'ID est fourni en path avec pagination"
|
|
)
|
|
@GetMapping("/page/by-structure-id/{structureId}")
|
|
public ResponseEntity<?> getSecteurByStructureIdPage(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) {
|
|
try {
|
|
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurListByStructureId(structureId,pageable), "Secteur trouvée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs d'une section",
|
|
description = "Permet de récuperer l'ensemble des secteurs de la section dont l'ID est fourni en path"
|
|
)
|
|
@GetMapping("/by-section-id/{sectionId}")
|
|
public ResponseEntity<?> getSecteurBySectionId(@PathVariable Long sectionId) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurListBySectionId(sectionId), "Secteur trouvée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
@Operation(
|
|
summary = "recuperer tous les secteurs d'une section avec pagination",
|
|
description = "Permet de récuperer l'ensemble des secteurs de la section dont l'ID est fourni en path avec pagination"
|
|
)
|
|
@GetMapping("/page/by-section-id/{sectionId}")
|
|
public ResponseEntity<?> getSecteurBySectionIdPage(@PathVariable Long sectionId, @RequestParam int pageNo, @RequestParam int pageSize) {
|
|
try {
|
|
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, secteurService.getSecteurListBySectionId(sectionId,pageable), "Secteur trouvée avec succès."),
|
|
HttpStatus.OK
|
|
);
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
FileStorageException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
} catch (NullPointerException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
} catch (Exception e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |