Skip to content
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
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/WebApi/bin/Debug/net6.0/WebApi.dll",
"args": [],
"cwd": "${workspaceFolder}/WebApi",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Clean-Architecture-WebApi.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Clean-Architecture-WebApi.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Clean-Architecture-WebApi.sln"
],
"problemMatcher": "$msCompile"
}
]
}
21 changes: 21 additions & 0 deletions Application/Features/Order/OrderCommands/OrderCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Order.OrderCommands
{
public class CreateOrder:IRequest<CreateOrderResponse>
{
public string CustomerId { get; set; }
public string Description { get; set; }
public string Address { get; set; }
public ICollection<string> ProductIds { get; set; }
}
public class CreateOrderResponse
{
public string OrderId { get; set; }
}
}
43 changes: 43 additions & 0 deletions Application/Features/Order/OrderCommands/OrderCommandHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Application.Features.Product.ProductCommands;
using AutoMapper;
using Domain.Interfaces;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Order.OrderCommands
{
public class OrderCommandHandlers :
IRequestHandler<CreateOrder, CreateOrderResponse>
{
private readonly IOrderRepository _orderRepository;
private readonly IProductRepository _productRepository;
private readonly IMapper _mapper;

public OrderCommandHandlers(IOrderRepository orderRepo, IProductRepository productRepo, IMapper mapper)
{
_orderRepository = orderRepo;
_productRepository = productRepo;
_mapper = mapper;
}

public async Task<CreateOrderResponse> Handle(CreateOrder request, CancellationToken cancellationToken)
{
var products = await _productRepository.GetProductsByIds(request.ProductIds);

var order = new Domain.Entities.Order
{
CustomerId = request.CustomerId,
Address = request.Address,
Description = request.Description,
Products = products
};
await _orderRepository.AddAsync(order);

return new CreateOrderResponse { OrderId = order.Id };
}
}
}
17 changes: 17 additions & 0 deletions Application/Features/Order/OrderQueries/OrderQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Order.OrderQueries
{
public class GetOrders:IRequest<GetOrdersResponse>
{
}
public class GetOrdersResponse
{
public object Orders { get; set; }
}
}
32 changes: 32 additions & 0 deletions Application/Features/Order/OrderQueries/OrderQueriesHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Application.Features.Order.OrderCommands;
using Application.Features.Product.ProductCommands;
using AutoMapper;
using Domain.Interfaces;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Order.OrderQueries
{
public class OrderQueriesHandlers :
IRequestHandler<GetOrders, GetOrdersResponse>
{
private readonly IOrderRepository _orderRepository;
private readonly IMapper _mapper;

public OrderQueriesHandlers(IOrderRepository orderRepo, IMapper mapper)
{
_orderRepository = orderRepo;
_mapper = mapper;
}

public async Task<GetOrdersResponse> Handle(GetOrders request, CancellationToken cancellationToken)
{
var orders = _orderRepository.GetAll();
return new() { Orders = orders };
}
}
}
9 changes: 9 additions & 0 deletions Application/ServiceRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Features.Category.CategoryQueries;
using Application.Features.Order.OrderCommands;
using Application.Features.Product.ProductCommands;
using AutoMapper;
using Domain.Entities;
Expand All @@ -20,10 +21,18 @@ public class RegisterMapper : Profile
{
public RegisterMapper()
{
// Product Mapeprs
CreateMap<CreateProduct, Product>();
CreateMap<UpdateProduct, Product>();
// Auth Mappers
CreateMap<RegisterCommand, RegisterUser>();
// Category Mappers
CreateMap<Category, GetCategoriesMapper>();
// Order Mappers
//CreateMap<CreateOrder, Order>()
// .ForMember(dest => dest.Products, opt => opt.Ignore())
// .ForSourceMember(src => src.ProductIds, opt => opt.DoNotValidate());

}
}
public static void AddMapperServices(this IServiceCollection services)
Expand Down
18 changes: 12 additions & 6 deletions Clean-Architecture-WebApi.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33627.172
# Visual Studio Version 16
VisualStudioVersion = 16.0.34114.132
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "WebApi\WebApi.csproj", "{C1BBCF62-2B34-4087-A393-CD006853D970}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{C1BBCF62-2B34-4087-A393-CD006853D970}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{2621E73D-E51C-4E4E-80E5-CB2DD402C01E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{2621E73D-E51C-4E4E-80E5-CB2DD402C01E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{9AF4F777-450C-4E3A-8F88-5E1D79DC9D9D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{9AF4F777-450C-4E3A-8F88-5E1D79DC9D9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{9472D01F-C7B3-4A9D-B6E4-3A650BA4D5F9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{9472D01F-C7B3-4A9D-B6E4-3A650BA4D5F9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi.Tests", "WebApi.Tests\WebApi.Tests.csproj", "{A5AE6E8E-ABC9-4B29-A3A3-0A03A91A0B4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,6 +35,10 @@ Global
{9472D01F-C7B3-4A9D-B6E4-3A650BA4D5F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9472D01F-C7B3-4A9D-B6E4-3A650BA4D5F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9472D01F-C7B3-4A9D-B6E4-3A650BA4D5F9}.Release|Any CPU.Build.0 = Release|Any CPU
{A5AE6E8E-ABC9-4B29-A3A3-0A03A91A0B4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5AE6E8E-ABC9-4B29-A3A3-0A03A91A0B4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5AE6E8E-ABC9-4B29-A3A3-0A03A91A0B4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5AE6E8E-ABC9-4B29-A3A3-0A03A91A0B4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions Domain/Entities/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Domain.Entities.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Entities
{
public class Order:BaseEntity
{
public string CustomerId { get; set; }
public string Description { get; set; }
public string Address { get; set; }
public ICollection<Product> Products { get; set; }
}
}
1 change: 1 addition & 0 deletions Domain/Entities/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class Product:BaseEntity
public bool IsActive { get; set; }
public int Stock { get; set; }
public string CategoryId { get; set; }
public ICollection<Order> Orders { get; set; }
}
}
14 changes: 14 additions & 0 deletions Domain/Interfaces/IOrderRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Domain.Entities;
using Domain.Interfaces.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Interfaces
{
public interface IOrderRepository:IGenericRepository<Order>
{
}
}
1 change: 1 addition & 0 deletions Domain/Interfaces/IProductRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ namespace Domain.Interfaces
public interface IProductRepository : IGenericRepository<Product>
{
Task<ICollection<Product>> GetProductsByCategoryId(string CategoryId);
Task<ICollection<Product>> GetProductsByIds(ICollection<string> productIds);
}
}
1 change: 1 addition & 0 deletions Infrastructure/Contexts/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class EFDBContext : IdentityDbContext<ApplicationUser, ApplicationRole, s
public EFDBContext(DbContextOptions options) : base(options) { }
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Order> Order { get; set; }

public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
Expand Down
Loading