Refactor controllers and update envelope status handling

- Updated `TestEnvelopeHistoryController` to use `EnvelopeStatus` for status parameters and marked it as obsolete.
- Modified `TestViewController` with new route attributes, simplified constructor, and improved error handling in HTTP methods.
- Cleaned up `DebugEnvelopes.cshtml` by removing unnecessary using directives and ensuring type safety in envelope grouping.
This commit is contained in:
2025-06-27 13:51:51 +02:00
parent fcbe956095
commit 6f73ba929c
3 changed files with 49 additions and 48 deletions

View File

@@ -3,9 +3,11 @@ using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory; using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static EnvelopeGenerator.Domain.Constants;
namespace EnvelopeGenerator.Web.Controllers.Test; namespace EnvelopeGenerator.Web.Controllers.Test;
[Obsolete("Use MediatR")]
public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistoryService, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long> public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistoryService, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>
{ {
public TestEnvelopeHistoryController(ILogger<TestEnvelopeHistoryController> logger, IEnvelopeHistoryService service) : base(logger, service) public TestEnvelopeHistoryController(ILogger<TestEnvelopeHistoryController> logger, IEnvelopeHistoryService service) : base(logger, service)
@@ -13,7 +15,7 @@ public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistory
} }
[HttpGet("Count")] [HttpGet("Count")]
public async Task<IActionResult> Count(int? envelopeId = null, string? userReference = null, int? status = null) public async Task<IActionResult> Count(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null)
{ {
return Ok(await _service.CountAsync(envelopeId, userReference, status)); return Ok(await _service.CountAsync(envelopeId, userReference, status));
} }
@@ -25,7 +27,7 @@ public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistory
} }
[HttpGet] [HttpGet]
public async Task<IActionResult> GetAsyncWith(int? envelopeId = null, string? userReference = null, int? status = null) public async Task<IActionResult> GetAsyncWith(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null)
{ {
return Ok(await _service.ReadAsync(envelopeId: envelopeId, userReference: userReference, status: status)); return Ok(await _service.ReadAsync(envelopeId: envelopeId, userReference: userReference, status: status));
} }

View File

@@ -1,56 +1,55 @@
using EnvelopeGenerator.CommonServices; using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Web.Services; using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Web.Controllers.Test namespace EnvelopeGenerator.Web.Controllers.Test;
[Route("api/test/[controller]")]
public class TestViewController : BaseController
{ {
[Route("api/test/[controller]")] private readonly EnvelopeOldService envelopeOldService;
public class TestViewController : BaseController private readonly IConfiguration _config;
public TestViewController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<TestViewController> logger, IConfiguration configuration) : base(databaseService, logger)
{ {
private readonly EnvelopeOldService envelopeOldService; this.envelopeOldService = envelopeOldService;
private readonly IConfiguration _config; _config = configuration;
}
public TestViewController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<TestViewController> logger, IConfiguration configuration) : base(databaseService, logger) [HttpGet]
{ public IActionResult Index()
this.envelopeOldService = envelopeOldService; {
_config = configuration; return View("AnnotationIndex");
} }
[HttpGet] [HttpPost]
public IActionResult Index() public IActionResult DebugEnvelopes([FromForm] string? password)
{
try
{ {
return View("AnnotationIndex"); var passwordFromConfig = _config["AdminPassword"];
}
[HttpPost] if (passwordFromConfig == null)
public IActionResult DebugEnvelopes([FromForm] string? password)
{
try
{ {
var passwordFromConfig = _config["AdminPassword"]; ViewData["error"] = "No admin password configured!";
if (passwordFromConfig == null)
{
ViewData["error"] = "No admin password configured!";
return View("AnnotationIndex");
}
if (password != passwordFromConfig)
{
ViewData["error"] = "Wrong Password!";
return View("AnnotationIndex");
}
List<Envelope> envelopes = envelopeOldService.LoadEnvelopes();
return View("DebugEnvelopes", envelopes);
}
catch(Exception ex)
{
_logger.LogError(ex, "Unexpected error");
ViewData["error"] = "Unknown error!";
return View("AnnotationIndex"); return View("AnnotationIndex");
} }
}
if (password != passwordFromConfig)
{
ViewData["error"] = "Wrong Password!";
return View("AnnotationIndex");
}
List<Envelope> envelopes = envelopeOldService.LoadEnvelopes();
return View("DebugEnvelopes", envelopes);
}
catch(Exception ex)
{
_logger.LogError(ex, "Unexpected error");
ViewData["error"] = "Unknown error!";
return View("AnnotationIndex");
}
} }
} }

View File

@@ -1,5 +1,5 @@
@using EnvelopeGenerator.CommonServices; @using EnvelopeGenerator.CommonServices;
@using EnvelopeGenerator.Domain; @using EnvelopeGenerator.Domain.Entities;
@using static EnvelopeGenerator.Domain.Constants; @using static EnvelopeGenerator.Domain.Constants;
@{ @{
ViewData["Title"] = "Debug"; ViewData["Title"] = "Debug";
@@ -12,9 +12,9 @@
return Helpers.EncodeEnvelopeReceiverId(envelope.Uuid, receiver.Signature); return Helpers.EncodeEnvelopeReceiverId(envelope.Uuid, receiver.Signature);
} }
IEnumerable<IGrouping<EnvelopeStatus, Envelope>> groupEnvelopes(List<Envelope> envelopes) IEnumerable<IGrouping<EnvelopeStatus, Envelope>> groupEnvelopes(List<Envelope> envelopes)
{ {
return envelopes.GroupBy(item => item.Status).OrderBy(item => (int)item.Key); return envelopes.GroupBy(item => (EnvelopeStatus) item.Status).OrderBy(item => item.Key);
} }
} }