public async Task <ActionResult <CursorPaginatedResponse <ExerciseForReturnDto> > > GetExercisesForEquipmentAsync(int id, [FromQuery] CursorPaginationParams searchParams)
        {
            var exerciseSearchParams = new ExerciseSearchParams
            {
                First        = searchParams.First,
                After        = searchParams.After,
                Last         = searchParams.Last,
                Before       = searchParams.Before,
                IncludeTotal = searchParams.IncludeTotal,
                EquipmentId  = new List <int> {
                    id
                }
            };

            var exercises = await exerciseRepository.SearchAsync(exerciseSearchParams);

            var paginatedResponse = CursorPaginatedResponse <ExerciseForReturnDto> .CreateFrom(exercises, mapper.Map <IEnumerable <ExerciseForReturnDto> >);

            return(Ok(paginatedResponse));
        }
Example #2
0
        public async Task <ActionResult <CursorPaginatedResponse <ExerciseForReturnDetailedDto> > > GetFavoriteExercisesForUserDetailedAsync(int userId, [FromQuery] ExerciseSearchParams searchParams)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var exercises = await userRepository.GetFavoriteExercisesForUserDetailedAsync(userId, searchParams);

            var paginatedResponse = CursorPaginatedResponse <ExerciseForReturnDetailedDto> .CreateFrom(exercises, mapper.Map <IEnumerable <ExerciseForReturnDetailedDto> >);

            return(Ok(paginatedResponse));
        }
Example #3
0
        public Task <CursorPagedList <Exercise> > GetFavoriteExercisesForUserDetailedAsync(int userId, ExerciseSearchParams searchParams)
        {
            IQueryable <Exercise> query = context.Users
                                          .Where(u => u.Id == userId)
                                          .SelectMany(u => u.FavoriteExercises.Select(fe => fe.Exercise));

            return(exerciseRepository.SearchDetailedAsync(query, searchParams));
        }
Example #4
0
        public async Task <ActionResult <CursorPaginatedResponse <ExerciseForReturnDetailedDto> > > GetExercisesDetailedAsync([FromQuery] ExerciseSearchParams searchParams)
        {
            var exercises = await exerciseRepository.SearchDetailedAsync(searchParams);

            var paginatedResponse = CursorPaginatedResponse <ExerciseForReturnDetailedDto> .CreateFrom(exercises, mapper.Map <IEnumerable <ExerciseForReturnDetailedDto> >);

            return(Ok(paginatedResponse));
        }