mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Add logic for movie request count
This commit is contained in:
parent
6ebe2deb52
commit
0e46e66a6d
1 changed files with 27 additions and 4 deletions
|
@ -487,12 +487,35 @@ namespace Ombi.Core.Engine
|
|||
|
||||
public async Task<RequestQuotaCountModel> GetRemainingRequests()
|
||||
{
|
||||
OmbiUser user = await GetUser();
|
||||
int limit = user.MovieRequestLimit ?? 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.Movie);
|
||||
|
||||
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 = false,
|
||||
Limit = 5,
|
||||
Remaining = 4,
|
||||
NextRequest = DateTime.Parse("2018-08-27T00:00:00+01"),
|
||||
HasLimit = true,
|
||||
Limit = limit,
|
||||
Remaining = count,
|
||||
NextRequest = oldestRequestedAt.AddDays(7),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue