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:
@@ -3,9 +3,11 @@ using EnvelopeGenerator.Application.Contracts.Services;
|
||||
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static EnvelopeGenerator.Domain.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers.Test;
|
||||
|
||||
[Obsolete("Use MediatR")]
|
||||
public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistoryService, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>
|
||||
{
|
||||
public TestEnvelopeHistoryController(ILogger<TestEnvelopeHistoryController> logger, IEnvelopeHistoryService service) : base(logger, service)
|
||||
@@ -13,7 +15,7 @@ public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistory
|
||||
}
|
||||
|
||||
[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));
|
||||
}
|
||||
@@ -25,7 +27,7 @@ public class TestEnvelopeHistoryController : CRUDControllerBase<IEnvelopeHistory
|
||||
}
|
||||
|
||||
[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));
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
@using EnvelopeGenerator.CommonServices;
|
||||
@using EnvelopeGenerator.Domain;
|
||||
@using EnvelopeGenerator.Domain.Entities;
|
||||
@using static EnvelopeGenerator.Domain.Constants;
|
||||
@{
|
||||
ViewData["Title"] = "Debug";
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user