Implement API endpoints for creating and retrieving product tables. This allows administrators to define product tables and retrieve them by name. The creation endpoint is secured and only accessible to administrators.
35 lines
No EOL
1.1 KiB
C#
35 lines
No EOL
1.1 KiB
C#
using DrinkRateAPI.ApiModels.ProductTable;
|
|
using DrinkRateAPI.AuthorizationPolicies;
|
|
using DrinkRateAPI.DbEntities;
|
|
using DrinkRateAPI.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DrinkRateAPI.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("productTable")]
|
|
public class ProductTableController : ControllerBase
|
|
{
|
|
private ProductTableService _productTableService;
|
|
|
|
public ProductTableController(ProductTableService productTableService)
|
|
{
|
|
_productTableService = productTableService;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize(Policy = PolicyConstants.AdminOnly)]
|
|
[Produces("application/json")]
|
|
public async Task<ProductTableGet> PostProductTable([FromBody] ProductTablePost productTable)
|
|
{
|
|
return await _productTableService.PostProductTableAsync(productTable);
|
|
}
|
|
|
|
[HttpGet("{productTableName}")]
|
|
[Produces("application/json")]
|
|
public async Task<ProductTableGet> GetProductTable([FromRoute] string productTableName)
|
|
{
|
|
return await _productTableService.GetProductTable(productTableName);
|
|
}
|
|
} |