proposal-system/api/src/ProposalSystem.Api/Controllers/CustomersController.cs

38 lines
1 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ProposalSystem.Application.DTOs;
using ProposalSystem.Application.Interfaces;
namespace ProposalSystem.Api.Controllers;
[ApiController]
[Route("api/customers")]
[Authorize]
public class CustomersController : ControllerBase
{
private readonly ICustomerService _customerService;
public CustomersController(ICustomerService customerService)
{
_customerService = customerService;
}
[HttpGet]
public async Task<ActionResult<IReadOnlyList<CustomerResponse>>> Search(
[FromQuery] string? query,
CancellationToken ct)
{
var result = await _customerService.SearchAsync(query, ct);
return Ok(result);
}
[HttpPost]
public async Task<ActionResult<CustomerResponse>> Create(
[FromBody] CreateCustomerRequest request,
CancellationToken ct)
{
var result = await _customerService.CreateAsync(request, ct);
return Created($"/api/customers/{result.Id}", result);
}
}