Commit f64990c1 authored by TTrueBenji's avatar TTrueBenji

refactor: сервис пагинации сделал обобщенным, чтобы его можно было…

refactor: сервис пагинации сделал обобщенным, чтобы его можно было переиспользовать для товаров и т.д.
parent 242d1f32
using System.Linq;
using System.Threading.Tasks;
using PhoneStore.Models;
namespace PhoneStore.Services.Abstractions
{
public interface IPaginationService
public interface IPaginationService<T>
{
Task<(IQueryable<User>, int)> GetABatchOfData(IQueryable<User> users, int page, int pageSize);
Task<(IQueryable<T>, int)> GetABatchOfData(IQueryable<T> elements, int page, int pageSize);
}
}
\ No newline at end of file
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using PhoneStore.Models;
using PhoneStore.Services.Abstractions;
namespace PhoneStore.Services
{
public class PaginationService : IPaginationService
public class PaginationService<T> : IPaginationService<T>
{
public async Task<(IQueryable<User>, int)> GetABatchOfData(IQueryable<User> users, int page, int pageSize)
public async Task<(IQueryable<T>, int)> GetABatchOfData(IQueryable<T> elements, int page, int pageSize)
{
int count = await users.CountAsync();
return (users.Skip((page - 1) * pageSize).Take(pageSize), count);
int count = await elements.CountAsync();
return (elements.Skip((page - 1) * pageSize).Take(pageSize), count);
}
}
}
\ No newline at end of file
......@@ -12,13 +12,13 @@ namespace PhoneStore.Services
private readonly MobileContext _db;
private readonly IUsersSortService _sortService;
private readonly IUsersFilter _usersFilter;
private readonly IPaginationService _paginationService;
private readonly IPaginationService<User> _paginationService;
public UserService(
MobileContext db,
IUsersSortService sortService,
IUsersFilter usersFilter,
IPaginationService paginationService)
IPaginationService<User> paginationService)
{
_db = db;
_sortService = sortService;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment