89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.FeatureManagement.Mvc;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
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);
|
|
}
|
|
}
|
|
}
|