65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.FeatureManagement.Mvc;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
|
|
|
[FeatureGate(FeatureFlags.EnableControllers)]
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class CommissionController : ControllerBase
|
|
{
|
|
private readonly ICommissionService _commissionService;
|
|
|
|
public CommissionController(ICommissionService commissionService)
|
|
{
|
|
_commissionService = commissionService;
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
try
|
|
{
|
|
var results= await _commissionService.GetCommissionsAsync();
|
|
return Ok(results);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpPut("")]
|
|
public async Task<IActionResult> SetCommissions(List<Commission> commissions)
|
|
{
|
|
try
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
await _commissionService.SaveCommissionsAsync(commissions);
|
|
return NoContent();
|
|
}
|
|
catch (CommissionExistsException ex)
|
|
{
|
|
return Conflict(ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}.");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|