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,12 +1,12 @@
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]")]
public class TestViewController : BaseController
{
private readonly EnvelopeOldService envelopeOldService; private readonly EnvelopeOldService envelopeOldService;
private readonly IConfiguration _config; private readonly IConfiguration _config;
@@ -52,5 +52,4 @@ namespace EnvelopeGenerator.Web.Controllers.Test
return View("AnnotationIndex"); 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";
@@ -14,7 +14,7 @@
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);
} }
} }