| | | 1 | | /* |
| | | 2 | | * eventlistController.cs |
| | | 3 | | * event-list |
| | | 4 | | * |
| | | 5 | | * Created by Tiago Amaral on 06/09/2025. |
| | | 6 | | * Copyright ©2024 Tiago Amaral. All rights reserved. |
| | | 7 | | */ |
| | | 8 | | |
| | | 9 | | using Microsoft.AspNetCore.Mvc; |
| | | 10 | | using event_list.modules.eventlist.services; |
| | | 11 | | using event_list.modules.eventlist.storage; |
| | | 12 | | using event_list.shared.exceptionsMessage; |
| | | 13 | | using event_list.shared.response_default; |
| | | 14 | | |
| | | 15 | | namespace event_list.modules.eventlist.infra; |
| | | 16 | | |
| | | 17 | | [ApiController] |
| | | 18 | | [Route("api/eventos")] |
| | | 19 | | |
| | | 20 | | public class EventListController : ControllerBase |
| | | 21 | | { |
| | | 22 | | |
| | | 23 | | private readonly IEventListServices _eventListServices; |
| | | 24 | | |
| | 5 | 25 | | public EventListController(IEventListServices eventListServices) |
| | 5 | 26 | | { |
| | 5 | 27 | | this._eventListServices = eventListServices; |
| | 5 | 28 | | } |
| | | 29 | | |
| | | 30 | | // GET [HOST]/api/eventos |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Lista todos os Eventos |
| | | 34 | | /// </summary> |
| | | 35 | | /// <description>Retorna uma lista de eventos.</description> |
| | | 36 | | [HttpGet] |
| | 1 | 37 | | public IActionResult GetAllAsync() => Ok(new ResponseDefault(200, string.Empty, this._eventListServices.GetAll())); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Consulta somente um evento usando sua identificação. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <param name="id"></param> |
| | | 43 | | /// <parameters>id - Identificador do evento.</parameters> |
| | | 44 | | /// <returns>Retorna um evento</returns> |
| | | 45 | | [HttpGet("id")] |
| | 1 | 46 | | public async Task<IActionResult> GetById(Guid id) => Ok(new ResponseDefault(200, string.Empty, await this._eventList |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Cria novo evento |
| | | 50 | | /// </summary> |
| | | 51 | | /// <param name="data"></param> |
| | | 52 | | /// <returns>Permite registrar um novo evento</returns> |
| | | 53 | | [HttpPost] |
| | 2 | 54 | | public async Task<IActionResult> Create([FromBody] EventFormDto dto) { |
| | | 55 | | |
| | 2 | 56 | | if (!ModelState.IsValid) |
| | 1 | 57 | | { |
| | 1 | 58 | | return BadRequest(ModelState); |
| | | 59 | | } |
| | | 60 | | |
| | 1 | 61 | | await this._eventListServices.CreateAsync(dto); |
| | 1 | 62 | | return Ok(new ResponseDefault( 200, ExceptionsMessages.SuccessCreateEvent, null)); |
| | 2 | 63 | | } |
| | | 64 | | |
| | | 65 | | // GET [HOST]/api/eventos/{id} |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Apaga evento |
| | | 69 | | /// </summary> |
| | | 70 | | /// <param name="id"></param> |
| | | 71 | | /// <returns>Permite remover um evento usando usa idenrtificação</returns> |
| | | 72 | | [HttpDelete] |
| | | 73 | | public async Task<IActionResult> DeleteById(Guid id) |
| | 1 | 74 | | { |
| | 1 | 75 | | await this._eventListServices.DeleteAsync(id); |
| | 1 | 76 | | return Ok(new ResponseDefault( 200, ExceptionsMessages.SuccessDeleteEvent, null)); |
| | 1 | 77 | | } |
| | | 78 | | } |