Adding
This commit is contained in:
+141
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.Configuration;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Extensions;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.FeatureManagement.Mvc;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.API.Collections.RepoApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
public class RefundStatusController : RepoControllerBase
|
||||
{
|
||||
private IRefundStatusService _refundStatusService;
|
||||
|
||||
public RefundStatusController(
|
||||
IRefundStatusService refundStatusService,
|
||||
IHttpContextAccessor httpContextAccessor) :
|
||||
base(httpContextAccessor)
|
||||
{
|
||||
_refundStatusService = refundStatusService;
|
||||
}
|
||||
|
||||
// GET: api/RefundStatus
|
||||
[HttpGet(Name = "GetAllRefundStatus")]
|
||||
[ProducesResponseType(typeof(IEnumerable<RefundStatus>), 200)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _refundStatusService.ListAllAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/RefundStatus/5
|
||||
[HttpGet("{repoId}", Name = "GetRefundStatusById")]
|
||||
[ProducesResponseType(typeof(RefundStatus), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> GetById(int repoId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (repoId <= 0)
|
||||
{
|
||||
return BadRequest("Invalid RepoId");
|
||||
}
|
||||
|
||||
var refundStatus = await _refundStatusService.GetAsync(repoId);
|
||||
return Ok(refundStatus);
|
||||
}
|
||||
catch (NotFoundException nfe)
|
||||
{
|
||||
return NotFound(nfe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(RefundStatus), 200)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> Post([FromBody] RefundStatus refundStatus)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
if (refundStatus.RepoId <= 0)
|
||||
{
|
||||
return BadRequest("Invalid ID");
|
||||
}
|
||||
|
||||
var newRefundStatus = await _refundStatusService.SaveAsync(refundStatus);
|
||||
return Ok(newRefundStatus);
|
||||
}
|
||||
catch (NotFoundException nfe)
|
||||
{
|
||||
return NotFound(nfe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{repoId}")]
|
||||
[ProducesResponseType(typeof(RefundStatus), 200)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> Put(int repoId, [FromBody] RefundStatus refundStatus)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
if (repoId <= 0 || repoId != refundStatus.RepoId)
|
||||
{
|
||||
return BadRequest("Invalid ID");
|
||||
}
|
||||
|
||||
var newRefundStatus = await _refundStatusService.UpdateAsync(refundStatus);
|
||||
return Ok(newRefundStatus);
|
||||
}
|
||||
catch (NotFoundException nfe)
|
||||
{
|
||||
return NotFound(nfe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user