Commit ab64adee authored by hasan khaddour's avatar hasan khaddour

refactor the solution architecture

parent 9f943cfa
......@@ -38,7 +38,9 @@ namespace PSManagement.Api
.AddApplication()
.AddPersistence(Configuration)
.AddInfrastructure(Configuration);
services
.AddControllers()
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Presentation
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
......@@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.ApiBase
namespace PSManagement.Presentation.Controllers.ApiBase
{
[Route("api/[controller]")]
[ApiController]
......
using System.Linq;
using Ardalis.Result;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Contracts.Authentication;
using PSManagement.Contracts.Authentication;
using System.Threading.Tasks;
using AuthenticationResponse = PSManagement.Contracts.Authentication.AuthenticationResponse;
using AutoMapper;
using PSManagement.Presentation.Controllers.ApiBase;
namespace PSManagement.Api.Controllers.Authentication
namespace PSManagement.Presentation.Controllers.Authentication
{
[Route("api/[controller]")]
public class AuthenticationController : APIController
......@@ -32,17 +32,17 @@ namespace PSManagement.Api.Controllers.Authentication
[HttpPost("Register")]
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
{
Result<AuthenticationResult> result = await _authenticationService.Register(
registerRequest.Email,
registerRequest.Email,
registerRequest.Password);
if (result.IsSuccess)
{
AuthenticationResponse response = new (
AuthenticationResponse response = new(
result.Value.EmployeeId,
result.Value.FirstName,
result.Value.LastName,
......@@ -52,7 +52,7 @@ namespace PSManagement.Api.Controllers.Authentication
return Ok(response);
}
return Problem(title: "An Errorr Occured " , detail:"", statusCode: 400);
return Problem(title: "An Errorr Occured ", detail: "", statusCode: 400);
}
}
......
......@@ -16,11 +16,11 @@ using PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer;
using PSManagement.Application.Customers.UseCases.Queries.ListAllCustomers;
using PSManagement.Contracts.Customers.Responses;
using PSManagement.Application.Customers.UseCases.Queries.GetCustomer;
using PSManagement.Api.Controllers.ApiBase;
using Ardalis.Result;
using PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo;
using PSManagement.Presentation.Controllers.ApiBase;
namespace PSManagement.Api.Controllers.Customers
namespace PSManagement.Presentation.Controllers.Customers
{
[Route("api/[controller]")]
[Authorize]
......@@ -29,7 +29,7 @@ namespace PSManagement.Api.Controllers.Customers
private readonly IMediator _sender;
private readonly IMapper _mapper;
public CustomersController(IMediator sender, IMapper mapper )
public CustomersController(IMediator sender, IMapper mapper)
{
_sender = sender;
_mapper = mapper;
......@@ -40,13 +40,13 @@ namespace PSManagement.Api.Controllers.Customers
{
var query = new ListAllCustomersQuery();
var result = _mapper.Map<Result<IEnumerable<CustomerResponse>>>( await _sender.Send(query));
var result = _mapper.Map<Result<IEnumerable<CustomerResponse>>>(await _sender.Send(query));
return HandleResult(result);
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id )
public async Task<IActionResult> Get(int id)
{
var query = new GetCustomerQuery(id);
......@@ -80,7 +80,7 @@ namespace PSManagement.Api.Controllers.Customers
}
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
......@@ -93,9 +93,10 @@ namespace PSManagement.Api.Controllers.Customers
}
[HttpPut("{id}")]
public async Task<IActionResult> Put(int id ,UpdateCustomerRequest request)
public async Task<IActionResult> Put(int id, UpdateCustomerRequest request)
{
if(id != request.CustomerId){
if (id != request.CustomerId)
{
return Problem();
}
var command = _mapper.Map<UpdateCustomerCommand>(request);
......
......@@ -3,7 +3,6 @@ using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Contracts.Providers;
using PSManagement.Application.Contracts.SyncData;
using PSManagement.Application.Employees.UseCases.Commands.UpdateEmployeeWorkHours;
......@@ -15,12 +14,13 @@ using PSManagement.Application.Employees.UseCases.Queries.GetEmployeeTrackHistor
using PSManagement.Contracts.Employees.Requests;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Contracts.Tracks.Response;
using PSManagement.Presentation.Controllers.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Employees
namespace PSManagement.Presentation.Controllers.Employees
{
[Route("api/[controller]")]
public class EmployeesController : APIController
......@@ -30,10 +30,11 @@ namespace PSManagement.Api.Controllers.Employees
private readonly IMediator _sender;
private readonly IMapper _mapper;
#region Constructors
public EmployeesController(
ISyncEmployeesService syncEmployeesService,
IMapper mapper,
IMediator sender,
IMediator sender,
IEmployeesProvider employeesProvider)
{
_syncEmployeesService = syncEmployeesService;
......@@ -41,7 +42,9 @@ namespace PSManagement.Api.Controllers.Employees
_sender = sender;
_employeesProvider = employeesProvider;
}
#endregion Constructors
#region Get Requests
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
......@@ -54,7 +57,7 @@ namespace PSManagement.Api.Controllers.Employees
}
[HttpGet("ByFilter")]
public async Task<IActionResult> GetByFilter([FromQuery]GetEmployeesByFilterRequest request)
public async Task<IActionResult> GetByFilter([FromQuery] GetEmployeesByFilterRequest request)
{
GetEmployeesByFilterQuery query = _mapper.Map<GetEmployeesByFilterQuery>(request);
......@@ -64,7 +67,7 @@ namespace PSManagement.Api.Controllers.Employees
}
[HttpGet("Available")]
public async Task<IActionResult> GetAllAvailable([FromQuery]GetAvailableEmployeesRequest request)
public async Task<IActionResult> GetAllAvailable([FromQuery] GetAvailableEmployeesRequest request)
{
GetAvailableEmployeesQuery query = _mapper.Map<GetAvailableEmployeesQuery>(request);
......@@ -76,12 +79,12 @@ namespace PSManagement.Api.Controllers.Employees
[HttpGet("Departments")]
public async Task<IActionResult> GetDepartments()
{
var query = new GetDepartmentsQuery();
var query = new GetDepartmentsQuery();
var result = await _sender.Send(query);
return HandleResult(_mapper.Map<Result<IEnumerable<DepartmentResponse>>>(result));
}
......@@ -94,7 +97,7 @@ namespace PSManagement.Api.Controllers.Employees
return HandleResult(_mapper.Map<Result<IEnumerable<EmployeeParticipateResponse>>>(result));
}
[HttpGet("TrackHistory")]
public async Task<IActionResult> GetEmployeeTrackHistory([FromQuery] GetEmployeeTrackHistoryRequest request)
{
......@@ -105,7 +108,9 @@ namespace PSManagement.Api.Controllers.Employees
}
#endregion Get Requests
#region Post Requests
[HttpPost("SyncEmployees")]
public async Task<IActionResult> Post()
{
......@@ -115,16 +120,20 @@ namespace PSManagement.Api.Controllers.Employees
}
#endregion Post Requests
#region Put Request
[HttpPut("UpdateWorkHours")]
public async Task<IActionResult> PutUpdateWorkHours(UpdateEmployeeWorkHoursRequest request)
{
UpdateEmployeeWorkHoursCommand query =_mapper.Map<UpdateEmployeeWorkHoursCommand>(request);
UpdateEmployeeWorkHoursCommand query = _mapper.Map<UpdateEmployeeWorkHoursCommand>(request);
var result = await _sender.Send(query);
return HandleResult(result);
}
#endregion Put Requests
}
}
......@@ -3,7 +3,6 @@ using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.FinancialSpends.UseCases.Commands.CreateFinancialSpendItem;
using PSManagement.Application.FinancialSpends.UseCases.Commands.RemoveFinancialSpendingItem;
using PSManagement.Application.FinancialSpends.UseCases.Commands.UpateFinancialSpendingItem;
......@@ -11,12 +10,13 @@ using PSManagement.Application.FinancialSpends.UseCases.Queries.GetFinancialSpen
using PSManagement.Application.FinancialSpends.UseCases.Queries.GetFinancialSpendingByProject;
using PSManagement.Contracts.FinancialSpends.Requests;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Presentation.Controllers.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.FinancialSpends
namespace PSManagement.Presentation.Controllers.FinancialSpends
{
[Route("api/[controller]")]
[ApiController]
......@@ -57,7 +57,7 @@ namespace PSManagement.Api.Controllers.FinancialSpends
}
[HttpGet]
public async Task<IActionResult> Get( [FromQuery]GetFinancialSpendItemByIdRequest request)
public async Task<IActionResult> Get([FromQuery] GetFinancialSpendItemByIdRequest request)
{
var query = _mapper.Map<GetFinancialSpendItemByIdQuery>(request);
......@@ -77,9 +77,10 @@ namespace PSManagement.Api.Controllers.FinancialSpends
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete([FromQuery] RemoveFinancialSpendItemRequest request,[FromRoute]int id)
public async Task<IActionResult> Delete([FromQuery] RemoveFinancialSpendItemRequest request, [FromRoute] int id)
{
if (id != request.Id) {
if (id != request.Id)
{
Result.Conflict();
}
......
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Projects.UseCases.Commands.AddAttachment;
using PSManagement.Application.Projects.UseCases.Commands.CreateProject;
using PSManagement.Application.Projects.UseCases.Queries.GetProject;
......@@ -24,8 +23,9 @@ using PSManagement.Application.Projects.UseCases.Commands.CompletePlaningProject
using PSManagement.Application.Contracts.Providers;
using PSManagement.Application.Projects.UseCases.Commands.CancelProject;
using PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManager;
using PSManagement.Presentation.Controllers.ApiBase;
namespace PSManagement.Api.Controllers.Projects
namespace PSManagement.Presentation.Controllers.Projects
{
[Route("api/[controller]")]
[ApiController]
......@@ -48,9 +48,9 @@ namespace PSManagement.Api.Controllers.Projects
[HttpGet]
public async Task<IActionResult> Get([FromQuery]ListAllProjectsRequest request)
public async Task<IActionResult> Get([FromQuery] ListAllProjectsRequest request)
{
var query = _mapper.Map<ListAllProjectsQuery>(request);
var query = _mapper.Map<ListAllProjectsQuery>(request);
var result = _mapper.Map<Result<IEnumerable<ProjectDetailsResponse>>>(await _sender.Send(query));
......@@ -67,9 +67,9 @@ namespace PSManagement.Api.Controllers.Projects
return HandleResult(_mapper.Map<Result<IEnumerable<ProjectDetailsResponse>>>(result));
}
[HttpGet("ByProjectManager")]
public async Task<IActionResult> GetByPojectManager([FromQuery] GetProjectsByProjectManagerRequest request )
public async Task<IActionResult> GetByPojectManager([FromQuery] GetProjectsByProjectManagerRequest request)
{
GetProjectsByFilterQuery query = _mapper.Map<GetProjectsByFilterQuery>(request);
......@@ -81,11 +81,11 @@ namespace PSManagement.Api.Controllers.Projects
[HttpGet("GetParticipants/{id}")]
public async Task<IActionResult> GetParticipants(int id)
{
GetProjectParticipantsQuery query = new (id);
GetProjectParticipantsQuery query = new(id);
var result = await _sender.Send(query);
return HandleResult( _mapper.Map<Result<IEnumerable<EmployeeParticipateResponse>>>(result));
return HandleResult(_mapper.Map<Result<IEnumerable<EmployeeParticipateResponse>>>(result));
}
......@@ -155,13 +155,14 @@ namespace PSManagement.Api.Controllers.Projects
}
[HttpPost("CancelProject/{id}")]
public async Task<IActionResult> PostCancelProjectRequest(int id )
public async Task<IActionResult> PostCancelProjectRequest(int id)
{
if (_currentUserProvider.EmployeeId is not null) {
if (_currentUserProvider.EmployeeId is not null)
{
int employeeId = _currentUserProvider.EmployeeId.Value;
var query = new CancelProjectCommand(id,employeeId);
var query = new CancelProjectCommand(id, employeeId);
var result = await _sender.Send(query);
......@@ -183,7 +184,7 @@ namespace PSManagement.Api.Controllers.Projects
}
[HttpPost("CompleteProject")]
public async Task<IActionResult> PostCompleteProjectRequest(CompleteProjectRequest request )
public async Task<IActionResult> PostCompleteProjectRequest(CompleteProjectRequest request)
{
var query = _mapper.Map<CompleteProjectCommand>(request);
......@@ -231,16 +232,17 @@ namespace PSManagement.Api.Controllers.Projects
return HandleResult(_mapper.Map<Result<ProjectDetailsResponse>>(response));
}
else {
else
{
return HandleResult(result);
}
}
[HttpPost("AddAttachment")]
public async Task<IActionResult> PostAddAttachment( [FromForm]AddAttachmentRequest request)
public async Task<IActionResult> PostAddAttachment([FromForm] AddAttachmentRequest request)
{
var command = _mapper.Map<AddAttachmentCommand>(request);
var result = await _sender.Send(command);
......@@ -248,7 +250,7 @@ namespace PSManagement.Api.Controllers.Projects
}
[HttpGet("Attachments/{id}")]
public async Task<IActionResult> GetAttachments([FromQuery]GetProjectAttachmentsRequest request)
public async Task<IActionResult> GetAttachments([FromQuery] GetProjectAttachmentsRequest request)
{
var query = _mapper.Map<GetProjectAttachmentsQuery>(request);
var result = await _sender.Send(query);
......
......@@ -3,17 +3,17 @@ using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.ProjectsTypes.UseCases.Commands.CreateNewType;
using PSManagement.Application.ProjectsTypes.UseCases.Queries.GetProjectsTypes;
using PSManagement.Application.ProjectsTypes.UseCases.Queries.GetTypeById;
using PSManagement.Contracts.ProjectsTypes.Request;
using PSManagement.Presentation.Controllers.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers
namespace PSManagement.Presentation.Controllers.ProjectsTypes
{
[Route("api/[controller]")]
[ApiController]
......
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Contracts.Authorization;
using PSManagement.Presentation.Controllers.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Roles
namespace PSManagement.Presentation.Controllers.Roles
{
[Route("api/[controller]")]
public class RolesController : APIController
......@@ -35,7 +35,7 @@ namespace PSManagement.Api.Controllers.Roles
return HandleResult(getRolesById);
}
[Authorize( Roles = "Admin")]
[Authorize(Roles = "Admin")]
[HttpPost("Create")]
public async Task<IActionResult> CreateRoleAsync(string roleName)
{
......
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Contracts.Authorization;
using PSManagement.Presentation.Controllers.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Roles
namespace PSManagement.Presentation.Controllers.Roles
{
[Route("api/[controller]")]
public class UserRolesController : APIController
......
......@@ -3,7 +3,6 @@ using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Steps.UseCases.Commands.ChangeStepWeight;
using PSManagement.Application.Steps.UseCases.Commands.RemoveStep;
using PSManagement.Application.Steps.UseCases.Commands.UpdateCompletionRatio;
......@@ -17,7 +16,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PSManagement.Contracts.Tracks.Response;
namespace PSManagement.Api.Controllers.Steps
using PSManagement.Presentation.Controllers.ApiBase;
namespace PSManagement.Presentation.Controllers.Steps
{
[Route("api/[controller]")]
public class StepsController : APIController
......@@ -32,9 +33,9 @@ namespace PSManagement.Api.Controllers.Steps
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id )
public async Task<IActionResult> Get(int id)
{
var query = new GetStepByIdQuery(id) ;
var query = new GetStepByIdQuery(id);
var result = _mapper.Map<Result<StepResponse>>(await _sender.Send(query));
......@@ -52,12 +53,13 @@ namespace PSManagement.Api.Controllers.Steps
}
[HttpPut("ChangeStepWeight/{id}")]
public async Task<IActionResult> PutChangeStepWeight(ChangeStepWeightRequest request,[FromRoute]int id)
public async Task<IActionResult> PutChangeStepWeight(ChangeStepWeightRequest request, [FromRoute] int id)
{
if (request.StepId != id) {
if (request.StepId != id)
{
return HandleResult(Result.NotFound("the step not found"));
}
var query = _mapper.Map<ChangeStepWeightCommand>(request); ;
var query = _mapper.Map<ChangeStepWeightCommand>(request); ;
var result = _mapper.Map<Result>(await _sender.Send(query));
......@@ -68,7 +70,7 @@ namespace PSManagement.Api.Controllers.Steps
[HttpGet("StepTrackHistory")]
public async Task<IActionResult> Get([FromQuery] GetStepTrackHistoryRequest request)
{
var query =_mapper.Map<GetStepTrackHistoryQuery>(request);
var query = _mapper.Map<GetStepTrackHistoryQuery>(request);
var result = _mapper.Map<Result<IEnumerable<StepTrackResponse>>>(await _sender.Send(query));
......@@ -86,11 +88,11 @@ namespace PSManagement.Api.Controllers.Steps
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete([FromRoute]int id)
public async Task<IActionResult> Delete([FromRoute] int id)
{
var query = new RemoveStepCommand(id);
var result =await _sender.Send(query);
var result = await _sender.Send(query);
return HandleResult(result);
}
......
......@@ -2,7 +2,6 @@
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Tracks.UseCaes.Commands.AddEmployeeTrack;
using PSManagement.Application.Tracks.UseCaes.Commands.AddStepTrack;
using PSManagement.Application.Tracks.UseCaes.Commands.CompleteTrack;
......@@ -17,10 +16,11 @@ using PSManagement.Application.Tracks.UseCaes.Queries.GetTracksByProject;
using PSManagement.Application.Tracks.UseCaes.Queries.GetUncompletedTracks;
using PSManagement.Contracts.Tracks.Requests;
using PSManagement.Contracts.Tracks.Response;
using PSManagement.Presentation.Controllers.ApiBase;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Tracks
namespace PSManagement.Presentation.Controllers.Tracks
{
[Route("api/[controller]")]
public class TracksController : APIController
......@@ -46,7 +46,7 @@ namespace PSManagement.Api.Controllers.Tracks
}
[HttpGet("GetStepsTrack/{id}")]
public async Task<IActionResult> GetStepsTrack([FromRoute]int id)
public async Task<IActionResult> GetStepsTrack([FromRoute] int id)
{
var query = new GetStepsTrackQuery(id);
......@@ -86,7 +86,7 @@ namespace PSManagement.Api.Controllers.Tracks
}
[HttpPost("AddStepTrack")]
public async Task<IActionResult>PostStepTrack(AddStepTrackRequest request)
public async Task<IActionResult> PostStepTrack(AddStepTrackRequest request)
{
var command = _mapper.Map<AddStepTrackCommand>(request);
......@@ -110,7 +110,7 @@ namespace PSManagement.Api.Controllers.Tracks
{
var command = _mapper.Map<CompleteTrackCommand>(request);
var result =await _sender.Send(command);
var result = await _sender.Send(command);
return HandleResult(result);
}
......@@ -120,7 +120,7 @@ namespace PSManagement.Api.Controllers.Tracks
{
var command = _mapper.Map<RemoveTrackCommand>(request);
var result =await _sender.Send(command);
var result = await _sender.Send(command);
return HandleResult(result);
}
......@@ -154,12 +154,12 @@ namespace PSManagement.Api.Controllers.Tracks
{
var command = _mapper.Map<UpdateEmployeeWorkTrackCommand>(request);
var result =await _sender.Send(command);
var result = await _sender.Send(command);
return HandleResult(result);
}
[HttpPut("UpdateStepTrack")]
public async Task<IActionResult> PutStepTrack(UpdateStepTrackRequest request)
{
......
......@@ -7,7 +7,6 @@ namespace PSManagement.Presentaion.DI
{
public static IServiceCollection AddPresentation(this IServiceCollection services)
{
return services;
}
......
......@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
......@@ -15,8 +16,4 @@
<ProjectReference Include="..\PSManagement.Contracts\PSManagement.Contracts.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
</Project>
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