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.
This commit is contained in:
OlgunR
2026-01-15 16:57:33 +01:00
parent a849a88fa3
commit facc376f74
5 changed files with 20 additions and 62 deletions

View File

@@ -50,17 +50,6 @@ public class CatalogsController : ControllerBase
return Ok(updated);
}
[HttpPut("upsert")]
public async Task<ActionResult<CatalogReadDto>> 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<IActionResult> Delete(int id, CancellationToken cancellationToken)
{

View File

@@ -58,21 +58,6 @@ public class CatalogService : ICatalogService
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
}
public async Task<CatalogReadDto?> UpsertAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default)
{
var entity = _mapper.Map<VwmyCatalog>(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<CatalogReadDto>(upserted);
}
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
{
return await _repository.DeleteAsync(id, cancellationToken);

View File

@@ -6,6 +6,5 @@ public interface ICatalogService
Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<CatalogReadDto> CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<CatalogReadDto?> UpdateAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<CatalogReadDto?> UpsertAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
}

View File

@@ -8,6 +8,5 @@ public interface ICatalogRepository
Task<VwmyCatalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default);
Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default);
Task<VwmyCatalog?> UpsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
}

View File

@@ -27,14 +27,9 @@ public class CatalogRepository : ICatalogRepository
public async Task<VwmyCatalog> 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<VwmyCatalog?> 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<VwmyCatalog?> UpsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default)
{
return await ExecuteUpsertAsync(catalog, cancellationToken);
}
public async Task<bool> 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<VwmyCatalog?> 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<bool> 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;
}
}