CurrenciesController.cs
1,034 bytes
| 1 | using App.BLL.Services; |
|---|---|
| 2 | using App.DTO.Mappers; |
| 3 | using App.DTO.v1; |
| 4 | using Asp.Versioning; |
| 5 | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| 6 | using Microsoft.AspNetCore.Authorization; |
| 7 | using Microsoft.AspNetCore.Mvc; |
| 8 | using System.Net; |
| 9 | |
| 10 | namespace WebApp.ApiControllers; |
| 11 | |
| 12 | [ApiVersion("1.0")] |
| 13 | [Route("api/v{version:apiVersion}/[controller]")] |
| 14 | [ApiController] |
| 15 | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| 16 | public class CurrenciesController : ControllerBase |
| 17 | { |
| 18 | private readonly ITripService _tripService; |
| 19 | |
| 20 | public CurrenciesController(ITripService tripService) |
| 21 | { |
| 22 | _tripService = tripService; |
| 23 | } |
| 24 | |
| 25 | // GET: api/v1/currencies |
| 26 | [HttpGet] |
| 27 | [AllowAnonymous] |
| 28 | [Produces("application/json")] |
| 29 | [ProducesResponseType<List<CurrencyDto>>((int)HttpStatusCode.OK)] |
| 30 | public async Task<ActionResult<List<CurrencyDto>>> GetCurrencies() |
| 31 | { |
| 32 | var currencies = await _tripService.GetAllCurrenciesAsync(); |
| 33 | return Ok(currencies.Select(CurrencyMapper.MapToDto).ToList()); |
| 34 | } |
| 35 | } |
| 36 | |