59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ProximaContracts.Application.Contracts.Services;
|
|
using ProximaContracts.Domain.Contracts.DTOs.Request;
|
|
|
|
namespace ProximaContracts.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ContractsController(IContractService service) : ControllerBase
|
|
{
|
|
private readonly IContractService _service = service;
|
|
|
|
|
|
[HttpGet("GetAll")]
|
|
public async Task<IActionResult> GetContracts()
|
|
{
|
|
var response = await _service.GetContracts();
|
|
return response.Any() ? Ok(response) : NotFound();
|
|
}
|
|
|
|
|
|
[HttpGet("GetById")]
|
|
public async Task<IActionResult> GetContractsById([FromQuery] ContractByIdRequestDto dto)
|
|
{
|
|
var response = await _service.GetContractById(dto);
|
|
return response != null ? Ok(response) : NotFound();
|
|
}
|
|
|
|
[HttpPost("CreateContract")]
|
|
public async Task<IActionResult> CreateContract([FromBody] CreateContractRequestDto dto)
|
|
{
|
|
var result = await _service.CreateContract(dto);
|
|
if(result.IsCreated)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(result);
|
|
}
|
|
}
|
|
|
|
[HttpPut("UpdateContract")]
|
|
public async Task<IActionResult> UpdateContract([FromBody] UpdateContractRequestDto dto)
|
|
{
|
|
var result = await _service.UpdateContract(dto);
|
|
|
|
if (result.IsUpdated)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(result);
|
|
}
|
|
}
|
|
}
|
|
}
|