Commit 7fd9449c authored by hasan khaddour's avatar hasan khaddour

Add step controller and financial spend contoller

parent 3604a56e
using Ardalis.Result;
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;
using PSManagement.Application.FinancialSpends.UseCases.Queries.GetFinancialSpendingById;
using PSManagement.Application.FinancialSpends.UseCases.Queries.GetFinancialSpendingByProject;
using PSManagement.Contracts.FinancialSpends.Requests;
using PSManagement.Contracts.Projects.Response;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.FinancialSpends
{
[Route("api/[controller]")]
[ApiController]
public class FinancialSpendsController : APIController
{
private readonly IMediator _sender;
private readonly IMapper _mapper;
public FinancialSpendsController(IMapper mapper, IMediator sender)
{
_mapper = mapper;
_sender = sender;
}
[HttpPost]
public async Task<IActionResult> Post(CreateFinancialSpendItemRequest request)
{
var query = _mapper.Map<CreateFinancialSpendItemCommand>(request);
var result = await _sender.Send(query);
return Ok(result);
}
[HttpGet]
public async Task<IActionResult> Get( [FromQuery]GetFinancialSpendItemByIdRequest request)
{
var query = _mapper.Map<GetFinancialSpendItemByIdQuery>(request);
var result = await _sender.Send(query);
return Ok(_mapper.Map<Result<FinancialSpendingResponse>>(result)); ;
}
[HttpGet("GetByProject")]
public async Task<IActionResult> GetByProject([FromQuery] GetFinancialSpendItemByProjecRequest request)
{
var query = _mapper.Map<GetFinancialSpendItemByProjectQuery>(request);
var result = await _sender.Send(query);
return Ok(_mapper.Map<Result<IEnumerable<FinancialSpendingResponse>>>(result)); ;
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete( RemoveFinancialSpendItemRequest request,[FromRoute]int id)
{
if (id != request.Id) {
Result.Conflict();
}
var query = _mapper.Map<RemoveFinancialSpendItemCommand>(request);
var result = await _sender.Send(query);
return Ok(result); ;
}
[HttpPut("{id}")]
public async Task<IActionResult> Put(UpdateFinancialSpendItemRequest request, [FromRoute] int id)
{
if (id != request.Id)
{
Result.Conflict();
}
var query = _mapper.Map<UpdateFinancialSpendItemCommand>(request);
var result = await _sender.Send(query);
return Ok(result); ;
}
}
}
using Microsoft.AspNetCore.Http;
using Ardalis.Result;
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;
using PSManagement.Application.Steps.UseCases.Queries.GetStepById;
using PSManagement.Application.Steps.UseCases.Queries.GetStepsByProject;
using PSManagement.Application.Steps.UseCases.Queries.GetStepTrackHistory;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Contracts.Steps.Requests;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -11,5 +22,78 @@ namespace PSManagement.Api.Controllers.Steps
[Route("api/[controller]")]
public class StepsController : APIController
{
private readonly IMapper _mapper;
private readonly IMediator _sender;
public StepsController(IMediator sender, IMapper mapper)
{
_sender = sender;
_mapper = mapper;
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id )
{
var query = new GetStepByIdQuery(id) ;
var result = _mapper.Map<Result<StepResponse>>(await _sender.Send(query));
return Ok(result);
}
[HttpGet("ByProject")]
public async Task<IActionResult> GetByProject(GetStepsByProjectRequest request)
{
GetStepsByProjectQuery query = _mapper.Map<GetStepsByProjectQuery>(request);
var result = _mapper.Map<Result<IEnumerable<StepResponse>>>(await _sender.Send(query));
return Ok(result);
}
[HttpPost("{id}")]
public async Task<IActionResult> ChangeStepWeight(ChangeStepWeightRequest request,[FromRoute]int id)
{
if (request.StepId != id) {
return Ok(Result.NotFound("the step not found"));
}
var query = _mapper.Map<ChangeStepWeightCommand>(request); ;
var result = _mapper.Map<Result>(await _sender.Send(query));
return Ok(result);
}
[HttpGet("StepTrackHistory")]
public async Task<IActionResult> Get(GetStepTrackHistoryRequest request)
{
var query =_mapper.Map<GetStepTrackHistoryQuery>(request);
var result = _mapper.Map<Result<IEnumerable<StepTrackResponse>>>(await _sender.Send(query));
return Ok(result);
}
[HttpPost]
public async Task<IActionResult> UpdateCompleteionRatio(UpdateCompletionRatioRequest request)
{
var query = _mapper.Map<UpdateCompletionRatioCommand>(request);
var result = _mapper.Map<Result>(await _sender.Send(query));
return Ok(result);
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete([FromRoute]int id)
{
var query = new RemoveStepCommand(id);
var result = _mapper.Map<Result>(await _sender.Send(query));
return Ok(result);
}
}
}
......@@ -21,10 +21,13 @@ namespace PSManagement.Api.DI
services.AddApiCors();
services.AddScoped<Mapper>();
services.AddAutoMapper(
typeof(CustomerMapperConfiguration),
typeof(ProjectMapperConfiguration),
typeof(MapperConfigurations));
services.AddAutoMapper(cfg => {
cfg.AddProfile<CustomerMapperConfiguration>();
cfg.AddProfile<ProjectMapperConfiguration>();
cfg.AddProfile<MappersConfigurations>();
});
return services;
}
......
......@@ -7,9 +7,9 @@ using System.Threading.Tasks;
namespace PSManagement.Api.Mappers
{
public class MapperConfigurations :Profile
public class MappersConfigurations :Profile
{
public MapperConfigurations()
public MappersConfigurations()
{
CreateMap(typeof(Result<>), typeof(Result<>)).ConvertUsing(typeof(ResultToResultConverter<,>));
}
......
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