Initial commit - ERP
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
|
||||
using Commerce.Contracts.DTOs;
|
||||
using Commerce.Core.Services;
|
||||
using Generic.Contracts.Generics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Commerce.Endpoints.v1;
|
||||
|
||||
public static class ProductMap
|
||||
{
|
||||
public static RouteGroupBuilder ProductEndpoints(this RouteGroupBuilder group)
|
||||
{
|
||||
|
||||
|
||||
// No Fetch
|
||||
group.MapGet(
|
||||
"products",
|
||||
async (
|
||||
[AsParameters] ProductFilter productFilter,
|
||||
[AsParameters] Pagination pagination,
|
||||
HttpContext httpContext,
|
||||
ProductService productService
|
||||
) =>
|
||||
{
|
||||
var result = await productService.FetchProduct(productFilter, pagination);
|
||||
httpContext.Response.Headers["X-Pagination"] = result.Item2.ToString();
|
||||
|
||||
return result.Item1;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// No Get
|
||||
group.MapGet(
|
||||
"product/{id}",
|
||||
async (Guid id, ProductService productService) =>
|
||||
{
|
||||
return await productService.GetProduct(id);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
// No Delete
|
||||
group.MapDelete(
|
||||
"product/{id}",
|
||||
async (Guid id, HttpContext httpContext, ProductService productService) =>
|
||||
{
|
||||
var userId = httpContext.User.Claims.First(x => x.Type == "uid").Value;
|
||||
await productService.RemoveProduct(id);
|
||||
}
|
||||
)
|
||||
.RequireAuthorization();
|
||||
|
||||
// No Put
|
||||
group.MapPut(
|
||||
"product",
|
||||
async ([FromBody] ProductVM product, ProductService productService) =>
|
||||
{
|
||||
await productService.UpdateProduct(product);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
// No Post
|
||||
group.MapPost(
|
||||
"product",
|
||||
async ([FromBody] ProductVM product, ProductService productService) =>
|
||||
{
|
||||
await productService.CreateProduct(product);
|
||||
}
|
||||
);
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user