Initial commit - ERP
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Commerce.Endpoints.v1;
|
||||
|
||||
namespace Commerce.Endpoints;
|
||||
|
||||
public static class RegisterEndpoints
|
||||
{
|
||||
public static void MapAPIv1(this IEndpointRouteBuilder app)
|
||||
{
|
||||
//hello
|
||||
app.MapGroup("api/v1/").ProductEndpoints().WithTags("Product").RequireCors("default");
|
||||
app.MapGroup("api/v1/").CategoryEndpoints().WithTags("Category").RequireCors("default");
|
||||
}
|
||||
public static void MapAPIv2(this IEndpointRouteBuilder app)
|
||||
{
|
||||
//hello
|
||||
app.MapGroup("api/v1/").ProductEndpoints().WithTags("Product").RequireCors("default");
|
||||
app.MapGroup("api/v1/").CategoryEndpoints().WithTags("Category").RequireCors("default");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
|
||||
using Commerce.Contracts.DTOs;
|
||||
using Commerce.Core.Services;
|
||||
using Commerce.Domain.Entities;
|
||||
using Generic.Contracts.Generics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Commerce.Endpoints.v1;
|
||||
|
||||
public static class CategoryMap
|
||||
{
|
||||
public static RouteGroupBuilder CategoryEndpoints(this RouteGroupBuilder group)
|
||||
{
|
||||
|
||||
|
||||
// No Fetch
|
||||
group.MapGet(
|
||||
"categories",
|
||||
async (
|
||||
[AsParameters] CategoryFilter categoryFilter,
|
||||
[AsParameters] Pagination pagination,
|
||||
CategoryService categoryService,
|
||||
HttpContext httpContext
|
||||
) =>
|
||||
{
|
||||
var result = await categoryService.FetchCategory(categoryFilter, pagination);
|
||||
httpContext.Response.Headers["X-Pagination"] = result.Item2.ToString();
|
||||
|
||||
return result.Item1;
|
||||
}
|
||||
);
|
||||
|
||||
group.MapGet(
|
||||
"categories/tree",
|
||||
async (string? name, CategoryService categoryService) =>
|
||||
{
|
||||
var result = await categoryService.GetAllCategories_Tree(name ?? "");
|
||||
return result.Select(x => Category.ToVM(x)).ToList();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// No Get
|
||||
group.MapGet(
|
||||
"category/{id}",
|
||||
async (Guid id, CategoryService categoryService) =>
|
||||
{
|
||||
return await categoryService.GetCategory(id);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
// No Delete
|
||||
group
|
||||
.MapDelete(
|
||||
"category/{id}",
|
||||
async (Guid id, HttpContext httpContext, CategoryService categoryService) =>
|
||||
{
|
||||
var userId = httpContext.User.Claims.First(x => x.Type == "uid").Value;
|
||||
await categoryService.RemoveCategory(id);
|
||||
}
|
||||
)
|
||||
.RequireAuthorization();
|
||||
|
||||
// No Put
|
||||
group.MapPut(
|
||||
"category",
|
||||
async ([FromBody] CategoryVM category, CategoryService categoryService) =>
|
||||
{
|
||||
await categoryService.UpdateCategory(category);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
// No Post
|
||||
group.MapPost(
|
||||
"category",
|
||||
async ([FromBody] CategoryVM category, CategoryService categoryService) =>
|
||||
{
|
||||
await categoryService.CreateCategory(category);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -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