public async Task <IActionResult> GetById(string id) { var result = await imagesService.GetById(id); var mapped = mapper.Map <ImagesResponse>(result); return(Ok(mapped)); }
public async Task <HttpResponseData> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "images/{imgid:Guid}")] HttpRequestData req, FunctionContext executionContext, string imgid) { var logger = executionContext.GetLogger(nameof(ImagesFunction)); logger.LogInformation($"C# HTTP trigger function GET images '{imgid}'"); var response = req.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Content-Type", "application/json"); if (!Guid.TryParse(imgid, out var imgGuid)) { logger.LogInformation($"Invalid GUID to images, exiting with bad request"); response.WriteString(JsonSerializer.Serialize(new { Error = "BadId", Message = $"Image ID not in proper format: {imgid}" }, JsonOptions)); response.StatusCode = HttpStatusCode.BadRequest; return(response); } // Once here, query the Images service to do further work try { logger.LogInformation($"Getting image {imgGuid}"); var img = await ImagesService.GetById(imgGuid); var stringBody = JsonSerializer.Serialize(TranslateImage(img), JsonOptions); response.WriteString(stringBody); } catch (Exception ex) { logger.LogInformation($"Exception attempting to retrieve and serialize img: {ex.Message} STACK: {ex.StackTrace}"); ResponseJsonHandler.SetExceptionToHttpResponse(ex, response, JsonOptions); } logger.LogInformation($"Sending response to client"); return(response); }
public async Task <ActionResult <ImageModel> > Get(string id) { return(Ok(await _imagesService.GetById(id))); }