Files
CutList/CutList.Web/Controllers/CatalogController.cs
AJ Isaacs 5000021193 feat: Add catalog import/export API endpoints
Replace the standalone ExportData console app and hardcoded SeedController
with generic GET /api/catalog/export and POST /api/catalog/import endpoints.
Import uses upsert semantics with per-item error handling, preserving
existing inventory quantities.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 00:09:53 -05:00

42 lines
1.1 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using CutList.Web.DTOs;
using CutList.Web.Services;
using Microsoft.AspNetCore.Mvc;
namespace CutList.Web.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CatalogController : ControllerBase
{
private readonly CatalogService _catalogService;
public CatalogController(CatalogService catalogService)
{
_catalogService = catalogService;
}
[HttpGet("export")]
public async Task<IActionResult> Export()
{
var data = await _catalogService.ExportAsync();
var options = new JsonSerializerOptions
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
return new JsonResult(data, options);
}
[HttpPost("import")]
public async Task<ActionResult<ImportResultDto>> Import([FromBody] CatalogData data)
{
var result = await _catalogService.ImportAsync(data);
return Ok(result);
}
}