public async Task <IActionResult> GetProductOptionById(Guid id) { try { _logger.LogDebug($"Received {nameof(GetProductOptionById)} request with Id {id}"); var productOption = await _service.GetByIdAsync(id); _logger.LogDebug($"Returned {nameof(GetProductOptionById)} response with " + $"product option {{@ProductOption}}", productOption); return(Ok(_mapper.Map <ProductOptionResponseDto>(productOption))); } catch (ProductOptionNotFoundException exception) { _logger.LogError(exception, exception.Message); return(NotFound(exception.Message)); } }
public async Task <IActionResult> GetByIdAsync(Guid productId, Guid productOptionId) { _logger.Information($"Executing GET - '/products/{productId}/options/{productOptionId}'"); if (!ModelState.IsValid) { return(WebApi.Response.Error(new Error(ErrorCode.BadRequest, AppConstants.InvalidRequest))); } try { var result = await _productOptionService.GetByIdAsync(productId, productOptionId); return(result.IsSuccess() ? WebApi.Response.Ok(result.Data) : WebApi.Response.Error(result.Error)); } catch (Exception ex) { _logger.Error("An error has occurred while getting product option by Id. ProductId: {productId}, ProductOptionId: {productOptionId}, Details: {message}", productId, productOptionId, ex.Message); } return(WebApi.Response.Fatal()); }