API mostly working, starting to work on webapp
This commit is contained in:
35
Models/Paginated.cs
Normal file
35
Models/Paginated.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
public class Paginated<T>
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Page { get;}
|
||||
public bool Last { get; }
|
||||
public int Count { get; }
|
||||
public List<T> Items { get; }
|
||||
public Paginated(int max, int page, IEnumerable<T> iter)
|
||||
{
|
||||
Max = max;
|
||||
Page = page;
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
Items = iter.Take(max + 1).ToList();
|
||||
if (Items.Count > max)
|
||||
{
|
||||
Last = false;
|
||||
Items.RemoveAt(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Last = true;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user