Latest
This commit is contained in:
43
Prefab.Catalog.Api/Controllers/ProductsController.cs
Normal file
43
Prefab.Catalog.Api/Controllers/ProductsController.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Prefab.Catalog.Domain.Exceptions;
|
||||
using Prefab.Endpoints;
|
||||
using Prefab.Shared;
|
||||
using Prefab.Shared.Catalog.Products;
|
||||
|
||||
namespace Prefab.Catalog.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("catalog/products")]
|
||||
public sealed class ProductsController : ControllerBase
|
||||
{
|
||||
[HttpGet("{slug}/config")]
|
||||
[ProducesResponseType(typeof(GetProductDetail.Response), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetProductConfig(
|
||||
[FromRoute] string slug,
|
||||
[FromServices] IProductClient productClient,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await productClient.GetProductDetail(slug, cancellationToken);
|
||||
return Ok(response);
|
||||
}
|
||||
catch (CatalogNotFoundException ex)
|
||||
{
|
||||
return NotFound(ApiProblemDetails.NotFound(ex.Resource, ex.Identifier, ex.Message));
|
||||
}
|
||||
catch (RemoteProblemException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
catch (ArgumentException argumentException)
|
||||
{
|
||||
return ValidationProblem(
|
||||
title: "Invalid product slug.",
|
||||
detail: argumentException.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user