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