Files
DbFirst/DbFirst.API/Controllers/CatalogsController.cs
OlgunR 14e1cbc3b6 Refactor DTOs, add Blazor WASM frontend, enable CORS
- Split `CatalogDto` into `CatalogReadDto` and `CatalogWriteDto` for clear separation of read/write operations in both backend and frontend.
- Updated API controllers, services, and AutoMapper profiles to use new DTOs; ensured audit fields are set in service layer.
- Enabled CORS in the API project to support Blazor WASM frontend.
- Added new Blazor WebAssembly project (`DbFirst.BlazorWasm`) with catalog management UI, API client, Bootstrap v5.1.0 styling, and configuration-driven API base URL.
- Included `bootstrap.min.css` and its source map for frontend styling and easier debugging.
- Updated solution file to include new project and support multiple build configurations.
- Result: improved API design, clean DTO separation, and a modern interactive frontend for catalog management.
2026-01-13 10:15:01 +01:00

86 lines
2.5 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<IActionResult> 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();
}
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();
}
[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();
}
}