mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 00:32:57 -07:00
Add logic for retriving request information
This commit is contained in:
parent
3959a79ea8
commit
6ebe2deb52
1 changed files with 26 additions and 3 deletions
|
@ -616,12 +616,35 @@ namespace Ombi.Core.Engine
|
|||
|
||||
public async Task<RequestQuotaCountModel> GetRemainingRequests()
|
||||
{
|
||||
OmbiUser user = await GetUser();
|
||||
int limit = user.EpisodeRequestLimit ?? 0;
|
||||
|
||||
if (limit <= 0)
|
||||
{
|
||||
return new RequestQuotaCountModel()
|
||||
{
|
||||
HasLimit = false,
|
||||
Limit = 0,
|
||||
Remaining = 0,
|
||||
NextRequest = DateTime.Now,
|
||||
};
|
||||
}
|
||||
|
||||
IQueryable<RequestLog> log = _requestLog.GetAll().Where(x => x.UserId == user.Id && x.RequestType == RequestType.TvShow);
|
||||
|
||||
int count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
||||
|
||||
DateTime oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7))
|
||||
.OrderBy(x => x.RequestDate)
|
||||
.Select(x => x.RequestDate)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return new RequestQuotaCountModel()
|
||||
{
|
||||
HasLimit = true,
|
||||
Limit = 5,
|
||||
Remaining = 4,
|
||||
NextRequest = DateTime.Parse("2018-08-30T00:00:00+01"),
|
||||
Limit = limit,
|
||||
Remaining = count,
|
||||
NextRequest = oldestRequestedAt.AddDays(7),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue