-
Notifications
You must be signed in to change notification settings - Fork 378
/
Copy pathFoodService.cs
30 lines (24 loc) · 1017 Bytes
/
FoodService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Microsoft.AspNetCore.Mvc;
using SampleWebApiAspNetCore.Models;
namespace SampleWebApiAspNetCore.Services
{
public class FoodService : IFoodService
{
private readonly IFoodRepository _foodRepository;
private readonly ILinkService _linkService;
public FoodService(IFoodRepository foodRepository, ILinkService linkService)
{
_foodRepository = foodRepository;
_linkService = linkService;
}
public FoodResultDto GetAllFoods(QueryParameters queryParameters, ApiVersion version)
{
var foodItems = _foodRepository.GetAll(queryParameters);
var allItemCount = _foodRepository.Count();
var paginationMetadata = new PaginationMetadata(allItemCount, queryParameters);
var links = _linkService.CreateLinksForCollection(queryParameters, allItemCount, version);
var toReturn = foodItems.Select(x => _linkService.ExpandSingleFoodItem(x, x.Id, version));
return new FoodResultDto(toReturn, links, paginationMetadata);
}
}
}