public async Task <IActionResult> Get([FromRoute] int userId)
        {
            _claimsManager.Init(HttpContext.User);
            _logger.LogInformation(
                $"User with id: {_claimsManager.GetUserIdClaim()} attempting to access nutrition target for userId: {userId}");

            if (!_claimsManager.VerifyUserId(userId))
            {
                _logger.LogInformation($"User with id: {_claimsManager.GetUserIdClaim()} was denied access to this resource");
                return(Forbid());
            }

            var nutritionTarget = await _context
                                  .NutritionTargets
                                  .Where(_ => _.UserId == userId)
                                  .GetNutritionTarget()
                                  .FirstOrDefaultAsync();

            _logger.LogInformation($"result from query: {JsonSerializer.Serialize(nutritionTarget)}");
            _logger.LogInformation("returning result");

            return(Ok(nutritionTarget));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get([FromRoute] int userId)
        {
            _claimsManager.Init(HttpContext.User);
            _logger.LogInformation(
                $"User with id: {_claimsManager.GetUserIdClaim()} attempting to access resistance training sessions for userId: {userId}");

            if (!_claimsManager.VerifyUserId(userId))
            {
                _logger.LogInformation($"User with id: {_claimsManager.GetUserIdClaim()} was denied access to this resource");
                return(Forbid());
            }

            var trainingSessions = await _context
                                   .Users
                                   .Where(_ => _.UserId == userId)
                                   .GetResistanceTrainingSessionsDTOs()
                                   .FirstOrDefaultAsync();


            _logger.LogInformation(
                $"Queried Resistance Training Sessions:\n{JsonSerializer.Serialize(trainingSessions, _jsonSerializerOptions)}");
            return(Ok(trainingSessions));
        }
        public async Task <IActionResult> Get(
            [FromRoute] int userId,
            [FromQuery] int pageSize = 10,
            [FromQuery] int page     = 0,
            [FromQuery] DailyNutritionLogSortingOption orderBy = DailyNutritionLogSortingOption.mostRecent)
        {
            _claimsManager.Init(HttpContext.User);

            if (!_claimsManager.VerifyUserId(userId))
            {
                _logger.LogInformation(
                    $"User with id: {_claimsManager.GetUserIdClaim()} attempting to access nutrition target for userId: {userId}");
                return(Forbid());
            }

            var dailyNutritionLogs = await _context
                                     .DailyNutritionLogs
                                     .Where(_ => _.UserId == userId)
                                     .GetDailyNutritionLogDTOs()
                                     .OrderDailyNutritionLogDTOsBy(orderBy)
                                     .ToListAsync();

            return(Ok(dailyNutritionLogs));
        }