Inventory Management System backend made with DotNet Core 6 and uses Vertical Slice Architecture and CQRS using EF Core with the UnitOfWork Pattern.
You can see the frontend repository here.
This api has the following features:
- Sign In (JWT AUTH)
- Permission Based Authorization
- Edit Profile Info
- CRUD Operations for Users
- CRUD Operatios for Roles
- CRUD Operations for Suppliers
- CURD Operations for Categories
- CRUD Operations for Products
public record CreateProductCommand(string Name, decimal Price) : IRequest<int>;
public class CreateProductCommandValidator : AbstractValidator<CreateProductCommand>
{
public CreateProductCommandValidator()
{
RuleFor(p => p.Name)
.NotNull()
.NotEmpty();
RuleFor(p => p.Price)
.NotNull()
.NotEmpty();
}
}
public class CreateProduct : IRequestHandler<CreateProductCommand, int>
{
private readonly IUnitOfWork _unitOfWork;
public CreateProduct(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
}
public async Task<int> Handle(CreateProductCommand request, CancellationToken cancellationToken)
{
var productRepository = _unitOfWork.GetRepository<Product, int>();
var newProduct = new Product(request.Name, request.Price);
await productRepository.CreateAndSaveAsync(newProduct);
return newProduct.Id;
}
}
public class ProductsController : ControllerBase
{
private readonly IMediator _mediator;
public ProductsController(IMediator mediator)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
}
[Authorize(Policy = Permissions.Products.Create)]
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateProductCommand command)
{
var productId = await _mediator.Send(command);
return Ok();
}
}- Cutomers Module
- Purchases Module
- Orders Module
- Reporting module
- Unit Test
Inspired by
- Minimal API Vertical Slice Architecture by Issac Ojeda
- CQRS and MediatR in ASP.NET Core by CodeMaze
- CQRS Validation Pipeline with MediatR and FluentValidation by CodeMaze