public async Task <ActionResult <MealToReturnDto> > GetMeal(int id) { var spec = new MealsWithTypesSpecification(id); var meal = await _mealsRepo.GetEntityWithSpec(spec); if (meal == null) { return(NotFound(new ApiResponse(404))); } return(_mapper.Map <Meal, MealToReturnDto>(meal)); }
public async Task <ActionResult <Pagination <MealToReturnDto> > > GetMeals([FromQuery] MealSpecParams mealParams) { var spec = new MealsWithTypesSpecification(mealParams); var countSpec = new MealWithFiltersForCountSpecification(mealParams); var totalItems = await _mealsRepo.CountAsync(countSpec); var meals = await _mealsRepo.ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Meal>, IReadOnlyList <MealToReturnDto> >(meals); return(Ok(new Pagination <MealToReturnDto>(mealParams.PageIndex, mealParams.PageSize, totalItems, data))); }