using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using LCU.API.Collections.RepoApi.Configuration; using LCU.API.Collections.RepoApi.HostedServices; 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 ProcessingReceiptController : RepoControllerBase { private readonly IProcessingReceiptService _receiptService; public ProcessingReceiptController(IProcessingReceiptService receiptService, IHttpContextAccessor httpContextAccessor): base(httpContextAccessor) { _receiptService = receiptService; } //GET: api/ProcessingReceipt/AccountNo/5 [HttpGet("AccountNo/{accountNo}")] [ProducesResponseType(typeof(ReadOnlyCollection),200)] [ProducesResponseType(typeof(string),400)] [ProducesResponseType(500)] public async Task GetByAccountNo(string accountNo) { try { if (string.IsNullOrWhiteSpace((accountNo))) { return BadRequest("Invalid ID"); } var results = await _receiptService.GetReceiptsByAccountNoAsync(accountNo); if (results.Any()) { return Ok(results); } return NotFound("No receipts found for for this account"); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } } }