namespace AAIntegration.SimmonsBank.API.Controllers; using AutoMapper; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using AAIntegration.SimmonsBank.API.Models.Autoclass; using AAIntegration.SimmonsBank.API.Services; using AAIntegration.SimmonsBank.API.Config; using System.Collections.Generic; using AAIntegration.SimmonsBank.API.Entities; using Microsoft.AspNetCore.Authorization; [Authorize] [ApiController] [Route("[controller]")] public class AutoclassController : ControllerBase { private IAutoclassService _autoclassService; private IMapper _mapper; private readonly AppSettings _appSettings; public AutoclassController( IAutoclassService autoclassService, IMapper mapper, IOptions appSettings) { _autoclassService = autoclassService; _mapper = mapper; _appSettings = appSettings.Value; } [HttpGet] public IActionResult GetAll(int? account = null) { List autoclassDtos = new List(); foreach (AutoclassRule auto in _autoclassService.GetAll(account)) autoclassDtos.Add(_mapper.Map(auto)); return Ok(autoclassDtos); } [HttpGet("{id}")] public IActionResult GetById(int id) { AutoclassRule auto = _autoclassService.GetById(id); return Ok(_mapper.Map(auto)); } [HttpPost] public IActionResult Create([FromBody]AutoclassRuleCreateRequest model) { _autoclassService.Create(model); return Ok(new { message = "AutoclassRule created" }); } [HttpPut("{id}")] public IActionResult Update(int id, [FromBody]AutoclassRuleUpdateRequest model) { _autoclassService.Update(id, model); return Ok(new { message = "AutoclassRule updated" }); } [HttpDelete("{id}")] public IActionResult Delete(int id) { _autoclassService.Delete(id); return Ok(new { message = "AutoclassRule deleted" }); } /*[HttpGet("RefreshBalance/{id}")] public IActionResult RefreshBalance(int id) { Account account = _accountService.RefreshAccountBalance(id); return Ok(_mapper.Map(account)); }*/ // [HttpGet("RefreshBalance/{id}")] [HttpGet("TypeOperatorInfo")] public IActionResult GetAllTypeOperatorInfo() { return Ok(_autoclassService.GetAllTypeOperatorInfo()); } [HttpGet("FieldInfo")] public IActionResult GetAllFieldInfo() { return Ok(_autoclassService.GetAllFieldInfo()); } [HttpGet("TriggerAutoclassRule/{id}")] public IActionResult TriggerAutoclassRule(int id) { int affectedTransactions = _autoclassService.ApplyAutoclassRule(id); return Ok(new { message = $"AutoclassRule triggered and updated {affectedTransactions} transaction(s)." }); } [HttpGet("TriggerTransactionRules/{id}")] public IActionResult TriggerAutoclassRulesForTransaction(int id) { int triggeredRules = _autoclassService.ApplyRulesForTransaction(id); return Ok(new { message = $"Transaction triggered {triggeredRules} autoclass rule(s)." }); } }