All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 39s
187 lines
10 KiB
Java
187 lines
10 KiB
Java
package io.gmss.fiscad.controllers.user;
|
|
|
|
|
|
import io.gmss.fiscad.entities.user.Fonction;
|
|
import io.gmss.fiscad.exceptions.*;
|
|
import io.gmss.fiscad.interfaces.rfu.metier.FonctionService;
|
|
import io.gmss.fiscad.paylaods.ApiResponse;
|
|
import io.gmss.fiscad.paylaods.request.crudweb.FonctionPaylaodWeb;
|
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
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/fonction", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@SecurityRequirement(name = "bearer")
|
|
@Tag(name = "Fonction")
|
|
@CrossOrigin(origins = "*")
|
|
public class FonctionController {
|
|
|
|
private final FonctionService fonctionService;
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FonctionController.class);
|
|
|
|
public FonctionController(FonctionService fonctionService) {
|
|
this.fonctionService = fonctionService;
|
|
}
|
|
|
|
@PostMapping("/create")
|
|
@PreAuthorize("hasAuthority('CREATE_FONCTION')")
|
|
public ResponseEntity<?> createFonction(@RequestBody @Valid @Validated FonctionPaylaodWeb fonctionPaylaodWeb) {
|
|
try {
|
|
fonctionPaylaodWeb = fonctionService.createFonction(fonctionPaylaodWeb);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, fonctionPaylaodWeb, "Secteur affecté 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);
|
|
}
|
|
}
|
|
|
|
@PutMapping("/update/{id}")
|
|
@PreAuthorize("hasAuthority('UPDATE_FONCTION')")
|
|
public ResponseEntity<?> updateFonction(@PathVariable Long id, @RequestBody FonctionPaylaodWeb fonctionPaylaodWeb) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, fonctionService.updateFonction(id, fonctionPaylaodWeb), "Affectation de Secteur mise à 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);
|
|
}
|
|
}
|
|
|
|
@DeleteMapping("/delete/{id}")
|
|
@PreAuthorize("hasAuthority('DELETE_FONCTION')")
|
|
public ResponseEntity<?> deleteFonction(@PathVariable Long id) {
|
|
try {
|
|
fonctionService.deleteFonction(id);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, "Fonction 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);
|
|
}
|
|
}
|
|
|
|
@GetMapping("/all")
|
|
@PreAuthorize("hasAuthority('READ_FONCTION')")
|
|
public ResponseEntity<?> getAllFonctionList() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, fonctionService.getFonctionListToDto(), "Liste des caractéristiques 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);
|
|
}
|
|
}
|
|
|
|
@GetMapping("/all-paged")
|
|
@PreAuthorize("hasAuthority('READ_FONCTION')")
|
|
public ResponseEntity<?> getAllFonctionPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
|
|
try {
|
|
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, fonctionService.getFonctionListToDtoPageable(pageable), "Liste des caractéristiques 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);
|
|
}
|
|
}
|
|
|
|
@GetMapping("/id/{id}")
|
|
@PreAuthorize("hasAuthority('READ_FONCTION')")
|
|
public ResponseEntity<?> getFonctionById(@PathVariable Long id) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, fonctionService.getFonctionByIdToDTO(id).orElse(null), "Fonction 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);
|
|
}
|
|
}
|
|
}
|