Commit 514c14b7 authored by hasan khaddour's avatar hasan khaddour

Add CQRS Structure

parent b7910ea4
using FluentResults; using FluentResults;
using FluentValidation; using FluentValidation;
using MediatR; using MediatR;
using PSManagement.Application.Common.Exceptions;
using PSManagement.SharedKernel.CQRS.Command;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ValidationException = PSManagement.Application.Common.Exceptions.ValidationException;
namespace PSManagement.Application.Behaviors.ValidationBehavior namespace PSManagement.Application.Behaviors.ValidationBehavior
{ {
......
using PSManagement.SharedKernel.DomainException;
using System.Collections.Generic;
namespace PSManagement.Application.Common.Exceptions
{
public sealed class ValidationException : BadRequestException
{
public ValidationException(Dictionary<string, string[]> errors)
: base("Validation errors occurred") =>
Errors = errors;
public Dictionary<string, string[]> Errors { get; }
}
}
using System; using PSManagement.Domain.Identity.Entities;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -12,6 +14,7 @@ namespace PSManagement.Application.Contracts.Authentication ...@@ -12,6 +14,7 @@ namespace PSManagement.Application.Contracts.Authentication
public String Email { get; set; } public String Email { get; set; }
public String LastName { get; set; } public String LastName { get; set; }
public String FirstName { get; set; } public String FirstName { get; set; }
public ICollection<Role> Roles { get; set; }
public String Token { get; set; } public String Token { get; set; }
} }
......
using System; using PSManagement.Domain.Identity.Entities;
using System;
namespace PSManagement.Application.Contracts.Authorization namespace PSManagement.Application.Contracts.Authorization
{ {
public interface IJwtTokenGenerator public interface IJwtTokenGenerator
{ {
public String GenerateToken(int id , String firstName , String lastName,String email ); public String GenerateToken(User user);
} }
} }
using FluentResults;
using PSManagement.Domain.Identity.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application.Contracts.Authorization
{
public interface IRoleService
{
Task<Result> CreateRoleAsync(string roleName);
Task<Result> DeleteRoleAsync(int roleId);
Task<List<Role>> GetRolesAsync();
Task<Result<Role>> GetRoleByIdAsync(int id);
Task<Result<Role>> UpdateRole(int id, string roleName);
}
}
using FluentResults;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PSManagement.Application.Contracts.Authorization
{
public interface IUserRoleService
{
Task<bool> IsInRoleAsync(int userId, string role);
Task<List<string>> GetUserRolesAsync(string email);
Task<Result> AssignUserToRole(string userName, string roleName);
Task UpdateUsersRole(string userName, string usersRole);
Task<Result> RemoveUserFromRole(string email, string roleName);
}
}
...@@ -4,7 +4,7 @@ using System.Linq; ...@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PSManagement.Application.Common.Services namespace PSManagement.Application.Contracts.Providers
{ {
public interface IDateTimeProvider public interface IDateTimeProvider
{ {
......
using System; using FluentResults;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PSManagement.Application.Customers.Common namespace PSManagement.Application.Contracts.Storage
{ {
public record AddressDTO( public interface IFileService
int StreetNumber, {
int ZipCode , public Result StoreFile(string fileName);
String StreetName ,
String City ); }
} }
using System; using PSManagement.Domain.Customers.ValueObjects;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -10,7 +11,7 @@ namespace PSManagement.Application.Customers.Common ...@@ -10,7 +11,7 @@ namespace PSManagement.Application.Customers.Common
{ {
public int Id { get; set; } public int Id { get; set; }
public String CustomerName { get; set; } public String CustomerName { get; set; }
public AddressDTO Address { get; set; } public Address Address { get; set; }
public String Email { get; set; } public String Email { get; set; }
public IEnumerable<ContactInfoDTO> ContactInfo { get; private set; } public IEnumerable<ContactInfoDTO> ContactInfo { get; private set; }
......
...@@ -15,7 +15,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer ...@@ -15,7 +15,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
public record CreateCustomerCommand( public record CreateCustomerCommand(
string CustomerName, string CustomerName,
string Email, string Email,
AddressDTO Address Address Address
) : ICommand<Result<int>>; ) : ICommand<Result<int>>;
} }
...@@ -17,16 +17,15 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer ...@@ -17,16 +17,15 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
public class CreateCustomerCommandHandler : ICommandHandler<CreateCustomerCommand, Result<int>> public class CreateCustomerCommandHandler : ICommandHandler<CreateCustomerCommand, Result<int>>
{ {
private readonly ICustomersRepository _customerRepository; private readonly ICustomersRepository _customerRepository;
private readonly IMapper _mapper;
public CreateCustomerCommandHandler(ICustomersRepository customerRepository, IMapper mapper) public CreateCustomerCommandHandler(ICustomersRepository customerRepository)
{ {
_customerRepository = customerRepository; _customerRepository = customerRepository;
_mapper = mapper;
} }
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
{ {
Customer customer = new (request.CustomerName ,_mapper.Map<Address>(request.Address),request.Email); Customer customer = new (request.CustomerName ,request.Address,request.Email);
customer =await _customerRepository.AddAsync(customer); customer =await _customerRepository.AddAsync(customer);
......
...@@ -15,7 +15,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer ...@@ -15,7 +15,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
int CustomerId, int CustomerId,
String CustomerName , String CustomerName ,
String Email, String Email,
AddressDTO Address Address Address
) : ICommand<Result>; ) : ICommand<Result>;
} }
...@@ -26,7 +26,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer ...@@ -26,7 +26,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
{ {
Customer customer = new (request.CustomerName ,_mapper.Map<Address>(request.Address),request.Email); Customer customer = new (request.CustomerName ,request.Address,request.Email);
customer.Id = request.CustomerId; customer.Id = request.CustomerId;
await _customerRepository.UpdateAsync(customer); await _customerRepository.UpdateAsync(customer);
......
...@@ -15,7 +15,6 @@ namespace PSManagement.Application.Mappers ...@@ -15,7 +15,6 @@ namespace PSManagement.Application.Mappers
{ {
public CustomerMapperConfiguration() public CustomerMapperConfiguration()
{ {
CreateMap<AddressDTO, Address>().ReverseMap();
CreateMap<CustomerDTO, Customer>().ReverseMap(); CreateMap<CustomerDTO, Customer>().ReverseMap();
CreateMap<ContactInfoDTO, ContactInfo>().ReverseMap(); CreateMap<ContactInfoDTO, ContactInfo>().ReverseMap();
......
...@@ -6,6 +6,30 @@ ...@@ -6,6 +6,30 @@
<ItemGroup> <ItemGroup>
<Folder Include="Behaviors\AuthorizationBehavior\" /> <Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="ProjectsStatus\UseCases\" />
<Folder Include="Projects\UseCases\Commands\AddStep\" />
<Folder Include="Projects\UseCases\Commands\AddFinincialSpending\" />
<Folder Include="Projects\UseCases\Commands\AddParticipant\" />
<Folder Include="Projects\UseCases\Commands\UpdateParticipant\" />
<Folder Include="Projects\UseCases\Commands\UpdateFinincialSpending\" />
<Folder Include="Projects\UseCases\Commands\UpdateProject\" />
<Folder Include="Projects\UseCases\Commands\UpdateStep\" />
<Folder Include="Projects\UseCases\Queries\ListAllProject\" />
<Folder Include="Projects\UseCases\Queries\GetProjectPlan\" />
<Folder Include="Projects\UseCases\Queries\GetProject\" />
<Folder Include="Projects\UseCases\Queries\GetProjectFinicialSpending\" />
<Folder Include="Tracks\UseCaes\Commands\CreateTrack\" />
<Folder Include="Tracks\UseCaes\Commands\AddStepsTrack\" />
<Folder Include="Tracks\UseCaes\Commands\AddEmployeesTrack\" />
<Folder Include="Tracks\UseCaes\Commands\SaveTrack\" />
<Folder Include="Tracks\UseCaes\Commands\UpdateEmployeeTrack\" />
<Folder Include="Tracks\UseCaes\Commands\UpdateStepTrack\" />
<Folder Include="Tracks\UseCaes\Commands\UpdateTrack\" />
<Folder Include="Tracks\UseCaes\Queries\ListAll\" />
<Folder Include="Tracks\UseCaes\Queries\GetTrack\" />
<Folder Include="Tracks\UseCaes\Queries\GetPlanTrack\" />
<Folder Include="Tracks\UseCaes\Queries\GetEmployeesTrack\" />
<Folder Include="Tracks\UseCaes\Queries\GetEmployeeTrack\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
namespace PSManagement.Application.Projects.Common
{
public class ProjectDTO
{
}
}
\ No newline at end of file
using FluentResults;
using PSManagement.Application.Projects.Common;
using PSManagement.Domain.Projects.ValueObjects;
using PSManagement.SharedKernel.CQRS.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public record CreateProjectCommand(
ProjectInfo ProjectInfo ,
ProposalInfo ProposalInfo,
Aggreement ProjectAggreement,
int TeamLeaderId ,
int ProjectManagerId,
int ProposerId
) : ICommand<Result<ProjectDTO>>;
}
using FluentResults;
using PSManagement.Application.Projects.Common;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public class CreateProjectCommandHandler : ICommandHandler<CreateProjectCommand, Result<ProjectDTO>>
{
private readonly IProjectsRepository _projectsRepository;
public CreateProjectCommandHandler(IProjectsRepository projectsRepository)
{
_projectsRepository = projectsRepository;
}
public Task<Result<ProjectDTO>> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
{
return Task.FromResult<Result<ProjectDTO>>(Result.Fail(new Error("")));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment