Skip to content

juan-canseco-dev/inventory-api-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Inventory API (Work In Progress)

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.

Features

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

Example of how a command/query works

  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();
        }
     }

To do

  • Cutomers Module
  • Purchases Module
  • Orders Module
  • Reporting module
  • Unit Test

Libraries used

Credits

Inspired by

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages