Add SP-based update/delete for Catalogs, new endpoints

Added support for updating and deleting Catalog records via SQL Server stored procedures. Introduced PUT /catalogs/sp and DELETE /catalogs/sp/{id} endpoints in CatalogsController. Extended service and repository interfaces and implementations to handle stored procedure operations. Added Microsoft.Data.SqlClient package for direct SQL execution. Repository checks for record existence before SP calls to prevent unintended behavior.
This commit is contained in:
OlgunR
2026-01-12 12:58:41 +01:00
parent d312230803
commit eabf60923d
6 changed files with 87 additions and 0 deletions

View File

@@ -40,8 +40,20 @@ public class CatalogService : ICatalogService
return await _repository.UpdateAsync(id, domainItem, cancellationToken);
}
public async Task<CatalogDto?> UpdateWithStoredProcedureAsync(CatalogDto dto, CancellationToken cancellationToken = default)
{
var domainItem = _mapper.Map<Catalog>(dto);
var updated = await _repository.UpdateWithStoredProcedureAsync(domainItem, cancellationToken);
return updated == null ? null : _mapper.Map<CatalogDto>(updated);
}
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
{
return await _repository.DeleteAsync(id, cancellationToken);
}
public async Task<bool> DeleteWithStoredProcedureAsync(int id, CancellationToken cancellationToken = default)
{
return await _repository.DeleteWithStoredProcedureAsync(id, cancellationToken);
}
}

View File

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