From facc376f74c24aa00d1171e07fad57fd6c029aa7 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Thu, 15 Jan 2026 16:57:33 +0100 Subject: [PATCH] Remove Upsert functionality from Catalog API Removed Upsert endpoint and related service/repository methods. Deleted ExecuteUpsertAsync helper. Insert now throws NotImplementedException as a placeholder. Refactored Delete method in repository; logic unchanged. --- DbFirst.API/Controllers/CatalogsController.cs | 11 ---- .../Catalogs/CatalogService.cs | 15 ------ .../Catalogs/ICatalogService.cs | 1 - .../Repositories/ICatalogRepository.cs | 1 - .../Repositories/CatalogRepository.cs | 54 +++++++------------ 5 files changed, 20 insertions(+), 62 deletions(-) diff --git a/DbFirst.API/Controllers/CatalogsController.cs b/DbFirst.API/Controllers/CatalogsController.cs index 5824671..1aaf1e0 100644 --- a/DbFirst.API/Controllers/CatalogsController.cs +++ b/DbFirst.API/Controllers/CatalogsController.cs @@ -50,17 +50,6 @@ public class CatalogsController : ControllerBase return Ok(updated); } - [HttpPut("upsert")] - public async Task> Upsert(CatalogWriteDto dto, CancellationToken cancellationToken) - { - var result = await _service.UpsertAsync(dto, cancellationToken); - if (result == null) - { - return BadRequest(); - } - return Ok(result); - } - [HttpDelete("{id:int}")] public async Task Delete(int id, CancellationToken cancellationToken) { diff --git a/DbFirst.Application/Catalogs/CatalogService.cs b/DbFirst.Application/Catalogs/CatalogService.cs index ff4f7eb..c2263da 100644 --- a/DbFirst.Application/Catalogs/CatalogService.cs +++ b/DbFirst.Application/Catalogs/CatalogService.cs @@ -58,21 +58,6 @@ public class CatalogService : ICatalogService return updated == null ? null : _mapper.Map(updated); } - public async Task UpsertAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default) - { - var entity = _mapper.Map(dto); - if (entity.Guid == 0) - { - entity.AddedWho = "system"; - entity.AddedWhen = DateTime.UtcNow; - } - entity.ChangedWho = "system"; - entity.ChangedWhen = DateTime.UtcNow; - - var upserted = await _repository.UpsertAsync(entity, cancellationToken); - return upserted == null ? null : _mapper.Map(upserted); - } - public async Task DeleteAsync(int id, CancellationToken cancellationToken = default) { return await _repository.DeleteAsync(id, cancellationToken); diff --git a/DbFirst.Application/Catalogs/ICatalogService.cs b/DbFirst.Application/Catalogs/ICatalogService.cs index 99e16b2..f7bc50f 100644 --- a/DbFirst.Application/Catalogs/ICatalogService.cs +++ b/DbFirst.Application/Catalogs/ICatalogService.cs @@ -6,6 +6,5 @@ public interface ICatalogService Task GetByIdAsync(int id, CancellationToken cancellationToken = default); Task CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default); Task UpdateAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default); - Task UpsertAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default); Task DeleteAsync(int id, CancellationToken cancellationToken = default); } diff --git a/DbFirst.Domain/Repositories/ICatalogRepository.cs b/DbFirst.Domain/Repositories/ICatalogRepository.cs index e098979..7821577 100644 --- a/DbFirst.Domain/Repositories/ICatalogRepository.cs +++ b/DbFirst.Domain/Repositories/ICatalogRepository.cs @@ -8,6 +8,5 @@ public interface ICatalogRepository Task GetByIdAsync(int id, CancellationToken cancellationToken = default); Task InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default); Task UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default); - Task UpsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default); Task DeleteAsync(int id, CancellationToken cancellationToken = default); } diff --git a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs index d84d727..449b446 100644 --- a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs +++ b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs @@ -27,14 +27,9 @@ public class CatalogRepository : ICatalogRepository public async Task InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default) { - catalog.Guid = 0; - var created = await ExecuteUpsertAsync(catalog, cancellationToken); - if (created == null) - { - throw new InvalidOperationException("Failed to insert catalog via stored procedure."); - } - - return created; + // Platzhalter: Insert-Prozedur folgt. + // TODO: Replace with dedicated insert stored procedure invocation. + throw new NotImplementedException("Insert stored procedure not implemented yet."); } public async Task UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default) @@ -46,33 +41,7 @@ public class CatalogRepository : ICatalogRepository } catalog.Guid = id; - return await ExecuteUpsertAsync(catalog, cancellationToken); - } - - public async Task UpsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default) - { - return await ExecuteUpsertAsync(catalog, cancellationToken); - } - - public async Task DeleteAsync(int id, CancellationToken cancellationToken = default) - { - var exists = await _db.VwmyCatalogs.AsNoTracking().AnyAsync(x => x.Guid == id, cancellationToken); - if (!exists) - { - return false; - } - - var guidParam = new SqlParameter("@GUID", id); - await _db.Database.ExecuteSqlRawAsync( - "EXEC dbo.PRTBMY_CATALOG_DELETE @GUID", - parameters: new[] { guidParam }, - cancellationToken: cancellationToken); - return true; - } - - private async Task ExecuteUpsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken) - { var guidParam = new SqlParameter("@GUID", SqlDbType.Int) { Direction = ParameterDirection.InputOutput, @@ -96,4 +65,21 @@ public class CatalogRepository : ICatalogRepository var guid = (int)guidParam.Value; return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken); } + + public async Task DeleteAsync(int id, CancellationToken cancellationToken = default) + { + var exists = await _db.VwmyCatalogs.AsNoTracking().AnyAsync(x => x.Guid == id, cancellationToken); + if (!exists) + { + return false; + } + + var guidParam = new SqlParameter("@GUID", id); + await _db.Database.ExecuteSqlRawAsync( + "EXEC dbo.PRTBMY_CATALOG_DELETE @GUID", + parameters: new[] { guidParam }, + cancellationToken: cancellationToken); + + return true; + } }