using e_suite.API.Common;
using e_suite.API.Common.models;
using e_suite.Utilities.Pagination;
using eSuite.API.security;
using eSuite.API.Utilities;
using eSuite.Core.Miscellaneous;
using eSuite.Core.Security;
using Microsoft.AspNetCore.Mvc;
namespace eSuite.API.Controllers;
///
/// This part of the API is responsible for allowing a user to interact with organisations.
///
[Route("api/[controller]")]
[ApiController]
public class OrganisationsController : ESuiteControllerBase
{
private readonly IOrganisationsManager _organisationsManager;
///
///
///
///
public OrganisationsController(IOrganisationsManager organisationsManager)
{
_organisationsManager = organisationsManager;
}
///
/// Returns a list of all the organisations in the system
///
/// This returns all the organisations in the system that are not soft deleted.
[Route("organisations")]
[HttpGet]
[AccessKey(SecurityAccess.ViewOrganisation)]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetOrganisationsList([FromQuery] Paging paging, CancellationToken cancellationToken = default!)
{
var organisations = await _organisationsManager.GetOrganisationList(paging, cancellationToken);
return Ok(organisations);
}
///
/// Reads an organisation
///
/// This willreturn the organisation with the specified id.
/// Either the id or the Guid of the organisation
///
[Route("organisation")]
[HttpGet]
[AccessKey(SecurityAccess.ViewOrganisation)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetOrganisation(
[FromQuery] GeneralIdRef generalIdRef,
CancellationToken cancellationToken = default!
)
{
var organisation = await _organisationsManager.GetOrganisation(generalIdRef, cancellationToken);
return Ok(organisation);
}
///
/// Create a organisation
///
/// Contains the data required to create a organisation
///
[Route("organisation")]
[HttpPost]
[AccessKey(SecurityAccess.AddOrganisation)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task CreateOrganisation(
[FromBody] CreateOrganisation createOrganisationDto,
CancellationToken cancellationToken = default!
)
{
await _organisationsManager.AddOrganisation(AuditUserDetails, createOrganisationDto, true, cancellationToken);
return Ok();
}
///
/// Edit a organisation
///
/// All the fields can be edited except the Id and Guid field
/// Contains the details of the updated organisation
///
[Route("organisation")]
[HttpPut]
[AccessKey(SecurityAccess.EditOrganisation)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task EditOrganisation(EditOrganisation editOrganisationDto, CancellationToken cancellationToken = default!)
{
await _organisationsManager.EditOrganisation(AuditUserDetails, editOrganisationDto, true, cancellationToken);
return Ok();
}
///
/// Deletes an organisation
///
/// This will perform a soft delete action. The organisation is not actually deleted.
/// Either the id or the Guid of the organisation
///
[Route("organisation")]
[HttpDelete]
[AccessKey(SecurityAccess.DeleteOrganisation)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task DeleteOrganisation(
GeneralIdRef generalIdRef,
CancellationToken cancellationToken = default!
)
{
await _organisationsManager.DeleteOrganisation(AuditUserDetails, generalIdRef, true, cancellationToken);
return Ok();
}
}