Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Teste de Backend #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions BackendTest/BackEndTest.Application/BackEndTest.Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BackEndTest.Domain\BackEndTest.Domain.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions BackendTest/BackEndTest.Application/DTOs/InventoryDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using BackEndTest.Domain.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BackEndTest.Application.DTOs
{
public class InventoryDTO
{
public int Id { get; set; }
public int ProductSku { get; set; }
public int Quantity { get; set; }
public List<WarehouseDTO> Warehouses { get; set; }
}
}
15 changes: 15 additions & 0 deletions BackendTest/BackEndTest.Application/DTOs/ProductDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using BackEndTest.Domain.Entities;
using System.ComponentModel.DataAnnotations.Schema;

namespace BackEndTest.Application.DTOs
{
public class ProductDTO
{
public int Id { get; set; }
public int Sku { get; set; }
public string Name { get; set; }
public bool isMarketable { get; set; }
public int InventoryId { get; set; }
public InventoryDTO Inventory { get; set; }
}
}
17 changes: 17 additions & 0 deletions BackendTest/BackEndTest.Application/DTOs/WarehouseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BackEndTest.Application.DTOs
{
public class WarehouseDTO
{
public int Id { get; set; }
public int ProductSku { get; set; }
public string Locality { get; set; }
public int Quantity { get; set; }
public string Type { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BackEndTest.Application.DTOs;

namespace BackEndTest.Application.Interfaces
{
public interface IInventoryService
{
Task<bool> CreateInventory(InventoryDTO inventory, int productSku);
Task<InventoryDTO> GetInventoryByProductSku(int productSku);
Task<bool> RemoveInventoryByProductSku(int productSku);
Task<bool> UpdateInventoryByProductSku(InventoryDTO inventory);
}
}
13 changes: 13 additions & 0 deletions BackendTest/BackEndTest.Application/Interfaces/IProductService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BackEndTest.Application.DTOs;

namespace BackEndTest.Application.Interfaces
{
public interface IProductService
{
bool CheckExistingSku(int sku);
Task<bool> CreateProduct(ProductDTO product);
Task<ProductDTO> GetProductBySku(int sku);
Task<bool> RemoveProductBySku(int sku);
Task<bool> UpdateProductBySku(ProductDTO product);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BackEndTest.Application.DTOs;

namespace BackEndTest.Application.Interfaces
{
public interface IWarehouseService
{
Task<bool> CreateWarehouses(List<WarehouseDTO> warehouses, int productSku);
Task<List<WarehouseDTO>> GetWarehousesByProductSku(int productSku);
Task<bool> RemoveWarehousesByProductSku(int productSku);
Task<bool> UpdateWarehousesBySku(List<WarehouseDTO> warehouses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AutoMapper;
using BackEndTest.Application.DTOs;
using BackEndTest.Domain.Entities;

namespace BackEndTest.Application.Mappings
{
public class DomainToDTOMappingProfile : Profile
{
public DomainToDTOMappingProfile()
{
CreateMap<Product, ProductDTO>().ReverseMap();
CreateMap<Inventory, InventoryDTO>().ReverseMap();
CreateMap<Warehouse, WarehouseDTO>().ReverseMap();
}
}
}
49 changes: 49 additions & 0 deletions BackendTest/BackEndTest.Application/Services/InventoryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using AutoMapper;
using BackEndTest.Application.DTOs;
using BackEndTest.Application.Interfaces;
using BackEndTest.Domain.Entities;
using BackEndTest.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BackEndTest.Application.Services
{
public class InventoryService : IInventoryService
{
private IMapper _mapper;
private IInventoryRepository _inventoryRepository;

public InventoryService(IInventoryRepository inventoryRepository, IMapper mapper)
{
_inventoryRepository = inventoryRepository ??
throw new ArgumentNullException(nameof(inventoryRepository));
_mapper = mapper;
}

public async Task<bool> CreateInventory(InventoryDTO inventoryDTO, int productSku)
{
var inventoryEntity = _mapper.Map<Inventory>(inventoryDTO);
return await _inventoryRepository.CreateInventoryAsync(inventoryEntity, productSku);
}

public async Task<InventoryDTO> GetInventoryByProductSku(int productSku)
{
Inventory inventoryEntity = await _inventoryRepository.GetInventoryByProductSkuAsync(productSku);
return _mapper.Map<InventoryDTO>(inventoryEntity);
}

public async Task<bool> RemoveInventoryByProductSku(int productSku)
{
return await _inventoryRepository.RemoveInventoryByProductSkuAsync(productSku);
}

public async Task<bool> UpdateInventoryByProductSku(InventoryDTO inventoryDTO)
{
var inventoryEntity = _mapper.Map<Inventory>(inventoryDTO);
return await _inventoryRepository.UpdateInventoryByProductSkuAsync(inventoryEntity);
}
}
}
55 changes: 55 additions & 0 deletions BackendTest/BackEndTest.Application/Services/ProductService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using AutoMapper;
using BackEndTest.Application.DTOs;
using BackEndTest.Application.Interfaces;
using BackEndTest.Domain.Entities;
using BackEndTest.Domain.Interfaces;

namespace BackEndTest.Application.Services
{
public class ProductService : IProductService
{
private IMapper _mapper;
private IProductRepository _productRepository;

public ProductService(IProductRepository productRepository, IMapper mapper)
{
_productRepository = productRepository ??
throw new ArgumentNullException(nameof(productRepository));
_mapper = mapper;
}

/** Verifica existência de SKU
* True se for repetido
* False caso contrário
* */
public bool CheckExistingSku(int sku)
{
var skuList = _productRepository.GetAllProductSku();
return skuList.Contains(sku);
}

public async Task<bool> CreateProduct(ProductDTO productDTO)
{
var productEntity = _mapper.Map<Product>(productDTO);
return await _productRepository.CreateProductAsync(productEntity);
}

public async Task<ProductDTO> GetProductBySku(int sku)
{
Product productEntity = await _productRepository.GetProductBySkuAsync(sku);
return _mapper.Map<ProductDTO>(productEntity);
}

public async Task<bool> RemoveProductBySku(int sku)
{
return await _productRepository.RemoveProductBySkuAsync(sku);
}

public async Task<bool> UpdateProductBySku(ProductDTO productDTO)
{
var productEntity = _mapper.Map<Product>(productDTO);
return await _productRepository.UpdateProductBySkuAsync(productEntity);

}
}
}
44 changes: 44 additions & 0 deletions BackendTest/BackEndTest.Application/Services/WarehouseService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using AutoMapper;
using BackEndTest.Application.DTOs;
using BackEndTest.Application.Interfaces;
using BackEndTest.Domain.Entities;
using BackEndTest.Domain.Interfaces;

namespace BackEndTest.Application.Services
{
public class WarehouseService : IWarehouseService
{
private IMapper _mapper;
private IWarehouseRepository _warehouseRepository;

public WarehouseService(IWarehouseRepository warehouseRepository, IMapper mapper)
{
_warehouseRepository = warehouseRepository ??
throw new ArgumentNullException(nameof(warehouseRepository));
_mapper = mapper;
}

public async Task<bool> CreateWarehouses(List<WarehouseDTO> warehousesDTOs, int productSku)
{
var warehousesEntity = _mapper.Map<List<Warehouse>>(warehousesDTOs);
return await _warehouseRepository.CreateWarehousesAsync(warehousesEntity, productSku);
}

public async Task<List<WarehouseDTO>> GetWarehousesByProductSku(int productSku)
{
List<Warehouse> WarehouseEntity = await _warehouseRepository.GetWarehousesByProductSkuAsync(productSku);
return _mapper.Map<List<WarehouseDTO>>(WarehouseEntity);
}

public async Task<bool> RemoveWarehousesByProductSku(int productSku)
{
return await _warehouseRepository.RemoveWarehousesByProductSkuAsync(productSku);
}

public async Task<bool> UpdateWarehousesBySku(List<WarehouseDTO> warehousesDTOs)
{
List<Warehouse> warehouseEntity = _mapper.Map<List<Warehouse>>(warehousesDTOs);
return await _warehouseRepository.UpdateWarehousesBySkuAsync(warehouseEntity);
}
}
}
9 changes: 9 additions & 0 deletions BackendTest/BackEndTest.Domain/BackEndTest.Domain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions BackendTest/BackEndTest.Domain/Entities/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace BackEndTest.Domain.Entities
{
public class Inventory
{
public int Id { get; set; }
public int ProductSku { get; set; }
public int Quantity { get; set; }
[NotMapped]
public List<Warehouse> Warehouses { get; set; }
}
}
14 changes: 14 additions & 0 deletions BackendTest/BackEndTest.Domain/Entities/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace BackEndTest.Domain.Entities
{
public class Product
{
public int Id { get; set; }
public int Sku { get; set; }
public string Name { get; set; }
public bool isMarketable { get; set; }
[NotMapped]
public Inventory Inventory { get; set; }
}
}
11 changes: 11 additions & 0 deletions BackendTest/BackEndTest.Domain/Entities/Warehouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace BackEndTest.Domain.Entities
{
public class Warehouse
{
public int Id { get; set; }
public int ProductSku { get; set; }
public string Locality { get; set; }
public int Quantity { get; set; }
public string Type { get; set; }
}
}
12 changes: 12 additions & 0 deletions BackendTest/BackEndTest.Domain/Interfaces/IInventoryRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BackEndTest.Domain.Entities;

namespace BackEndTest.Domain.Interfaces
{
public interface IInventoryRepository
{
Task<bool> CreateInventoryAsync(Inventory inventory, int productSku);
Task<Inventory> GetInventoryByProductSkuAsync(int productSku);
Task<bool> RemoveInventoryByProductSkuAsync(int productSku);
Task<bool> UpdateInventoryByProductSkuAsync(Inventory inventory);
}
}
13 changes: 13 additions & 0 deletions BackendTest/BackEndTest.Domain/Interfaces/IProductRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BackEndTest.Domain.Entities;

namespace BackEndTest.Domain.Interfaces
{
public interface IProductRepository
{
Task<bool> CreateProductAsync(Product product);
List<int> GetAllProductSku();
Task<Product> GetProductBySkuAsync(int sku);
Task<bool> RemoveProductBySkuAsync(int sku);
Task<bool> UpdateProductBySkuAsync(Product product);
}
}
12 changes: 12 additions & 0 deletions BackendTest/BackEndTest.Domain/Interfaces/IWarehouseRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BackEndTest.Domain.Entities;

namespace BackEndTest.Domain.Interfaces
{
public interface IWarehouseRepository
{
Task<bool> CreateWarehousesAsync(List<Warehouse> warehouses, int productSku);
Task<List<Warehouse>> GetWarehousesByProductSkuAsync(int productSku);
Task<bool> RemoveWarehousesByProductSkuAsync(int productSku);
Task<bool> UpdateWarehousesBySkuAsync(List<Warehouse> warehouses);
}
}
Loading