From 3e78e2e2cf6bb8aa4b902a4f49aa795b937a8d8a Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 20 Apr 2026 16:38:29 +0200 Subject: [PATCH] Move catalog title update validation to handler Validation preventing CatTitle changes during updates is now enforced in UpdateCatalogHandler instead of the controller. The handler throws an exception if a title change is attempted. Also, streamlined UpdateProcedure handling and removed redundant CatTitle mapping logic. --- DbFirst.API/Controllers/CatalogsController.cs | 11 ----------- .../Catalogs/Commands/UpdateCatalogHandler.cs | 12 +++++++----- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/DbFirst.API/Controllers/CatalogsController.cs b/DbFirst.API/Controllers/CatalogsController.cs index 254b39d..92518b8 100644 --- a/DbFirst.API/Controllers/CatalogsController.cs +++ b/DbFirst.API/Controllers/CatalogsController.cs @@ -50,17 +50,6 @@ public class CatalogsController : ControllerBase [HttpPut("{id:int}")] public async Task> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken) { - var current = await _mediator.Send(new GetCatalogByIdQuery(id), cancellationToken); - if (current == null) - { - return NotFound(); - } - if (dto.UpdateProcedure == CatalogUpdateProcedure.Update && - !string.Equals(current.CatTitle, dto.CatTitle, StringComparison.OrdinalIgnoreCase)) - { - return BadRequest("Titel kann nicht geändert werden."); - } - var updated = await _mediator.Send(new UpdateCatalogCommand(id, dto), cancellationToken); if (updated == null) { diff --git a/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs b/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs index 9e25ef5..193cd1a 100644 --- a/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs +++ b/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs @@ -25,18 +25,20 @@ public class UpdateCatalogHandler : IRequestHandler(request.Dto); entity.Guid = request.Id; - entity.CatTitle = request.Dto.UpdateProcedure == CatalogUpdateProcedure.Update - ? existing.CatTitle - : request.Dto.CatTitle; entity.AddedWho = existing.AddedWho; entity.AddedWhen = existing.AddedWhen; entity.ChangedWho = "system"; entity.ChangedWhen = DateTime.UtcNow; - var procedure = request.Dto.UpdateProcedure; - var updated = await _repository.UpdateAsync(request.Id, entity, procedure, cancellationToken); + var updated = await _repository.UpdateAsync(request.Id, entity, request.Dto.UpdateProcedure, cancellationToken); return updated == null ? null : _mapper.Map(updated); } }