| | 1 | | using Api.Extensions; |
| | 2 | | using Api.Request.Parameters; |
| | 3 | | using Application.service; |
| | 4 | | using Application.Service; |
| | 5 | | using Infrastructure.Entity; |
| | 6 | | using Microsoft.AspNetCore.Mvc; |
| | 7 | |
|
| | 8 | | namespace Api.Controller.v1; |
| | 9 | |
|
| | 10 | | [ApiController] |
| | 11 | | [Route("api/[controller]/[action]")] |
| | 12 | | [ApiVersion("1")] |
| | 13 | | [Produces("application/json")] |
| | 14 | | public class CustomerController : ControllerBase { |
| | 15 | | private readonly ILogger<CustomerController> _logger; |
| | 16 | | private readonly CustomerService _service; |
| | 17 | |
|
| 4 | 18 | | public CustomerController(ILogger<CustomerController> logger, CustomerService service) { |
| 2 | 19 | | _logger = logger; |
| 2 | 20 | | _service = service; |
| 2 | 21 | | } |
| | 22 | |
|
| | 23 | | [HttpGet] |
| | 24 | | [ProducesResponseType(typeof(customer[]), StatusCodes.Status200OK)] |
| 1 | 25 | | public async Task<IActionResult> GetCustomers(CancellationToken ct) { |
| 1 | 26 | | var results = await _service.FindAll(ct); |
| 1 | 27 | | _logger.LogResults(typeof(employee), results); |
| 1 | 28 | | return Ok(results); |
| 1 | 29 | | } |
| | 30 | |
|
| | 31 | | [HttpGet] |
| | 32 | | [ProducesResponseType(typeof(customer), StatusCodes.Status200OK)] |
| | 33 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| 1 | 34 | | public async Task<IActionResult> GetCustomer([FromQuery] CustomerRequest req, CancellationToken ct) { |
| 1 | 35 | | var result = await _service.FindById(req.CustomerID, ct); |
| 1 | 36 | | if (result is null) { |
| 0 | 37 | | _logger.LogInformation("Customer {CustomerId} not found", req.CustomerID); |
| 0 | 38 | | return NotFound(new ProblemDetails { |
| 0 | 39 | | Title = "Customer not found", |
| 0 | 40 | | Status = StatusCodes.Status404NotFound, |
| 0 | 41 | | Detail = $"Not customer with id „{req.CustomerID}“ exists", |
| 0 | 42 | | }); |
| | 43 | | } |
| 1 | 44 | | return Ok(result); |
| 1 | 45 | | } |
| | 46 | |
|
| | 47 | |
|
| | 48 | | } |