Skip to content

Instantly share code, notes, and snippets.

@pedrovasconcellos
Created December 3, 2018 06:56
Show Gist options
  • Save pedrovasconcellos/f966879e9f6fb22fa4b1a75af37cca46 to your computer and use it in GitHub Desktop.
Save pedrovasconcellos/f966879e9f6fb22fa4b1a75af37cca46 to your computer and use it in GitHub Desktop.
Example of a documented endpoint
/// <summary>
/// Realiza a consulta por id do carro
/// </summary>
/// <param name="id"></param>
/// <response code="200">Ok</response>
/// <response code="400">Bad Request</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
[HttpGet("{id}")]
[ProducesResponseType(typeof(IList<CarModel>),200)]
[ProducesResponseType(typeof(IList<Error>),400)]
[ProducesResponseType(404)]
[ProducesResponseType(500)]
public async Task<ActionResult<IList<CarModel>>> GetById(int id)
{
var entity = this._context.Car.Include(x => x.Color).FirstOrDefault(x => x.Id == id);
if(entity == null) return await Task.FromResult(this.NotFound());
return await Task.FromResult(this.Ok(_mapper.Map<List<CarModel>>(entity)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment