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:
@@ -50,17 +50,6 @@ public class CatalogsController : ControllerBase
|
|||||||
return Ok(updated);
|
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}")]
|
[HttpDelete("{id:int}")]
|
||||||
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
|
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,21 +58,6 @@ public class CatalogService : ICatalogService
|
|||||||
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
|
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)
|
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return await _repository.DeleteAsync(id, cancellationToken);
|
return await _repository.DeleteAsync(id, cancellationToken);
|
||||||
|
|||||||
@@ -6,6 +6,5 @@ public interface ICatalogService
|
|||||||
Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||||
Task<CatalogReadDto> CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default);
|
Task<CatalogReadDto> CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default);
|
||||||
Task<CatalogReadDto?> UpdateAsync(int id, 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);
|
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,5 @@ public interface ICatalogRepository
|
|||||||
Task<VwmyCatalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
Task<VwmyCatalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||||
Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default);
|
Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default);
|
||||||
Task<VwmyCatalog?> UpdateAsync(int id, 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);
|
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,14 +27,9 @@ public class CatalogRepository : ICatalogRepository
|
|||||||
|
|
||||||
public async Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default)
|
public async Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
catalog.Guid = 0;
|
// Platzhalter: Insert-Prozedur folgt.
|
||||||
var created = await ExecuteUpsertAsync(catalog, cancellationToken);
|
// TODO: Replace with dedicated insert stored procedure invocation.
|
||||||
if (created == null)
|
throw new NotImplementedException("Insert stored procedure not implemented yet.");
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Failed to insert catalog via stored procedure.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default)
|
public async Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default)
|
||||||
@@ -46,33 +41,7 @@ public class CatalogRepository : ICatalogRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
catalog.Guid = id;
|
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)
|
var guidParam = new SqlParameter("@GUID", SqlDbType.Int)
|
||||||
{
|
{
|
||||||
Direction = ParameterDirection.InputOutput,
|
Direction = ParameterDirection.InputOutput,
|
||||||
@@ -96,4 +65,21 @@ public class CatalogRepository : ICatalogRepository
|
|||||||
var guid = (int)guidParam.Value;
|
var guid = (int)guidParam.Value;
|
||||||
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user