Guest User

Untitled

a guest
Jul 30th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System.Diagnostics;
  4. using webapi.Integration.Interfaces;
  5. using webapi.Integration.Response;
  6. using System;
  7. namespace webapi.Controllers
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class CepController : ControllerBase
  12. {
  13. private readonly IViaCepIntegration _viaCepIntegration;
  14.  
  15. public CepController(IViaCepIntegration viaCepIntegration)
  16. {
  17. _viaCepIntegration = viaCepIntegration;
  18. }
  19.  
  20. [HttpGet("{cep}")]
  21. public async Task<ActionResult<ViaCepResponse>> ListarDadosEndereco(string cep)
  22. {
  23. try
  24. {
  25. var responseData = await _viaCepIntegration.ObterDadosViaCep(cep);
  26.  
  27. if (responseData == null)
  28. {
  29. return BadRequest("CEP não encontrado.");
  30. }
  31. return Ok(responseData);
  32.  
  33. }
  34.  
  35. catch (Exception e)
  36.  
  37. {
  38. Console.WriteLine(e);
  39. return BadRequest("Erro."+e);
  40. }
  41.  
  42. }
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment