Initial commit
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package io.gmss.infocad.controllers.decoupage;
|
||||
|
||||
|
||||
import io.gmss.infocad.entities.decoupage.Departement;
|
||||
import io.gmss.infocad.interfaces.decoupage.DepartementService;
|
||||
import io.gmss.infocad.paylaods.ApiResponse;
|
||||
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.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/departement", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public class DepartementController {
|
||||
|
||||
private final DepartementService departementService;
|
||||
|
||||
public DepartementController(DepartementService departementService) {
|
||||
this.departementService = departementService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createDepartement(@RequestBody @Valid @Validated Departement departement) {
|
||||
try{
|
||||
departement = departementService.createDepartement(departement);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, departement, "Departement créé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, e.getMessage()),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public ResponseEntity<?> updateDepartement(@PathVariable Long id, @RequestBody Departement departement) {
|
||||
try{
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, departementService.updateDepartement(id, departement), "Département 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<?> deleteDepartementr(@PathVariable Long id) {
|
||||
try{
|
||||
departementService.deleteDepartement(id);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true,"Département supprimé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, e.getMessage()),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<?> getAllDepartementList() {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, departementService.getDepartementList(), "Liste des département chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/all-paged")
|
||||
public ResponseEntity<?> getAllDepartementPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
|
||||
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, departementService.getDepartementList(pageable), "Liste des département chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<?> getDepartementById(@PathVariable Long id) {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, departementService.getDepartementById(id), "Département trouvé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user