-
Notifications
You must be signed in to change notification settings - Fork 79
Create e-commerce Web API #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4cd5b4c
f3071a4
99475dd
867c034
c77f4ce
ef660f4
95637bd
ef30dfe
2a068e4
c7f788d
5d0f861
296cee7
89df08a
5ca2f5c
32be35e
ded8d39
7b0751c
963bb4c
480fe77
b33be1e
779f9dc
fd70152
f4eec04
af2fe3e
92eaf59
62c8da7
8e09dc7
9a3ed5b
0f6c64f
1803daa
a6d9433
5df25cd
5ec82e9
2010954
cf97492
26ff99c
cd1d3cc
2250178
833f12b
fe1ebc8
b9087c5
5fe7a34
5ba1eb3
fb9e8e1
c87f47e
86df173
59d6ceb
a21fe01
e51adde
1b62a7f
e793f57
a46a6b5
94b0f82
caa9944
7d8ea08
15c3a46
3a6189f
c46a6e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| namespace Ecommerce.Core.DTOs.Auth; | ||
|
|
||
| public record AuthResponseDto(string Token, DateTime Expires); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Ecommerce.Core.DTOs.Auth; | ||
|
|
||
| public record LoginDto | ||
| { | ||
| public string Email { get; init; } = string.Empty; | ||
| public string Password { get; init; } = string.Empty; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace Ecommerce.Core.DTOs.Auth; | ||
|
|
||
| public record RegisterDto | ||
| { | ||
| public string Username { get; init; } = string.Empty; | ||
| public string Email { get; init; } = string.Empty; | ||
| public string Password { get; init; } = string.Empty; | ||
| public string? Address { get; init; } | ||
| public string? PhoneNumber { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace Ecommerce.Core.DTOs.Category; | ||
|
|
||
| public record CategoryDto | ||
| { | ||
| public int Id { get; init; } | ||
| public string Name { get; init; } = string.Empty; | ||
| public string? Description { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Ecommerce.Core.DTOs.Category; | ||
|
|
||
| public record CreateCategoryDto | ||
| { | ||
| public string Name { get; init; } = string.Empty; | ||
| public string? Description { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Ecommerce.Core.DTOs.Category; | ||
|
|
||
| public record UpdateCategoryDto | ||
| { | ||
| public string Name { get; init; } = string.Empty; | ||
| public string? Description { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Ecommerce.Core.DTOs.Product; | ||
|
|
||
| public record CreateProductDto | ||
| { | ||
| public string Name { get; init; } = string.Empty; | ||
| public decimal Price { get; init; } | ||
| public int Quantity { get; init; } = 1; | ||
| public string? Description { get; init; } | ||
| public string? ImageUrl { get; init; } | ||
| public int CategoryId { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Ecommerce.Core.DTOs.Product; | ||
|
|
||
| public record ProductDto | ||
| { | ||
| public int Id { get; init; } | ||
| public string Name { get; init; } = string.Empty; | ||
| public decimal Price { get; init; } | ||
| public int Quantity { get; init; } | ||
| public string? Description { get; init; } | ||
| public string? ImageUrl { get; init; } | ||
| public int CategoryId { get; init; } | ||
| public string CategoryName { get; init; } = string.Empty; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Ecommerce.Core.DTOs.Product; | ||
|
|
||
| public record UpdateProductDto | ||
| { | ||
| public string Name { get; init; } = string.Empty; | ||
| public decimal Price { get; init; } | ||
| public int Quantity { get; init; } | ||
| public string? Description { get; init; } | ||
| public string? ImageUrl { get; init; } | ||
| public int CategoryId { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace Ecommerce.Core.DTOs.Sale; | ||
|
|
||
| public record CreateSaleDto | ||
| { | ||
| public List<CreateSaleItemDto> Items { get; init; } = new(); | ||
| } | ||
|
|
||
| public record CreateSaleItemDto | ||
| { | ||
| public int ProductId { get; init; } | ||
| public int Quantity { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| namespace Ecommerce.Core.DTOs.Sale; | ||
|
|
||
| public record SaleDto | ||
| { | ||
| public int Id { get; init; } | ||
| public DateTime CreationDate { get; init; } | ||
| public decimal TotalPrice { get; init; } | ||
| public List<SaleItemDto> Items { get; init; } = new(); | ||
| } | ||
|
|
||
| public record SaleItemDto | ||
| { | ||
| public int ProductId { get; init; } | ||
| public string? ProductName { get; init; } = string.Empty; | ||
| public decimal UnitPrice { get; init; } | ||
| public int Quantity { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FluentValidation" Version="12.1.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Microsoft.Extensions.Identity.Stores"> | ||
| <HintPath>..\..\..\..\..\..\..\..\..\..\home\basem\.nuget\packages\microsoft.extensions.identity.stores\10.0.3\lib\net10.0\Microsoft.Extensions.Identity.Stores.dll</HintPath> | ||
| </Reference> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Ecommerce.Core.Interfaces.Common; | ||
|
|
||
| public interface IBaseEntity | ||
| { | ||
| int Id { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Ecommerce.Core.Interfaces.Common; | ||
|
|
||
| public interface ISoftDeletable | ||
| { | ||
| bool IsDeleted { get; set; } | ||
| DateTime? DeletedAt { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| using Ecommerce.Core.Models; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Repositories; | ||
|
|
||
| public interface ICategoryRepository : IGenericRepository<Category> | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System.Linq.Expressions; | ||
| using Ecommerce.Core.Interfaces.Common; | ||
| using Ecommerce.Core.Utilities; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Repositories; | ||
|
|
||
| public interface IGenericRepository<T> where T : class | ||
| { | ||
| Task<List<T>> GetAllAsync(params Expression<Func<T, object?>>[] includeProperties); | ||
| Task<List<T>> GetAllAsync(PaginationParams paginationParams, params Expression<Func<T, object?>>[] includeProperties); | ||
| Task<List<T>> FindAsync(Expression<Func<T, bool>> predicate, params Expression<Func<T, object?>>[] includeProperties); | ||
| Task<T?> GetByIdAsync(int id, params Expression<Func<T, object?>>[] includes); | ||
| void Add(T entity); | ||
| void Update(T entity); | ||
| void Delete(ISoftDeletable entity); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| using Ecommerce.Core.Models; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Repositories; | ||
|
|
||
| public interface IProductRepository : IGenericRepository<Product> | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Ecommerce.Core.Models; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Repositories; | ||
|
|
||
| public interface ISaleRepository : IGenericRepository<Sale> | ||
| { | ||
| Task<Sale?> GetSaleWithItemsAsync(int id); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using Ecommerce.Core.Models; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Repositories; | ||
|
|
||
| public interface IUnitOfWork | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Unit of Work ❓ I know you have implemented CA and app should not know about infra, but should unit of work be defined here as a contract? Also as you are using EFCore in Infra, that already implements the UoW pattern, so is kind of pointless. |
||
| { | ||
| IProductRepository Products { get; } | ||
| ICategoryRepository Categories { get; } | ||
| ISaleRepository Sales { get; } | ||
|
|
||
| Task<int> CompleteAsync(); | ||
| void Dispose(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using Ecommerce.Core.DTOs.Auth; | ||
| using Ecommerce.Core.Utilities; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Services; | ||
|
|
||
| public interface IAuthService | ||
| { | ||
| Task<Result<string>> Register(RegisterDto registerDto); | ||
| Task<Result<AuthResponseDto>> Login(LoginDto loginDto); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using Ecommerce.Core.DTOs.Category; | ||
| using Ecommerce.Core.Utilities; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Services; | ||
|
|
||
| public interface ICategoryService | ||
| { | ||
| Task<Result<CategoryDto>> CreateCategoryAsync(CreateCategoryDto category); | ||
| Task<Result<CategoryDto>> GetCategoryAsync(int id); | ||
| Task<Result<IEnumerable<CategoryDto>>> GetAllCategoriesAsync(); | ||
| Task<Result<CategoryDto>> UpdateCategoryAsync(int id, UpdateCategoryDto category); | ||
| Task<Result<bool>> DeleteCategoryAsync(int id); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Ecommerce.Core.DTOs; | ||
| using Ecommerce.Core.DTOs.Product; | ||
| using Ecommerce.Core.Utilities; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Services; | ||
|
|
||
| public interface IProductService | ||
| { | ||
| Task<Result<ProductDto>> CreateProductAsync(CreateProductDto product); | ||
| Task<Result<ProductDto>> GetProductAsync(int id); | ||
| Task<Result<IEnumerable<ProductDto>>> GetAllProductsAsync(PaginationParams paginationParams); | ||
| Task<Result<ProductDto>> UpdateProductAsync(int id, UpdateProductDto product); | ||
| Task<Result<bool>> DeleteProductAsync(int id); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using Ecommerce.Core.DTOs.Sale; | ||
| using Ecommerce.Core.Utilities; | ||
|
|
||
| namespace Ecommerce.Core.Interfaces.Services; | ||
|
|
||
| public interface ISaleService | ||
| { | ||
| Task<Result<SaleDto>> CreateSaleAsync(CreateSaleDto sale); | ||
| Task<Result<SaleDto>> GetSaleAsync(int id); | ||
| Task<Result<IEnumerable<SaleDto>>> GetAllSalesAsync(PaginationParams paginationParams); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Microsoft.AspNetCore.Identity; | ||
|
|
||
| namespace Ecommerce.Core.Models; | ||
|
|
||
| public class ApplicationUser : IdentityUser | ||
| { | ||
| public string? Address { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using Ecommerce.Core.Interfaces.Common; | ||
|
|
||
| namespace Ecommerce.Core.Models; | ||
|
|
||
| public class Category : IBaseEntity, ISoftDeletable | ||
| { | ||
| public const int MaxNameLength = 50; | ||
| public const int MaxDescriptionLength = 250; | ||
|
|
||
| public int Id { get; set; } | ||
| public string Name { get; set; } = string.Empty; | ||
| public string? Description { get; set; } | ||
| public ICollection<Product> Products { get; set; } = new List<Product>(); | ||
|
|
||
| public bool IsDeleted { get; set; } | ||
| public DateTime? DeletedAt { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Ecommerce.Core.Interfaces.Common; | ||
|
|
||
| namespace Ecommerce.Core.Models; | ||
|
|
||
| public class Product : IBaseEntity, ISoftDeletable | ||
| { | ||
| public const int MaxNameLength = 50; | ||
| public const int MaxDescriptionLength = 250; | ||
|
|
||
| public int Id { get; set; } | ||
| public string Name { get; set; } = string.Empty; | ||
| public decimal Price { get; set; } | ||
| public int Quantity { get; set; } | ||
| public string? Description { get; set; } | ||
| public string? ImageUrl { get; set; } | ||
| public int CategoryId { get; set; } | ||
| public Category? Category { get; set; } | ||
|
|
||
| public bool IsDeleted { get; set; } | ||
| public DateTime? DeletedAt { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Ecommerce.Core.Interfaces.Common; | ||
|
|
||
| namespace Ecommerce.Core.Models; | ||
|
|
||
| public class Sale : IBaseEntity, ISoftDeletable | ||
| { | ||
| public int Id { get; set; } | ||
| public DateTime CreationDate { get; init; } | ||
| public decimal TotalPrice { get; init; } | ||
| public ICollection<SaleItem> Items { get; init; } = new List<SaleItem>(); | ||
|
|
||
| public bool IsDeleted { get; set; } | ||
| public DateTime? DeletedAt { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Ecommerce.Core.Models; | ||
|
|
||
| public class SaleItem | ||
| { | ||
| public int ProductId { get; set; } | ||
| public Product? Product { get; set; } | ||
| public int SaleId { get; set; } | ||
| public Sale? Sale { get; set; } | ||
| public decimal UnitPriceAtTimeOfSale { get; set; } | ||
| public int Quantity { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Ecommerce.Core.Utilities; | ||
|
|
||
| public record PaginationParams | ||
| { | ||
| private const int DefaultPageSize = 50; | ||
|
|
||
| public int PageNumber | ||
| { | ||
| get; | ||
| init => | ||
| field = value > 0 ? value : 1; | ||
| } = 1; | ||
|
|
||
| public int PageSize | ||
| { | ||
| get; | ||
| init => | ||
| field = value > DefaultPageSize ? DefaultPageSize : value; | ||
| } = 10; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.