Files
DbFirst/DbFirst.API/Controllers/CatalogsController.cs
OlgunR facc376f74 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.
2026-01-15 16:57:33 +01:00

64 lines
1.8 KiB
C#

using DbFirst.Application.Catalogs;
using Microsoft.AspNetCore.Mvc;
namespace DbFirst.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CatalogsController : ControllerBase
{
private readonly ICatalogService _service;
public CatalogsController(ICatalogService service)
{
_service = service;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CatalogReadDto>>> GetAll(CancellationToken cancellationToken)
{
var result = await _service.GetAllAsync(cancellationToken);
return Ok(result);
}
[HttpGet("{id:int}")]
public async Task<ActionResult<CatalogReadDto>> GetById(int id, CancellationToken cancellationToken)
{
var result = await _service.GetByIdAsync(id, cancellationToken);
if (result == null)
{
return NotFound();
}
return Ok(result);
}
[HttpPost]
public async Task<ActionResult<CatalogReadDto>> Create(CatalogWriteDto dto, CancellationToken cancellationToken)
{
var created = await _service.CreateAsync(dto, cancellationToken);
return CreatedAtAction(nameof(GetById), new { id = created.Guid }, created);
}
[HttpPut("{id:int}")]
public async Task<ActionResult<CatalogReadDto>> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
{
var updated = await _service.UpdateAsync(id, dto, cancellationToken);
if (updated == null)
{
return NotFound();
}
return Ok(updated);
}
[HttpDelete("{id:int}")]
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
{
var deleted = await _service.DeleteAsync(id, cancellationToken);
if (!deleted)
{
return NotFound();
}
return NoContent();
}
}