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

@@ -1,56 +1,55 @@
using EnvelopeGenerator.CommonServices;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Web.Services;
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]")]
public class TestViewController : BaseController
private readonly EnvelopeOldService envelopeOldService;
private readonly IConfiguration _config;
public TestViewController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<TestViewController> logger, IConfiguration configuration) : base(databaseService, logger)
{
private readonly EnvelopeOldService envelopeOldService;
private readonly IConfiguration _config;
this.envelopeOldService = envelopeOldService;
_config = configuration;
}
public TestViewController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<TestViewController> logger, IConfiguration configuration) : base(databaseService, logger)
{
this.envelopeOldService = envelopeOldService;
_config = configuration;
}
[HttpGet]
public IActionResult Index()
{
return View("AnnotationIndex");
}
[HttpGet]
public IActionResult Index()
[HttpPost]
public IActionResult DebugEnvelopes([FromForm] string? password)
{
try
{
return View("AnnotationIndex");
}
var passwordFromConfig = _config["AdminPassword"];
[HttpPost]
public IActionResult DebugEnvelopes([FromForm] string? password)
{
try
if (passwordFromConfig == null)
{
var passwordFromConfig = _config["AdminPassword"];
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!";
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");
}
}
}