64 lines
2.2 KiB
C#
64 lines
2.2 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.Authorization;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
|
|
|
[FeatureGate(FeatureFlags.EnableControllers)]
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class UserAssignmentController : ControllerBase
|
|
{
|
|
private readonly IUserAssignmentService _userAssignmentService;
|
|
|
|
public UserAssignmentController(IUserAssignmentService userAssignmentService)
|
|
{
|
|
_userAssignmentService = userAssignmentService;
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public async Task<IActionResult> GetAllUserAssignments()
|
|
{
|
|
try
|
|
{
|
|
var result = await _userAssignmentService.GetAllUserAssignmentsAsync();
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[RequirePermission("ASSIGN_REGIONAL_MANAGER")]
|
|
[HttpPost("SetRegionalManager", Name = "SetRegionalManager")]
|
|
public async Task<IActionResult> SetRegionalManager([FromBody] UserAssignmentRequest assignmentRequest)
|
|
{
|
|
try
|
|
{
|
|
assignmentRequest.Type = AssignmentType.RegionalManager;
|
|
var result = await _userAssignmentService.SetRegionalManager(assignmentRequest);
|
|
return Ok();
|
|
}
|
|
catch (BadUserAssignmentException ex)
|
|
{
|
|
return BadRequest(ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|