Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateGoal(int goalId, [FromBody] UpdateGoalRequestModel updateGoalRequestModel)
        {
            try
            {
                System.Threading.Thread.Sleep(1000);
                var goalExists = await _goalRepository.GoalExists(updateGoalRequestModel.GoalName);

                if (goalExists)
                {
                    return(BadRequest(new ApiResponseBadRequestResult()
                    {
                        ErrorMessage = $"Goal { updateGoalRequestModel.GoalName } already exists"
                    }));
                }

                await _goalRepository.UpdateGoal(goalId, updateGoalRequestModel.GoalName);

                return(Ok(new ApiResponseOKResult()
                {
                    StatusCode = StatusCodes.Status200OK, Data = updateGoalRequestModel
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to update goal");
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponseFailure()
                {
                    ErrorMessage = "Failed to update goal"
                }));
            }
        }