Adding
This commit is contained in:
+751
@@ -0,0 +1,751 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
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.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ActivityController : ControllerBase
|
||||
{
|
||||
private readonly IActivityService _activityService;
|
||||
private readonly IActivityDetailService _activityDetailService;
|
||||
private readonly IDashboardService _dashboardService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
private readonly IActivityDecisionService _activityDecisionService;
|
||||
private readonly IEStatementService _eStatementService;
|
||||
|
||||
public ActivityController(IActivityService activityService, IActivityDetailService activityDetailService, IUserService userService,
|
||||
ICurrentUserService currentUser, IDashboardService dashboardService, IActivityDecisionService activityDecisionService,
|
||||
IEStatementService eStatementService)
|
||||
{
|
||||
_activityService = activityService;
|
||||
_activityDetailService = activityDetailService;
|
||||
_userService = userService;
|
||||
_currentUser = currentUser;
|
||||
_dashboardService = dashboardService;
|
||||
_activityDecisionService = activityDecisionService;
|
||||
_eStatementService = eStatementService;
|
||||
}
|
||||
|
||||
[HttpGet("paged")]
|
||||
[ProducesResponseType(typeof(PagedResponse<Activity>), 200)]
|
||||
public async Task<IActionResult> Get([FromQuery] ActivityFilter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchResult = await _activityService.ListByFilterAsync(filter);
|
||||
|
||||
foreach (var activity in searchResult.Items)
|
||||
{
|
||||
activity?.TransformForView();
|
||||
}
|
||||
|
||||
var result = new PagedResponse<Activity>(searchResult, filter, Url, Request);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me", Name = "GetCurrentUserProgress")]
|
||||
[RequirePermission("VIEW_DASHBOARD")]
|
||||
public async Task<IActionResult> GetCurrentUserProgress([FromQuery] int fromMonth, [FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear, [FromQuery] string employeeId = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (!string.IsNullOrWhiteSpace(employeeId))
|
||||
{
|
||||
employee = await _userService.GetUserByEmployeeIdAsync(employeeId);
|
||||
}
|
||||
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result = await _dashboardService.GetEmployeeProgressForMonthRangeAsync(employee, monthRange);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me/departments", Name = "GetCurrentUserDepartmentProgress")]
|
||||
[RequirePermission("VIEW_DASHBOARD,VIEW_PERFORMANCE_FOR_DEPARTMENT")]
|
||||
public async Task<IActionResult> GetCurrentUserDepartmentProgress([FromQuery] int fromMonth,
|
||||
[FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear, [FromQuery] int departmentId = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result = new List<DepartmentProgress>();
|
||||
if (departmentId != 0)
|
||||
{
|
||||
result.Add(
|
||||
await _dashboardService.GetDepartmentProgressForMonthRangeAsync(departmentId, monthRange));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AddRange(
|
||||
await _dashboardService.GetDepartmentProgressForMonthRangeAsync(employee.Departments,
|
||||
monthRange));
|
||||
}
|
||||
|
||||
foreach (var departmentProgress in result)
|
||||
{
|
||||
departmentProgress?.TransformForView();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("region", Name = "GetRegionProgress")]
|
||||
[RequirePermission("VIEW_DASHBOARD,VIEW_PERFORMANCE_FOR_REGION")]
|
||||
public async Task<IActionResult> GetRegionProgress([FromQuery] int fromMonth,
|
||||
[FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear, [FromQuery] string regionCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
List<Region> regions = new List<Region>();
|
||||
if (string.IsNullOrEmpty(regionCode))
|
||||
{
|
||||
var userDept = employee.Departments.FirstOrDefault(x => x.Role == Role.RegionalManager);
|
||||
if (userDept == null)
|
||||
{
|
||||
return Unauthorized("No User-Dept for region found.");
|
||||
}
|
||||
|
||||
regions.Add(Region.FindByCode(userDept.Department.RegionCode));
|
||||
}
|
||||
else if (regionCode == "ALL")
|
||||
{
|
||||
regions = Region.Regions;
|
||||
}
|
||||
else
|
||||
{
|
||||
regions.Add(Region.FindByCode(regionCode));
|
||||
}
|
||||
|
||||
if (!regions.Any())
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var regionProgress = new List<RegionProgress>();
|
||||
foreach (var region in regions)
|
||||
{
|
||||
var result =
|
||||
await _dashboardService.GetRegionProgressForMonthRangeAsync(region, monthRange);
|
||||
regionProgress.Add(result);
|
||||
}
|
||||
|
||||
foreach (var region in regionProgress)
|
||||
{
|
||||
region?.TransformForView();
|
||||
}
|
||||
|
||||
return Ok(regionProgress);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("businessLine", Name = "GetBusinessLineProgress")]
|
||||
[RequirePermission("VIEW_DASHBOARD,VIEW_PERFORMANCE_FOR_BUSINESS_LINE")]
|
||||
public async Task<IActionResult> GetBusinessLineProgress([FromQuery] int fromMonth,
|
||||
[FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear, [FromQuery] string businessLineCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
List<BusinessLine> bls = new List<BusinessLine>();
|
||||
if (string.IsNullOrEmpty(businessLineCode))
|
||||
{
|
||||
var userDept = employee.FindDepartmentForRole(Role.BusinessLineManager);
|
||||
if (userDept == null)
|
||||
{
|
||||
return Unauthorized("No User-Dept for business line found.");
|
||||
}
|
||||
|
||||
bls.Add(BusinessLine.FindByCode(userDept.Department.BusinessLineCode));
|
||||
}
|
||||
else if (businessLineCode == "ALL")
|
||||
{
|
||||
bls = BusinessLine.BusinessLines;
|
||||
}
|
||||
else
|
||||
{
|
||||
bls.Add(BusinessLine.FindByCode(businessLineCode));
|
||||
}
|
||||
|
||||
if (!bls.Any())
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var blProgress = new List<BusinessLineProgress>();
|
||||
foreach (var bl in bls)
|
||||
{
|
||||
var result =
|
||||
await _dashboardService.GetBusinessLineProgressForMonthRangeAsync(bl, monthRange);
|
||||
blProgress.Add(result);
|
||||
}
|
||||
|
||||
foreach (var bl in blProgress)
|
||||
{
|
||||
bl?.TransformForView();
|
||||
}
|
||||
|
||||
return Ok(blProgress);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateActivity([FromBody] Activity activity)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _activityService.SaveActivityAsync(activity);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("StateChange")]
|
||||
[HttpPost("ManualStateChange")]
|
||||
public async Task<IActionResult> ManuallyUpdateActivityState([FromBody] ActivityStateChange activityStateChange)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
|
||||
if (employee == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
await _activityService.ValidateCanApplyActivityStateChange(employee, activityStateChange);
|
||||
|
||||
var result = await _activityService.ApplyStateChange(activityStateChange);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (BadActivityStateChangeException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (NotAuthorizedException ex)
|
||||
{
|
||||
return StatusCode(403, ex.Message);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("Activity Not Found.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId}/StateChanges")]
|
||||
public async Task<IActionResult> GetActivityStateChanges([FromRoute] int activityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _activityService.GetActivityStateChanges(activityId);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId:int}/DetailChanges")]
|
||||
public async Task<IActionResult> GetActivityDetailChanges([FromRoute] int activityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var activity = await _activityService.GetActivity(activityId);
|
||||
var result = await _activityDetailService.GetAllActivityDetailUpdates(activity.Detail.Id);
|
||||
if (result == null || !result.Any())
|
||||
{
|
||||
NoContent();
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return NotFound($"No activity with Id {activityId} could be found");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId}/AvailableCommands")]
|
||||
public async Task<IActionResult> GetActivityAuthorizedCommands([FromRoute] int activityId, [FromQuery] string employeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (!string.IsNullOrWhiteSpace(employeeId))
|
||||
{
|
||||
employee = await _userService.GetUserByEmployeeIdAsync(employeeId);
|
||||
}
|
||||
|
||||
if (employee == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
var result = await _activityService.GetActivityAuthorizedCommands(employee, activityId);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId}")]
|
||||
public async Task<IActionResult> Get([FromRoute] int activityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _activityService.GetActivity(activityId);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("Activity Not Found.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("RequestTransfer")]
|
||||
[RequirePermission("TRANSFER_ACTIVITIES_BETWEEN_DEPARTMENTS, TRANSFER_ACTIVITIES_BETWEEN_ASSOCIATES")]
|
||||
public async Task<IActionResult> RequestTransfer([FromBody] ActivityTransferRequest transferRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _activityService.RequestTransfer(transferRequest);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("Activity Not Found.");
|
||||
}
|
||||
catch (BadActivityTransferActionException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("RequestTransferToOwnDepartment")]
|
||||
public async Task<IActionResult> RequestTransferToOwnDepartment([FromBody] ActivityTransferRequest transferRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _activityService.TransferToOwnDepartment(transferRequest, employee);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("Activity Not Found.");
|
||||
}
|
||||
catch (BadActivityTransferActionException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (NotAuthorizedException ex)
|
||||
{
|
||||
return Unauthorized(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("ApproveTransfer")]
|
||||
[RequirePermission("TRANSFER_ACTIVITIES_BETWEEN_DEPARTMENTS, TRANSFER_ACTIVITIES_BETWEEN_ASSOCIATES")]
|
||||
public async Task<IActionResult> ApproveTransfer([FromBody] ActivityTransferApprovalRequest approvalRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var result = await _activityService.ApproveTransfer(employee, approvalRequest);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("Activity Transfer Not Found.");
|
||||
}
|
||||
catch (NotAuthorizedException ex)
|
||||
{
|
||||
return StatusCode(403, ex.Message);
|
||||
}
|
||||
catch (BadActivityTransferActionException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId}/RequestedTransferAction")]
|
||||
public async Task<IActionResult> GetTransferAction([FromRoute] int activityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _activityService.GetRequestedTransfer(activityId);
|
||||
|
||||
result?.TransformForView();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
[Obsolete("Added here for legacy client support, please use Paginated version")]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _activityService.GetActivitiesAsync();
|
||||
|
||||
foreach (var activity in result)
|
||||
{
|
||||
activity?.TransformForView();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("matchActivities")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateReferralStatusProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> GetMatchActivityTemp()
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = await _activityService.MatchOrExpireReferrals();
|
||||
return Ok(results);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("updateEStatementReferrals")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateEStatementProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> GetDeliveryMethodsForEStatements()
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = await _eStatementService.UpdateOrExpireEStatementReferral();
|
||||
return Ok(results);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunDailyManualReviewRequery")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateAccountDecisionProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunDailyManualReviewRequery()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _activityDecisionService.UpdateAndDecideManualReviewActivities();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunDailyLICStationRequery")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateLICSalesProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunDailyLICRequery()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _activityDecisionService.UpdateAndDecideLicReferralActivities();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunDailyDirectDepositRequery")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateDirectDepositReferralsProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunDailyDirectDepositRequery()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _activityDecisionService.UpdateAndDecideDirectDepositPendingReferralActivities();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunDecisionService")]
|
||||
[Obsolete("Moved to Processing Controller, please use endpoint QueueNightlyIncentiveProcess/UpdateAccountDecisionProcess. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunDecisionService()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Information("RunDecisionService was forced");
|
||||
var decisioned = await _activityDecisionService.DecisionActivityByState(ActivityState.Created);
|
||||
Log.Information($"Auto-decisioned {decisioned.Count} activities in Created state");
|
||||
decisioned = await _activityDecisionService.DecisionActivityByState(ActivityState.ManualReview);
|
||||
Log.Information($"Auto-decisioned {decisioned.Count} activities in Manual Review state");
|
||||
decisioned = await _activityDecisionService.UpdateAndDecideManualReviewActivities();
|
||||
Log.Information($"Updated and Auto-Decisioned {decisioned.Count} Activities");
|
||||
decisioned = await _activityDecisionService.UpdateAndDecideDpEligibleLoanActivities();
|
||||
Log.Information($"Updated and Auto-Decisioned {decisioned.Count} Debt Protection Eligible Loan Activities");
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.FeatureManagement.Mvc;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ActivityImportController : ControllerBase
|
||||
{
|
||||
private readonly IQueueCreditCardImportService _queueCreditCardImportService;
|
||||
private readonly IQueueIndirectVehicleImportService _queueIndirectVehicleImportService;
|
||||
private readonly IQueueActionCreditCardService _queueActionCreditCardService;
|
||||
private readonly IQueueActionVehicleService _queueActionVehicleService;
|
||||
private readonly IQueueAlliedGapMbpService _queueAlliedGapMbpService;
|
||||
|
||||
public ActivityImportController(IQueueCreditCardImportService queueCreditCardImportService,
|
||||
IQueueIndirectVehicleImportService queueIndirectVehicleImportService, IQueueActionCreditCardService queueActionCreditCardService,
|
||||
IQueueActionVehicleService queueActionVehicleService, IQueueAlliedGapMbpService queueAlliedGapMbpService)
|
||||
{
|
||||
_queueCreditCardImportService = queueCreditCardImportService;
|
||||
_queueIndirectVehicleImportService = queueIndirectVehicleImportService;
|
||||
_queueActionCreditCardService = queueActionCreditCardService;
|
||||
_queueActionVehicleService = queueActionVehicleService;
|
||||
_queueAlliedGapMbpService = queueAlliedGapMbpService;
|
||||
}
|
||||
|
||||
[HttpPost("QueueCreditCardImportRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueCreditCardImportRequest([FromBody] ImportCreditCardSalesRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueCreditCardImportService.QueueCreditCardSalesImport(request);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueIndirectVehicleImportRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueIndirectVehicleImportRequest([FromBody] ImportIndirectVehicleSalesRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueIndirectVehicleImportService.QueueIndirectVehicleSalesImport(request);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueActionCreditCardRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueActionCreditCardRequest([FromBody] ActionCreditCardRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueActionCreditCardService.QueueActionCreditCardProcess(request);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueActionVehicleRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueActionVehicleRequest([FromBody] ActionVehicleRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueActionVehicleService.QueueActionVehicleProcess(request);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueAlliedGapMbpRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueAlliedGapMbpRequest([FromBody] AlliedGapMbpRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueAlliedGapMbpService.QueueGapMbpProcess(request);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
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;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DeadActivityController: ControllerBase
|
||||
{
|
||||
private readonly IDeadActivityService _deadActivityService;
|
||||
public DeadActivityController(IDeadActivityService deadActivityService)
|
||||
{
|
||||
_deadActivityService = deadActivityService;
|
||||
}
|
||||
|
||||
[HttpGet("paged")]
|
||||
[ProducesResponseType(typeof(PagedResponse<DeadActivity>), 200)]
|
||||
public async Task<IActionResult> Get([FromQuery] DeadActivityFilter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchResult = await _deadActivityService.ListByFilterAsync(filter);
|
||||
|
||||
foreach (var activity in searchResult.Items)
|
||||
{
|
||||
activity?.TransformForView();
|
||||
}
|
||||
|
||||
var result = new PagedResponse<DeadActivity>(searchResult, filter, Url, Request);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{activityId}")]
|
||||
public async Task<IActionResult> Get([FromRoute] int activityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _deadActivityService.GetDeadActivity(activityId);
|
||||
result?.TransformForView();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("DeadActivity Not Found.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{activityId}")]
|
||||
public async Task<IActionResult> Delete([FromRoute] int activityId, [FromQuery] int activityRef = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _deadActivityService.ProcessDeadActivity(activityId, activityRef);
|
||||
result?.TransformForView();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return BadRequest("DeadActivity Not Found.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
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.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
public class DepartmentController : ControllerBase
|
||||
{
|
||||
private readonly IDepartmentService _departmentService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public DepartmentController(IDepartmentService departmentService, IUserService userService, ICurrentUserService currentUser)
|
||||
{
|
||||
_departmentService = departmentService;
|
||||
_userService = userService;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
[HttpGet("", Name = "GetAllDepartments")]
|
||||
public async Task<IActionResult> GetDepartments([FromQuery] bool? canEditDepartmentGoals, [FromQuery] bool? canEditPersonnelGoals)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (canEditDepartmentGoals != null || canEditPersonnelGoals != null)
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
|
||||
if (employee == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
if (canEditDepartmentGoals.HasValue)
|
||||
{
|
||||
return Ok(await _departmentService.GetHierarchicalDepartmentsForEmployeeAsync(employee, false));
|
||||
}
|
||||
if (canEditPersonnelGoals.HasValue)
|
||||
{
|
||||
return Ok( await _departmentService.GetHierarchicalDepartmentsForEmployeeAsync(employee, true));
|
||||
}
|
||||
}
|
||||
var result = await _departmentService.GetAllDepartmentsAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{departmentId:int}", Name = "GetDepartmentById")]
|
||||
public async Task<IActionResult> GetDepartmentById([FromRoute] int departmentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _departmentService.GetDepartmentByIdAsync(departmentId);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return NotFound($"Could not find Department with that Id");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("", Name = "CreateNewDepartment")]
|
||||
public async Task<IActionResult> CreateDepartment([FromBody] Department newDepartment)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (newDepartment.Id != null)
|
||||
{
|
||||
return BadRequest("Id Field Cannot Be Assigned");
|
||||
}
|
||||
|
||||
var result = await _departmentService.SaveDepartmentAsync(newDepartment);
|
||||
return (Ok(result));
|
||||
}
|
||||
catch (DuplicateDataException)
|
||||
{
|
||||
return BadRequest($"Department Name Must Be Unique.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{id:int}", Name = "UpdateExistingDepartment")]
|
||||
public async Task<IActionResult> UpdateDepartment([FromBody] Department newDepartment, [FromRoute] int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _departmentService.UpdateDepartmentAsync(newDepartment, id);
|
||||
return (Ok(result));
|
||||
}
|
||||
catch (DuplicateDataException)
|
||||
{
|
||||
return BadRequest($"Department Name Must Be Unique.");
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return NotFound($"Could not find Department with that Id");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}/details", Name = "GetDepartmentDetails")]
|
||||
public async Task<IActionResult> GetDepartmentDetails([FromRoute] int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var details = await _departmentService.GetDepartmentDetailsAsync(id);
|
||||
return Ok(details);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.FeatureManagement.Mvc;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Authorization;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class EmployeeController : ControllerBase
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IDayForceSyncService _dayForceSyncService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public EmployeeController(
|
||||
ICurrentUserService currentUserService,
|
||||
IDayForceSyncService dayForceSyncService,
|
||||
IUserService userService
|
||||
)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_dayForceSyncService = dayForceSyncService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> GetAllUsers([FromQuery] string query, [FromQuery] string role)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchRequest = new UserSearchRequest
|
||||
{
|
||||
Query = query,
|
||||
Role = role
|
||||
};
|
||||
var result = await _userService.GetAllUsersAsync(searchRequest);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("terminated")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public IActionResult GetTerminatedUsers([FromQuery] int month, [FromQuery] int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(year, month);
|
||||
var result = _userService.GetTerminatedUsersAsync(monthRange);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
Log.Error(ex, $"Bad Request in {GetType().Name}");
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("resolve")]
|
||||
public async Task<IActionResult> ResolveUser(
|
||||
[FromQuery] string employeeId = null,
|
||||
[FromQuery] string email = null
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
var count = 0;
|
||||
if (!string.IsNullOrWhiteSpace(employeeId))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(email))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 1)
|
||||
{
|
||||
return BadRequest("Please provide only one query argument.");
|
||||
}
|
||||
|
||||
var result = await _userService.FindUserAsync(employeeId, email);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me")]
|
||||
public async Task<IActionResult> GetCurrentEmployee()
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
Log.Warning("Failed To Get Current User From Auth Context");
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var result = await _userService.GetUserByAdEmailAsync(currentUser.Email);
|
||||
if (result == null)
|
||||
{
|
||||
Log.Warning($"Failed To Get Current User From Email: {currentUser.Email}");
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{employeeId}")]
|
||||
[RequirePermission("ASSIGN_PERMISSIONS_TO_ASSOCIATES,ASSIGN_ASSOCIATES_TO_DEPARTMENT")]
|
||||
public async Task<IActionResult> GetEmployeeById(string employeeId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (employeeId == null)
|
||||
{
|
||||
return BadRequest("no_employee_id");
|
||||
}
|
||||
|
||||
var result = await _userService.GetUserByEmployeeIdAsync(employeeId);
|
||||
if (result == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[RequirePermission("ASSIGN_ASSOCIATES_TO_DEPARTMENT")]
|
||||
[HttpPost("{employeeId}/AssignDept", Name = "AssignDept")]
|
||||
public async Task<IActionResult> AssignDepartment(
|
||||
string employeeId,
|
||||
[FromBody] DepartmentAssignmentRequest assignment
|
||||
)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(currentUser.Email);
|
||||
if (UserService.ValidateChangePermission(employee.EmployeeId, employeeId))
|
||||
{
|
||||
return StatusCode(403, "Not allowed to assign yourself to a department.");
|
||||
}
|
||||
|
||||
await _userService.AssignDepartments(employeeId, assignment);
|
||||
return (Ok());
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (BadDepartmentAssignmentException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{employeeId}/UpdatePerms", Name = "UpdatePerms")]
|
||||
public async Task<IActionResult> AssignPermission(
|
||||
string employeeId,
|
||||
[FromBody] AdditionalPermissionRequest request
|
||||
)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _userService.UpdatePermissions(employeeId, request);
|
||||
return Ok(response);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[RequirePermission("ASSIGN_ASSOCIATES_TO_DEPARTMENT")]
|
||||
[HttpPost("{employeeId}/UpdateDept/{assignmentId:int}", Name = "UpdateDept")]
|
||||
public async Task<IActionResult> UpdateDepartmentAssignment(
|
||||
string employeeId,
|
||||
int assignmentId,
|
||||
[FromBody] DepartmentUpdateRequest request
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(currentUser.Email);
|
||||
if (UserService.ValidateChangePermission(employee.EmployeeId, employeeId))
|
||||
{
|
||||
return StatusCode(403, "Not allowed to terminate yourself from a department.");
|
||||
}
|
||||
|
||||
await _userService.UpdateDepartmentAssignment(request);
|
||||
return (Ok());
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (BadDepartmentAssignmentException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetHcmSystemUsers")]
|
||||
[RequirePermission("MANAGE_EMPLOYEE_DETAILS")]
|
||||
public async Task<IActionResult> GetHcmSystemUsers(string email = "", string employeeId = "", string fullName = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _dayForceSyncService.GetMatchingHcmUsers(email, employeeId, fullName);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("UpdateEmployeeDetails", Name = "UpdateEmployeeDetails")]
|
||||
[RequirePermission("MANAGE_EMPLOYEE_DETAILS")]
|
||||
public async Task<IActionResult> UpdateEmployeeDetails([FromBody] EmployeeDetailsUpdate request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var result = await _userService.GetUserByAdEmailAsync(request.OldEmail);
|
||||
if (result == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var updatedUserResult = await _dayForceSyncService.UpdateEmployeeDetails(request);
|
||||
|
||||
if (updatedUserResult.UpdatedSuccessfully)
|
||||
{
|
||||
return Ok(updatedUserResult);
|
||||
}
|
||||
|
||||
return BadRequest(updatedUserResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("SyncEmployeeIds")]
|
||||
[RequirePermission("MANAGE_EMPLOYEE_DETAILS")]
|
||||
public async Task<IActionResult> SyncEmployeeIds()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _userService.SyncActiveUserIds();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("sync", Name = "ForceRefresh")]
|
||||
public async Task<IActionResult> SyncDayForce()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Information("DayForce Sync was forced");
|
||||
var request = new DayforceProcessRequest();
|
||||
await _dayForceSyncService.SyncDayForceUsers(request);
|
||||
Log.Information("DayForce forced Sync has completed");
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information("DayForce forced Sync has failed");
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
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.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Authorization;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
public class GoalController : ControllerBase
|
||||
{
|
||||
private readonly IGoalService _goalService;
|
||||
private readonly IGoalDispersalService _goalDispersalService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public GoalController(IGoalService goalService, IGoalDispersalService goalDispersalService, ICurrentUserService currentUser, IUserService userService)
|
||||
{
|
||||
_goalService = goalService;
|
||||
_currentUser = currentUser;
|
||||
_userService = userService;
|
||||
_goalDispersalService = goalDispersalService;
|
||||
}
|
||||
|
||||
[HttpGet("", Name = "GetGoals")]
|
||||
public async Task<IActionResult> GetGoals([FromQuery] int fromMonth, [FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear, [FromQuery] int departmentId,
|
||||
[FromQuery] bool includePersonnel = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var query = new GoalSearchRequest()
|
||||
{
|
||||
DateRange = monthRange,
|
||||
departmentId = departmentId,
|
||||
IncludePersonnel = includePersonnel
|
||||
};
|
||||
|
||||
var result = await _goalService.GetGoalsAsync(query);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("department/", Name = "GetAllDepartmentsGoals")]
|
||||
public async Task<IActionResult> GetAllDepartmentsGoals([FromQuery] int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Now.Year;
|
||||
var result = await _goalService.GetAllAnnualDepartmentGoalsAsync(searchYear);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("department/{departmentId}", Name = "GetDepartmentGoals")]
|
||||
public async Task<IActionResult> GetDepartmentGoals(int departmentId, [FromQuery] int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Now.Year;
|
||||
var result = await _goalService.GetAnnualDepartmentGoalsAsync(departmentId, searchYear);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("personnel/{departmentId}", Name = "GetPersonnelGoals")]
|
||||
public async Task<IActionResult> GetPersonnelGoals(int departmentId, [FromQuery] int month,
|
||||
[FromQuery] int year, [FromQuery] bool includeAllPersonnel = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Now.Year;
|
||||
var searchMonth = month > 0 ? month : DateTime.Now.Month;
|
||||
var searchRequest = new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = departmentId,
|
||||
Month = searchMonth,
|
||||
Year = searchYear,
|
||||
IncludeAllPersonnel = includeAllPersonnel
|
||||
};
|
||||
var result = await _goalService.GetMonthlyPersonnelGoalsAsync(searchRequest);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("personnel/{departmentId}/disperse", Name = "DisperseByExtrapolation")]
|
||||
public async Task<IActionResult> GetPersonnelGoals(int departmentId, [FromBody] ExtrapolateGoalDispersalRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _goalDispersalService.DisperseGoalsByExtrapolatingLastMonth(departmentId, request.Month, request.Year);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me", Name = "GetCurrentUserGoals")]
|
||||
[RequirePermission("VIEW_DASHBOARD")]
|
||||
public async Task<IActionResult> GetCurrentUserGoals([FromQuery] int fromMonth, [FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result = await _goalService.GetEmployeeGoalsForMonthRangeAsync(employee, monthRange);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me/departments", Name = "GetCurrentUserDepartmentsGoals")]
|
||||
[RequirePermission("VIEW_DASHBOARD,VIEW_PERFORMANCE_FOR_DEPARTMENT")]
|
||||
public async Task<IActionResult> GetCurrentUserDepartmentsGoals([FromQuery] int fromMonth,
|
||||
[FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth, [FromQuery] int toYear)
|
||||
{
|
||||
try
|
||||
{
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result = await _goalService.GetEmployeeDepartmentsGoalsForMonthRangeAsync(employee, monthRange);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SetGoalForAudienceAndTimePeriod(GoalChange goalChange)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _goalService.SaveGoalAsync(goalChange);
|
||||
return Created($"{result.Select(x => x.Id)}", result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("multi")]
|
||||
public async Task<IActionResult> SetGoalsForAudienceAndTimePeriod(List<GoalChange> goalChanges)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var result = await _goalService.SaveGoalRangeAsync(goalChanges);
|
||||
return Created($"{result.Count}", result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("DisperseAll")]
|
||||
public async Task<IActionResult> DisperseAll(GoalDispersalRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _goalDispersalService.ExecuteMonthStartDispersal(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("personnel/CustomWeightedDispersal")]
|
||||
public async Task<IActionResult> CustomWeightedDispersal([FromBody] CustomWeightedDispersalRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _goalDispersalService.CustomWeightedDispersal(request);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}.");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.HostedServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers
|
||||
{
|
||||
public class HostedServicesController : ControllerBase
|
||||
{
|
||||
private readonly IApplicationDbIntegrityHostedService _applicationDbIntegrityHostedServiceStarter;
|
||||
|
||||
public HostedServicesController(IApplicationDbIntegrityHostedService applicationDbIntegrityHostedServiceStarter)
|
||||
{
|
||||
_applicationDbIntegrityHostedServiceStarter = applicationDbIntegrityHostedServiceStarter;
|
||||
}
|
||||
|
||||
[HttpPost("StartApplicationDbIntegrity", Name = "StartApplicationDbIntegrity")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> StartApplicationDbIntegrity()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _applicationDbIntegrityHostedServiceStarter.StartAsync();
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("StopApplicationDbIntegrity", Name = "StopApplicationDbIntegrity")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> StopApplicationDbIntegrity()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _applicationDbIntegrityHostedServiceStarter.StopAsync();
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Payout;
|
||||
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.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
public class PayoutController : ControllerBase
|
||||
{
|
||||
private readonly IPayoutService _payoutService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IActivityService _activityService;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public PayoutController(IPayoutService payoutService, IUserService userService, ICurrentUserService currentUser, IActivityService activityService)
|
||||
{
|
||||
_payoutService = payoutService;
|
||||
_userService = userService;
|
||||
_currentUser = currentUser;
|
||||
_activityService = activityService;
|
||||
}
|
||||
|
||||
[HttpGet("{employeeId}", Name = "GetEmployeePayout")]
|
||||
[RequirePermission("VIEW_DASHBOARD")]
|
||||
public async Task<IActionResult> GetEmployeePayout(string employeeId, [FromQuery] int year,
|
||||
[FromQuery] int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Now.Year;
|
||||
var searchMonth = month > 0 ? month : DateTime.Now.Month;
|
||||
|
||||
var employee = await _userService.GetUserByEmployeeIdAsync(employeeId);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result =
|
||||
await _payoutService.RetrieveCombinedDepartmentPayouts(employee, new MonthRange(searchYear, searchMonth));
|
||||
return Ok( result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("me", Name = "GetCurrentUserPayout")]
|
||||
[RequirePermission("VIEW_DASHBOARD")]
|
||||
public async Task<IActionResult> GetCurrentUserPayout( [FromQuery] int year, [FromQuery] int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Now.Year;
|
||||
var searchMonth = month > 0 ? month : DateTime.Now.Month;
|
||||
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var result =
|
||||
await _payoutService.CreateCombinedDepartmentPayouts(employee, new MonthRange(searchYear, searchMonth));
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("export", Name = "ExportMonthlyPayout")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public async Task<IActionResult> ExportMonthlyPayout([FromQuery] int year,
|
||||
[FromQuery] int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchYear = year > 0 ? year : DateTime.Today.Year;
|
||||
var searchMonth = month > 0 ? month : DateTime.Today.Month;
|
||||
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var period = new DateTime(searchYear, searchMonth, 1);
|
||||
var payouts = await _payoutService.RetrieveMonthlyIncentivePayouts(period);
|
||||
return Ok(payouts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("runMonthly", Name = "RunMonthlyPayout")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public async Task<IActionResult> RunMonthlyPayout([FromQuery] int monthsBack = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var request = new PayoutIncentiveRequest()
|
||||
{
|
||||
MonthsBack = monthsBack
|
||||
};
|
||||
|
||||
var payouts = await _payoutService.CreateMonthlyIncentivePayouts(request);
|
||||
|
||||
return Ok(payouts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("runAccounting", Name = "RunMonthlyAccounting")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public async Task<IActionResult> RunMonthlyAccounting([FromQuery] int monthsBack = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
period = period.AddMonths( -1 * monthsBack);
|
||||
var range = new MonthRange(period);
|
||||
var payouts = await _payoutService.CreateMonthlyAccountingPayouts(range);
|
||||
|
||||
return Ok(payouts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("getAccounting", Name = "GetMonthlyAccounting")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public async Task<IActionResult> GetMonthlyAccounting([FromQuery] DateTime period)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var range = new MonthRange(period);
|
||||
var payouts = await _payoutService.RetrieveMonthlyAccountingPayouts(range);
|
||||
|
||||
return Ok(payouts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("runMonthlySingle", Name = "RunMonthlyPayoutSingle")]
|
||||
[RequirePermission("GENERATE_PAYOUT_FILES")]
|
||||
public async Task<IActionResult> RunMonthlyPayoutSingle([FromQuery] string employeeId, [FromQuery] int monthsBack = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByEmployeeIdAsync(employeeId);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
period = period.AddMonths( -1 * monthsBack);
|
||||
var range = new MonthRange(period);
|
||||
var payouts = await _payoutService.CreateCombinedDepartmentPayouts(employee, range);
|
||||
|
||||
return Ok(payouts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+393
@@ -0,0 +1,393 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.FeatureManagement.Mvc;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Allied;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Action;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Action;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Allied;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using System.Threading;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ProcessingController : Controller
|
||||
{
|
||||
private readonly IActionCreditCardImportService _actionCreditCardImportService;
|
||||
private readonly IActionVehicleImportService _actionVehicleImportService;
|
||||
private readonly IAlliedGapMbpTransactionImportService _alliedTransactionImportService;
|
||||
private readonly IApplicationDbIntegrityService _applicationDbIntegrityService;
|
||||
private readonly IDnaActivitySyncService _dnaActivitySyncService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
private readonly IGapInsuranceActivityService _gapInsuranceActivityService;
|
||||
private readonly IQueueIncentiveProcessesService _queueIncentiveProcessService;
|
||||
private readonly IQueueNightlyIncentiveProcessesService _queueNightlyIncentiveProcessService;
|
||||
private readonly IQueueReportingService _queueReportingService;
|
||||
private readonly IQueuePayoutIncentiveService _queuePayoutIncentiveService;
|
||||
private readonly IQueueGoalDispersalService _queueGoalDispersalService;
|
||||
private readonly IQueueDayforceSyncService _queueDayforceSyncService;
|
||||
|
||||
public ProcessingController(
|
||||
IActionCreditCardImportService actionCreditCardImportService,
|
||||
IActionVehicleImportService actionVehicleImportService,
|
||||
IAlliedGapMbpTransactionImportService alliedTransactionImportService,
|
||||
IApplicationDbIntegrityService applicationDbIntegrityService,
|
||||
ICurrentUserService currentUserService,
|
||||
IDnaActivitySyncService dnaActivitySyncService,
|
||||
IUserService userService,
|
||||
IGapInsuranceActivityService gapInsuranceActivityService,
|
||||
IQueueIncentiveProcessesService queueIncentiveProcessService,
|
||||
IQueueNightlyIncentiveProcessesService queueNightlyIncentiveProcessService,
|
||||
IQueueReportingService queueReportingService, IQueuePayoutIncentiveService queuePayoutIncentiveService,
|
||||
IQueueGoalDispersalService queueGoalDispersalService, IQueueDayforceSyncService queueDayforceSyncService
|
||||
)
|
||||
{
|
||||
_actionCreditCardImportService = actionCreditCardImportService;
|
||||
_actionVehicleImportService = actionVehicleImportService;
|
||||
_alliedTransactionImportService = alliedTransactionImportService;
|
||||
_applicationDbIntegrityService = applicationDbIntegrityService;
|
||||
_currentUser = currentUserService;
|
||||
_dnaActivitySyncService = dnaActivitySyncService;
|
||||
_userService = userService;
|
||||
_gapInsuranceActivityService = gapInsuranceActivityService;
|
||||
_queueIncentiveProcessService = queueIncentiveProcessService;
|
||||
_queueNightlyIncentiveProcessService = queueNightlyIncentiveProcessService;
|
||||
_queueReportingService = queueReportingService;
|
||||
_queuePayoutIncentiveService = queuePayoutIncentiveService;
|
||||
_queueGoalDispersalService = queueGoalDispersalService;
|
||||
_queueDayforceSyncService = queueDayforceSyncService;
|
||||
}
|
||||
|
||||
[HttpPost("QueueIncentiveProcess")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueIncentiveProcess([FromBody] IncentiveProcessRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueIncentiveProcessService.QueueIncentiveProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Incentive Process Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueNightlyIncentiveProcess")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueNightlyIncentiveProcess([FromBody] NightlyIncentiveProcessRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueNightlyIncentiveProcessService.QueueNightlyIncentiveProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Nightly Incentive Process Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueuePayoutProcess")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueuePayoutProcess([FromBody] PayoutIncentiveRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queuePayoutIncentiveService.QueuePayoutIncentiveProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueReportingRequest")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueReportingRequest([FromBody] ReportingRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueReportingService.QueueReportingProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueGoalDispersalSyncProcess")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueGoalDispersalSyncProcess([FromBody] GoalDispersalRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueGoalDispersalService.QueueGoalDispersalProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information("Queue Goal Dispersal Process has failed");
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueDayforceSyncProcess")]
|
||||
[ProducesResponseType(202)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> QueueDayforceSyncProcess([FromBody] DayforceProcessRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueDayforceSyncService.QueueDayforceSyncProcess(request);
|
||||
return Accepted();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information("DayForce forced Sync has failed");
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunAlliedImport")]
|
||||
[Obsolete("Replaced with ActivityImport process, please use endpoint ActivityImport/QueueAlliedGapMbpRequest Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunAlliedImport([FromBody] AlliedGapMbpRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
Log.Information("No AppUser found");
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Log.Information($"Importing transactions from Allied, kicked off manually");
|
||||
var imported = await _alliedTransactionImportService.ImportTransactions<AlliedSaleRow>(request);
|
||||
Log.Information($"Imported {imported.Count} transactions from Allied");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunCreditCardImport")]
|
||||
[Obsolete("Replaced with ActivityImport process, please use endpoint ActivityImport/QueueActionCreditCardRequest Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunCreditCardImport(ActionCreditCardRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Log.Information($"Importing credit cards, kicked off manually");
|
||||
var imported = await _actionCreditCardImportService.ImportTransactions<ActionCreditCardPersonalRow>("personal", request);
|
||||
Log.Information($"Imported {imported.Count} credit cards - personal");
|
||||
imported = await _actionCreditCardImportService.ImportTransactions<ActionCreditCardBusinessRow>("business", request);
|
||||
Log.Information($"Imported {imported.Count} credit cards - business");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunVehicleImport")]
|
||||
[Obsolete("Replaced with ActivityImport process, please use endpoint ActivityImport/QueueActionVehicleRequest Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunVehicleImport([FromBody] ActionVehicleRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Log.Information($"Importing vehicles, kicked off manually");
|
||||
var imported = await _actionVehicleImportService.ImportTransactions<ActionSaleRow>(request);
|
||||
Log.Information($"Imported {imported.Count} vehicles");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunDnaSyncQuery")]
|
||||
[Obsolete("Replaced with Incentive Processes, please use QueueIncentiveProcesses. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunDnaSyncQuery()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Log.Information("DNA Sync was forced");
|
||||
await _dnaActivitySyncService.SyncLatestActivitiesFromDna();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("MatchOrRemoveGapAccessories")]
|
||||
[Obsolete("Moved to Nightly Processes Controller. Please use QueueNightlyIncentiveProcesses. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> MatchOrRemoveGapAccessories(
|
||||
[FromQuery] int fromMonth,
|
||||
[FromQuery] int fromYear,
|
||||
[FromQuery] int toMonth,
|
||||
[FromQuery] int toYear
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var monthRange = new MonthRange(fromYear, fromMonth, toYear, toMonth);
|
||||
Log.Information("MatchOrRemoveGapAccessories was forced");
|
||||
var updatedCount = await _gapInsuranceActivityService.MatchOrRemoveGapAccessories(monthRange);
|
||||
Log.Information($"MatchOrRemoveGapAccessories updated {updatedCount} records");
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("RunAppUserIdIntegrityMaintenance")]
|
||||
[Obsolete("Moved to Nightly Processes Controller. Please use QueueNightlyIncentiveProcesses. Date: 1/1/2025")]
|
||||
public async Task<IActionResult> RunAppUserIdIntegrityMaintenance()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUser = _currentUser.GetCurrentUser();
|
||||
|
||||
if (appUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found");
|
||||
}
|
||||
|
||||
var employee = await _userService.GetUserByAdEmailAsync(appUser.Email);
|
||||
if (employee == null)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Log.Information("AppUserId Integrity Maintenance was forced");
|
||||
var token = new CancellationToken();
|
||||
await _applicationDbIntegrityService.AppUserIdIntegrityMaintenanceSucceeded(token);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
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.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[Route("api/[controller]")]
|
||||
public class SettingsController : ControllerBase
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IDateTime _dateTimeService;
|
||||
private readonly IDepartmentService _departmentService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public SettingsController(
|
||||
ICurrentUserService currentUserService,
|
||||
IDateTime dateTimeService,
|
||||
IDepartmentService departmentService,
|
||||
ISettingsService settingsService,
|
||||
IUserService userService
|
||||
)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_dateTimeService = dateTimeService;
|
||||
_departmentService = departmentService;
|
||||
_settingsService = settingsService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = new Settings();
|
||||
settings.Departments = await _departmentService.GetAllDepartmentsAsync();
|
||||
settings.Employees = await _userService.GetAllUserSummariesAsync();
|
||||
settings.NextBonusPeriod = _dateTimeService.getNextBonusPeriod(DateTime.Today);
|
||||
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email != null && currentUser.UserType() != UserType.System)
|
||||
{
|
||||
var appUser = await _userService.GetUserByAdEmailAsync(currentUser.Email);
|
||||
settings.AuthorizedReports = await _settingsService.GetAuthorizedReportSettings(appUser);
|
||||
|
||||
Log.Debug($"Returning Settings For AppUser:{appUser.FullName}");
|
||||
|
||||
return Ok(settings);
|
||||
}
|
||||
|
||||
Log.Warning("No Authorized AppUser Found, Returning Base Settings");
|
||||
return Ok(settings);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int)System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetAllRoleMappings", Name = "GetAllRoleMappings")]
|
||||
public async Task<IActionResult> GetAllRoleMappings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _settingsService.GetRoleMappingsAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("UpdateRoleMapping", Name = "UpdateRoleMapping")]
|
||||
public async Task<IActionResult> UpdateRoleMapping([FromBody] RoleMappingUpdateRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
await _settingsService.SaveRoleMappingAsync(request);
|
||||
return (Ok());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetAuthorizedReportSettings", Name = "GetAuthorizedReportSettings")]
|
||||
public async Task<IActionResult> GetAuthorizedReports()
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
if (currentUser?.Email == null)
|
||||
{
|
||||
return Unauthorized("No AD User Found.");
|
||||
}
|
||||
|
||||
var appUser = await _userService.GetUserByAdEmailAsync(currentUser.Email);
|
||||
|
||||
var result = await _settingsService.GetAuthorizedReportSettings(appUser);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.Status.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class StatusController : ControllerBase
|
||||
{
|
||||
private readonly IApiHealthCheckService _apiHealthCheckService;
|
||||
private readonly IDateTime _dateTime;
|
||||
|
||||
public StatusController(IApiHealthCheckService apiHealthCheckService, IDateTime dateTime)
|
||||
{
|
||||
_apiHealthCheckService = apiHealthCheckService;
|
||||
_dateTime = dateTime;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_apiHealthCheckService.CheckApiHealthAndBuildEnvironmentView());
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("LocalTime")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult GetLocalTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_dateTime.Now);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("UtcTime")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult GetUTCTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_dateTime.UTCNow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("WindowsCstTime")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult GetWindowsCSTTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_dateTime.CSTWindowsNow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("LinuxCstTime")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult GetLinuxCSTTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_dateTime.CSTLinuxNow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("ConvertCSTToUTCWindows/{dateTimeString}")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult ConvertCSTToUTCWindows(string dateTimeString)
|
||||
{
|
||||
try
|
||||
{
|
||||
var convertedTime = _dateTime.ConvertDateTimeFromCSTToUTCWindows(dateTimeString);
|
||||
return Ok(convertedTime);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("ConvertCSTToUTCLinux/{dateTimeString}")]
|
||||
[ProducesResponseType(200)]
|
||||
public IActionResult ConvertCSTToUTCLinux(string dateTimeString)
|
||||
{
|
||||
try
|
||||
{
|
||||
var convertedTime = _dateTime.ConvertDateTimeFromCSTToUTCLinux(dateTimeString);
|
||||
return Ok(convertedTime);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name}");
|
||||
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user