Refactor Catalog update/upsert endpoints and service logic
- Update endpoint now returns CatalogReadDto or NotFound - Replace UpdateWithStoredProcedure with Upsert endpoint (PUT /upsert) - Rename AddAsync to InsertAsync; UpdateAsync returns DTO or null - Introduce UpsertAsync for combined insert/update logic - Remove stored procedure-specific update/delete methods - Use DTOs consistently in controller/service responses - Repository methods now return entities instead of booleans
This commit is contained in:
@@ -40,20 +40,9 @@ public class CatalogsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("{id:int}")]
|
||||
public async Task<IActionResult> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult<CatalogReadDto>> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var updated = await _service.UpdateAsync(id, dto, cancellationToken);
|
||||
if (!updated)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("sp/{id:int}")]
|
||||
public async Task<ActionResult<CatalogReadDto>> UpdateWithStoredProcedure(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var updated = await _service.UpdateWithStoredProcedureAsync(id, dto, cancellationToken);
|
||||
if (updated == null)
|
||||
{
|
||||
return NotFound();
|
||||
@@ -61,6 +50,17 @@ 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)
|
||||
{
|
||||
@@ -71,15 +71,4 @@ public class CatalogsController : ControllerBase
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("sp/{id:int}")]
|
||||
public async Task<IActionResult> DeleteWithStoredProcedure(int id, CancellationToken cancellationToken)
|
||||
{
|
||||
var deleted = await _service.DeleteWithStoredProcedureAsync(id, cancellationToken);
|
||||
if (!deleted)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user