|
|
|
@ -4,71 +4,22 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
|
|
|
|
namespace espacecollab.backend.api.Controllers |
|
|
|
|
{ |
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController] |
|
|
|
|
public class CollaborateursController : ControllerBase |
|
|
|
|
//[Route("api/[controller]")] |
|
|
|
|
//[ApiController] |
|
|
|
|
public class CollaborateursController : BaseController<CollaborateurApiDto> |
|
|
|
|
{ |
|
|
|
|
private CollaborateursServices CollaborateursServices { get; } |
|
|
|
|
|
|
|
|
|
public CollaborateursController(CollaborateursServices collaborateursServices) |
|
|
|
|
public CollaborateursController(CollaborateursServices collaborateursServices) : base(collaborateursServices) |
|
|
|
|
{ |
|
|
|
|
CollaborateursServices = collaborateursServices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
|
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateurs() |
|
|
|
|
{ |
|
|
|
|
return Ok(CollaborateursServices.GetAll()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet("{collaborateurId:int:min(1)}")] |
|
|
|
|
public ActionResult<CollaborateurApiDto> GetCollaborateurById(uint collaborateurId) |
|
|
|
|
{ |
|
|
|
|
CollaborateurApiDto? collaborateur = CollaborateursServices.GetById(collaborateurId); |
|
|
|
|
if (collaborateur == null) |
|
|
|
|
return NotFound(); |
|
|
|
|
|
|
|
|
|
return Ok(collaborateur); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
public ActionResult<CollaborateurApiDto> AddCollaborateur(CollaborateurApiDto collaborateurApi) |
|
|
|
|
{ |
|
|
|
|
CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); |
|
|
|
|
if (addedCollaborateur == null) |
|
|
|
|
return Problem(); |
|
|
|
|
|
|
|
|
|
return Ok(addedCollaborateur); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpDelete("{collaborateurId:int:min(1)}")] |
|
|
|
|
public ActionResult DeleteCollaborateur(uint collaborateurId) |
|
|
|
|
{ |
|
|
|
|
bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); |
|
|
|
|
if (!isCollaborateurDeleted) |
|
|
|
|
return Problem(); |
|
|
|
|
|
|
|
|
|
return Ok(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpPut("{collaborateurId:int:min(1)}")] |
|
|
|
|
public ActionResult<CollaborateurApiDto> UpdateCollaborateur(uint collaborateurId, CollaborateurApiDto collaborateurApi) |
|
|
|
|
{ |
|
|
|
|
if (collaborateurApi.Id != collaborateurId) |
|
|
|
|
return Unauthorized(); |
|
|
|
|
CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); |
|
|
|
|
if (updatedCollaborateur == null) |
|
|
|
|
return Problem(); |
|
|
|
|
|
|
|
|
|
return Ok(updatedCollaborateur); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet("businessunit/{businessUnitId:int:min(1)}")] |
|
|
|
|
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByBusinessUnit(uint businessUnitId) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId); |
|
|
|
|
if (collaborateurs == null) |
|
|
|
|
if (!collaborateurs.Any()) |
|
|
|
|
return NotFound(); |
|
|
|
|
|
|
|
|
|
return Ok(collaborateurs); |
|
|
|
@ -78,7 +29,7 @@ namespace espacecollab.backend.api.Controllers |
|
|
|
|
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByReferrer(uint referrerId) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); |
|
|
|
|
if (collaborateurs == null) |
|
|
|
|
if (!collaborateurs.Any()) |
|
|
|
|
return NotFound(); |
|
|
|
|
|
|
|
|
|
return Ok(collaborateurs); |
|
|
|
|