Add logic for retriving request information

pull/2467/head
Kenton Royal 6 years ago
parent 3959a79ea8
commit 6ebe2deb52

@ -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…
Cancel
Save