mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 09:12:57 -07:00
refactor(request-limits): ♻️ Refactored the request limits to sit in their own services
This commit is contained in:
parent
364b9f11af
commit
6adf75d0ec
13 changed files with 983 additions and 403 deletions
|
@ -5,6 +5,7 @@ using NUnit.Framework;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Core.Engine;
|
using Ombi.Core.Engine;
|
||||||
using Ombi.Core.Models;
|
using Ombi.Core.Models;
|
||||||
|
using Ombi.Core.Services;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
@ -24,7 +25,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
{
|
{
|
||||||
|
|
||||||
private AutoMocker _mocker;
|
private AutoMocker _mocker;
|
||||||
private MovieRequestEngine _subject;
|
private RequestLimitService _subject;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
|
@ -37,14 +38,14 @@ namespace Ombi.Core.Tests.Engine
|
||||||
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
|
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
|
||||||
_mocker.Use(principleMock.Object);
|
_mocker.Use(principleMock.Object);
|
||||||
|
|
||||||
_subject = _mocker.CreateInstance<MovieRequestEngine>();
|
_subject = _mocker.CreateInstance<RequestLimitService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task User_No_MovieLimit_Set()
|
public async Task User_No_MovieLimit_Set()
|
||||||
{
|
{
|
||||||
var user = new OmbiUser();
|
var user = new OmbiUser();
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result.HasLimit, Is.False);
|
Assert.That(result.HasLimit, Is.False);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +60,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(null);
|
var result = await _subject.GetRemainingMovieRequests(null);
|
||||||
|
|
||||||
Assert.That(result, Is.Null);
|
Assert.That(result, Is.Null);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(null);
|
var result = await _subject.GetRemainingMovieRequests(null);
|
||||||
|
|
||||||
Assert.That(result.HasLimit, Is.False);
|
Assert.That(result.HasLimit, Is.False);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(new List<RequestLog>().AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(new List<RequestLog>().AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -124,7 +125,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -198,7 +199,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -231,7 +232,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -264,7 +265,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -303,7 +304,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -336,7 +337,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -368,7 +369,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -407,7 +408,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -439,7 +440,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -472,7 +473,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -512,7 +513,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingMovieRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
|
526
src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
Normal file
526
src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
Normal file
|
@ -0,0 +1,526 @@
|
||||||
|
using MockQueryable.Moq;
|
||||||
|
using Moq;
|
||||||
|
using Moq.AutoMock;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Ombi.Core.Authentication;
|
||||||
|
using Ombi.Core.Engine;
|
||||||
|
using Ombi.Core.Models;
|
||||||
|
using Ombi.Core.Services;
|
||||||
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using Ombi.Store.Entities.Requests;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.Core.Tests.Engine
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class MusicRequestLimitTests
|
||||||
|
{
|
||||||
|
|
||||||
|
private AutoMocker _mocker;
|
||||||
|
private RequestLimitService _subject;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
|
||||||
|
_mocker = new AutoMocker();
|
||||||
|
var principleMock = new Mock<IPrincipal>();
|
||||||
|
var identityMock = new Mock<IIdentity>();
|
||||||
|
identityMock.SetupGet(x => x.Name).Returns("Test");
|
||||||
|
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
|
||||||
|
_mocker.Use(principleMock.Object);
|
||||||
|
|
||||||
|
_subject = _mocker.CreateInstance<RequestLimitService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task User_No_MusicLimit_Set()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser();
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result.HasLimit, Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task No_UserPassedIn_UsernotExist_No_MusicLimit_Set()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser();
|
||||||
|
|
||||||
|
var um = _mocker.GetMock<OmbiUserManager>();
|
||||||
|
um.SetupGet(x => x.Users).Returns(new List<OmbiUser> { user }.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(null);
|
||||||
|
|
||||||
|
Assert.That(result, Is.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task No_UserPassedIn_No_MusicLimit_Set()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST"
|
||||||
|
};
|
||||||
|
|
||||||
|
var um = _mocker.GetMock<OmbiUserManager>();
|
||||||
|
um.SetupGet(x => x.Users).Returns(new List<OmbiUser> { user }.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(null);
|
||||||
|
|
||||||
|
Assert.That(result.HasLimit, Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_No_Requests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 1
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(new List<RequestLog>().AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(1)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var yesterday = DateTime.Now.AddDays(-1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = yesterday, // Yesterday
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(1)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(yesterday.AddDays(7))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_MultipleRequests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var yesterday = DateTime.Now.AddDays(-1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = yesterday,
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = yesterday.AddDays(-2),
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate =yesterday.AddDays(-3), // Yesterday
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate =yesterday.AddDays(-4), // Yesterday
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate =yesterday.AddDays(-5), // Yesterday
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate =yesterday.AddDays(-6), // Yesterday
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate =yesterday.AddDays(-7), // Yesterday
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = yesterday.AddDays(-8), // Yesterday
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(0)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(yesterday.AddDays(1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_NoRequestsToday()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Day,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var yesterday = DateTime.Now.AddDays(-1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = yesterday,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_OneRequestsToday()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Day,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
|
||||||
|
var today = DateTime.Now;
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today.AddHours(-1),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(1)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(today.AddDays(1).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_AllRequestsToday()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Day,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var today = DateTime.Now;
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today.AddHours(-1),
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today.AddHours(-2),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(0)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(today.AddDays(1).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_NoRequests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Week,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var lastWeek = DateTime.Now.FirstDateInWeek().AddDays(-1); // Day before reset
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = lastWeek,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_OneRequestsWeek()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Week,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var today = DateTime.UtcNow;
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(1)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(today.FirstDateInWeek().AddDays(7).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_AllRequestsWeek()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Week,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var today = DateTime.Now;
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today.AddDays(-1),
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(0)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(today.FirstDateInWeek().AddDays(7).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_NoRequests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Month,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var lastWeek = DateTime.Now.AddMonths(-1).AddDays(-1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = lastWeek,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_OneRequests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Month,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var today = DateTime.Now;
|
||||||
|
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(1)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(firstDayOfMonth.AddMonths(1).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_AllRequests()
|
||||||
|
{
|
||||||
|
var user = new OmbiUser
|
||||||
|
{
|
||||||
|
NormalizedUserName = "TEST",
|
||||||
|
MusicRequestLimit = 2,
|
||||||
|
MusicRequestLimitType = RequestLimitType.Month,
|
||||||
|
Id = "id1"
|
||||||
|
};
|
||||||
|
var today = DateTime.Now;
|
||||||
|
var firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
|
||||||
|
var log = new List<RequestLog>
|
||||||
|
{
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today.AddDays(-1),
|
||||||
|
},
|
||||||
|
new RequestLog
|
||||||
|
{
|
||||||
|
UserId = "id1",
|
||||||
|
RequestType = RequestType.Album,
|
||||||
|
RequestDate = today,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var result = await _subject.GetRemainingMusicRequests(user);
|
||||||
|
|
||||||
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Limit)).EqualTo(2)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.Remaining)).EqualTo(0)
|
||||||
|
.And.Property(nameof(RequestQuotaCountModel.NextRequest)).EqualTo(firstDayOfMonth.AddMonths(1).Date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ using NUnit.Framework;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Core.Engine;
|
using Ombi.Core.Engine;
|
||||||
using Ombi.Core.Models;
|
using Ombi.Core.Models;
|
||||||
|
using Ombi.Core.Services;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
|
@ -21,7 +22,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
{
|
{
|
||||||
|
|
||||||
private AutoMocker _mocker;
|
private AutoMocker _mocker;
|
||||||
private TvRequestEngine _subject;
|
private RequestLimitService _subject;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
|
@ -33,14 +34,14 @@ namespace Ombi.Core.Tests.Engine
|
||||||
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
|
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
|
||||||
_mocker.Use(principleMock.Object);
|
_mocker.Use(principleMock.Object);
|
||||||
|
|
||||||
_subject = _mocker.CreateInstance<TvRequestEngine>();
|
_subject = _mocker.CreateInstance<RequestLimitService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task User_No_TvLimit_Set()
|
public async Task User_No_TvLimit_Set()
|
||||||
{
|
{
|
||||||
var user = new OmbiUser();
|
var user = new OmbiUser();
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result.HasLimit, Is.False);
|
Assert.That(result.HasLimit, Is.False);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(null);
|
var result = await _subject.GetRemainingTvRequests(null);
|
||||||
|
|
||||||
Assert.That(result, Is.Null);
|
Assert.That(result, Is.Null);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(null);
|
var result = await _subject.GetRemainingTvRequests(null);
|
||||||
|
|
||||||
Assert.That(result.HasLimit, Is.False);
|
Assert.That(result.HasLimit, Is.False);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +90,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(new List<RequestLog>().AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(new List<RequestLog>().AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -120,7 +121,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -202,7 +203,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -236,7 +237,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -269,7 +270,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -310,7 +311,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -351,7 +352,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -385,7 +386,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -418,7 +419,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -459,7 +460,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -500,7 +501,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -534,7 +535,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -567,7 +568,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -608,7 +609,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
@ -649,7 +650,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
var repoMock = _mocker.GetMock<IRepository<RequestLog>>();
|
||||||
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
var result = await _subject.GetRemainingRequests(user);
|
var result = await _subject.GetRemainingTvRequests(user);
|
||||||
|
|
||||||
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
Assert.That(result, Is.InstanceOf<RequestQuotaCountModel>()
|
||||||
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
.With.Property(nameof(RequestQuotaCountModel.HasLimit)).EqualTo(true)
|
||||||
|
|
|
@ -22,7 +22,6 @@ namespace Ombi.Core.Engine
|
||||||
Task<RequestEngineResult> RequestAlbum(MusicAlbumRequestViewModel model);
|
Task<RequestEngineResult> RequestAlbum(MusicAlbumRequestViewModel model);
|
||||||
Task<IEnumerable<AlbumRequest>> SearchAlbumRequest(string search);
|
Task<IEnumerable<AlbumRequest>> SearchAlbumRequest(string search);
|
||||||
Task<bool> UserHasRequest(string userId);
|
Task<bool> UserHasRequest(string userId);
|
||||||
Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user = null);
|
|
||||||
Task<RequestsViewModel<AlbumRequest>> GetRequestsByStatus(int count, int position, string sort, string sortOrder, RequestStatus available);
|
Task<RequestsViewModel<AlbumRequest>> GetRequestsByStatus(int count, int position, string sort, string sortOrder, RequestStatus available);
|
||||||
Task<RequestsViewModel<AlbumRequest>> GetRequests(int count, int position, string sort, string sortOrder);
|
Task<RequestsViewModel<AlbumRequest>> GetRequests(int count, int position, string sort, string sortOrder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ namespace Ombi.Core.Engine.Interfaces
|
||||||
Task<int> GetTotal();
|
Task<int> GetTotal();
|
||||||
Task UnSubscribeRequest(int requestId, RequestType type);
|
Task UnSubscribeRequest(int requestId, RequestType type);
|
||||||
Task SubscribeToRequest(int requestId, RequestType type);
|
Task SubscribeToRequest(int requestId, RequestType type);
|
||||||
Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user = null);
|
|
||||||
Task<RequestEngineResult> ReProcessRequest(int requestId, CancellationToken cancellationToken);
|
Task<RequestEngineResult> ReProcessRequest(int requestId, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -753,98 +753,5 @@ namespace Ombi.Core.Engine
|
||||||
|
|
||||||
return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id };
|
return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
|
|
||||||
{
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
user = await GetUser();
|
|
||||||
|
|
||||||
// If user is still null after attempting to get the logged in user, return null.
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = 0;
|
|
||||||
DateTime oldestRequestedAt = DateTime.Now;
|
|
||||||
DateTime nextRequest = DateTime.Now;
|
|
||||||
|
|
||||||
if (!user.MovieRequestLimitType.HasValue)
|
|
||||||
{
|
|
||||||
count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
|
||||||
|
|
||||||
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 = limit,
|
|
||||||
Remaining = count < 0 ? 0 : count,
|
|
||||||
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (user.MovieRequestLimitType)
|
|
||||||
{
|
|
||||||
case RequestLimitType.Day:
|
|
||||||
count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.Date);
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date)
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = oldestRequestedAt.AddDays(1).Date;
|
|
||||||
break;
|
|
||||||
case RequestLimitType.Week:
|
|
||||||
var fdow = DateTime.UtcNow.FirstDateInWeek();
|
|
||||||
count = limit - await log.CountAsync(x => x.RequestDate >= fdow);
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= fdow)
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = fdow.AddDays(7).Date;
|
|
||||||
break;
|
|
||||||
case RequestLimitType.Month:
|
|
||||||
var now = DateTime.UtcNow;
|
|
||||||
var firstDayOfMonth = new DateTime(now.Year, now.Month, 1);
|
|
||||||
count = limit - await log.CountAsync(x => x.RequestDate >= firstDayOfMonth);
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= firstDayOfMonth)
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = firstDayOfMonth.AddMonths(1).Date;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RequestQuotaCountModel()
|
|
||||||
{
|
|
||||||
HasLimit = true,
|
|
||||||
Limit = limit,
|
|
||||||
Remaining = count < 0 ? 0 : count,
|
|
||||||
NextRequest = DateTime.SpecifyKind(nextRequest, DateTimeKind.Utc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -435,49 +435,6 @@ namespace Ombi.Core.Engine
|
||||||
Result = true
|
Result = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
|
|
||||||
{
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
user = await GetUser();
|
|
||||||
|
|
||||||
// If user is still null after attempting to get the logged in user, return null.
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int limit = user.MusicRequestLimit ?? 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.Album);
|
|
||||||
|
|
||||||
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 = limit,
|
|
||||||
Remaining = count,
|
|
||||||
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<RequestEngineResult> MarkAvailable(int modelId)
|
public async Task<RequestEngineResult> MarkAvailable(int modelId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -955,123 +955,7 @@ namespace Ombi.Core.Engine
|
||||||
return new RequestEngineResult { Result = true, RequestId = model.Id };
|
return new RequestEngineResult { Result = true, RequestId = model.Id };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
|
|
||||||
{
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
user = await GetUser();
|
|
||||||
|
|
||||||
// If user is still null after attempting to get the logged in user, return null.
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = 0;
|
|
||||||
DateTime oldestRequestedAt = DateTime.Now;
|
|
||||||
DateTime nextRequest = DateTime.Now;
|
|
||||||
|
|
||||||
|
|
||||||
IQueryable<RequestLog> filteredLog;
|
|
||||||
int zeroEpisodeCount;
|
|
||||||
int episodeCount;
|
|
||||||
|
|
||||||
if (!user.EpisodeRequestLimitType.HasValue)
|
|
||||||
{
|
|
||||||
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
|
||||||
// Needed, due to a bug which would cause all episode counts to be 0
|
|
||||||
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
|
||||||
|
|
||||||
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
|
||||||
|
|
||||||
count = limit - (zeroEpisodeCount + episodeCount);
|
|
||||||
|
|
||||||
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 = limit,
|
|
||||||
Remaining = count < 0 ? 0 : count,
|
|
||||||
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (user.EpisodeRequestLimitType)
|
|
||||||
{
|
|
||||||
case RequestLimitType.Day:
|
|
||||||
|
|
||||||
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date);
|
|
||||||
// Needed, due to a bug which would cause all episode counts to be 0
|
|
||||||
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
|
||||||
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
|
||||||
count = limit - (zeroEpisodeCount + episodeCount);
|
|
||||||
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date)
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = oldestRequestedAt.AddDays(1);
|
|
||||||
break;
|
|
||||||
case RequestLimitType.Week:
|
|
||||||
|
|
||||||
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7));
|
|
||||||
// Needed, due to a bug which would cause all episode counts to be 0
|
|
||||||
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
|
||||||
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
|
||||||
count = limit - (zeroEpisodeCount + episodeCount);
|
|
||||||
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7))
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = oldestRequestedAt.AddDays(7);
|
|
||||||
break;
|
|
||||||
case RequestLimitType.Month:
|
|
||||||
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddMonths(-1));
|
|
||||||
// Needed, due to a bug which would cause all episode counts to be 0
|
|
||||||
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
|
||||||
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
|
||||||
count = limit - (zeroEpisodeCount + episodeCount);
|
|
||||||
|
|
||||||
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddMonths(-1))
|
|
||||||
.OrderBy(x => x.RequestDate)
|
|
||||||
.Select(x => x.RequestDate)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
nextRequest = oldestRequestedAt.AddMonths(1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RequestQuotaCountModel()
|
|
||||||
{
|
|
||||||
HasLimit = true,
|
|
||||||
Limit = limit,
|
|
||||||
Remaining = count < 0 ? 0 : count,
|
|
||||||
NextRequest = DateTime.SpecifyKind(nextRequest, DateTimeKind.Utc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<RequestEngineResult> UpdateAdvancedOptions(MediaAdvancedOptions options)
|
public async Task<RequestEngineResult> UpdateAdvancedOptions(MediaAdvancedOptions options)
|
||||||
{
|
{
|
||||||
|
|
293
src/Ombi.Core/Services/RequestLimitService.cs
Normal file
293
src/Ombi.Core/Services/RequestLimitService.cs
Normal file
|
@ -0,0 +1,293 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Ombi.Core.Authentication;
|
||||||
|
using Ombi.Core.Engine.Interfaces;
|
||||||
|
using Ombi.Core.Models;
|
||||||
|
using Ombi.Core.Rule.Interfaces;
|
||||||
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using Ombi.Store.Entities.Requests;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.Core.Services
|
||||||
|
{
|
||||||
|
public interface IRequestLimitService
|
||||||
|
{
|
||||||
|
Task<RequestQuotaCountModel> GetRemainingMovieRequests(OmbiUser user = default);
|
||||||
|
Task<RequestQuotaCountModel> GetRemainingTvRequests(OmbiUser user = default);
|
||||||
|
Task<RequestQuotaCountModel> GetRemainingMusicRequests(OmbiUser user = default);
|
||||||
|
}
|
||||||
|
public class RequestLimitService : BaseEngine, IRequestLimitService
|
||||||
|
{
|
||||||
|
private readonly IRepository<RequestLog> _requestLog;
|
||||||
|
|
||||||
|
public RequestLimitService(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules, IRepository<RequestLog> rl) : base(user, um, rules)
|
||||||
|
{
|
||||||
|
_requestLog = rl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<RequestQuotaCountModel> GetRemainingMovieRequests(OmbiUser user)
|
||||||
|
{
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = await GetUser();
|
||||||
|
|
||||||
|
// If user is still null after attempting to get the logged in user, return null.
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (!user.MovieRequestLimitType.HasValue)
|
||||||
|
{
|
||||||
|
var count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
||||||
|
|
||||||
|
var 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 = limit,
|
||||||
|
Remaining = count < 0 ? 0 : count,
|
||||||
|
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return await CalculateBasicRemaingRequests(user, limit, user.MovieRequestLimitType ?? RequestLimitType.Day, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<RequestQuotaCountModel> GetRemainingMusicRequests(OmbiUser user)
|
||||||
|
{
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = await GetUser();
|
||||||
|
|
||||||
|
// If user is still null after attempting to get the logged in user, return null.
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int limit = user.MusicRequestLimit ?? 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.Album);
|
||||||
|
|
||||||
|
// Hisoric Limits
|
||||||
|
if (!user.MusicRequestLimitType.HasValue)
|
||||||
|
{
|
||||||
|
var oldcount = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
||||||
|
|
||||||
|
var oldestRequestedAtOld = 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 = limit,
|
||||||
|
Remaining = oldcount < 0 ? 0 : oldcount,
|
||||||
|
NextRequest = DateTime.SpecifyKind(oldestRequestedAtOld.AddDays(7), DateTimeKind.Utc),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return await CalculateBasicRemaingRequests(user, limit, user.MusicRequestLimitType ?? RequestLimitType.Day, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<RequestQuotaCountModel> CalculateBasicRemaingRequests(OmbiUser user, int limit, RequestLimitType type, IQueryable<RequestLog> log)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
DateTime oldestRequestedAt = DateTime.Now;
|
||||||
|
DateTime nextRequest = DateTime.Now;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case RequestLimitType.Day:
|
||||||
|
count = limit - await log.CountAsync(x => x.RequestDate >= DateTime.UtcNow.Date);
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date)
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = oldestRequestedAt.AddDays(1).Date;
|
||||||
|
break;
|
||||||
|
case RequestLimitType.Week:
|
||||||
|
var fdow = DateTime.UtcNow.FirstDateInWeek();
|
||||||
|
count = limit - await log.CountAsync(x => x.RequestDate >= fdow);
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= fdow)
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = fdow.AddDays(7).Date;
|
||||||
|
break;
|
||||||
|
case RequestLimitType.Month:
|
||||||
|
var now = DateTime.UtcNow;
|
||||||
|
var firstDayOfMonth = new DateTime(now.Year, now.Month, 1);
|
||||||
|
count = limit - await log.CountAsync(x => x.RequestDate >= firstDayOfMonth);
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= firstDayOfMonth)
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = firstDayOfMonth.AddMonths(1).Date;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RequestQuotaCountModel()
|
||||||
|
{
|
||||||
|
HasLimit = true,
|
||||||
|
Limit = limit,
|
||||||
|
Remaining = count < 0 ? 0 : count,
|
||||||
|
NextRequest = DateTime.SpecifyKind(nextRequest, DateTimeKind.Utc),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<RequestQuotaCountModel> GetRemainingTvRequests(OmbiUser user)
|
||||||
|
{
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = await GetUser();
|
||||||
|
|
||||||
|
// If user is still null after attempting to get the logged in user, return null.
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 0;
|
||||||
|
DateTime oldestRequestedAt = DateTime.Now;
|
||||||
|
DateTime nextRequest = DateTime.Now;
|
||||||
|
|
||||||
|
|
||||||
|
IQueryable<RequestLog> filteredLog;
|
||||||
|
int zeroEpisodeCount;
|
||||||
|
int episodeCount;
|
||||||
|
|
||||||
|
if (!user.EpisodeRequestLimitType.HasValue)
|
||||||
|
{
|
||||||
|
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.AddDays(-7));
|
||||||
|
// Needed, due to a bug which would cause all episode counts to be 0
|
||||||
|
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
||||||
|
|
||||||
|
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
||||||
|
|
||||||
|
count = limit - (zeroEpisodeCount + episodeCount);
|
||||||
|
|
||||||
|
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 = limit,
|
||||||
|
Remaining = count < 0 ? 0 : count,
|
||||||
|
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (user.EpisodeRequestLimitType)
|
||||||
|
{
|
||||||
|
case RequestLimitType.Day:
|
||||||
|
|
||||||
|
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date);
|
||||||
|
// Needed, due to a bug which would cause all episode counts to be 0
|
||||||
|
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
||||||
|
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
||||||
|
count = limit - (zeroEpisodeCount + episodeCount);
|
||||||
|
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date)
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = oldestRequestedAt.AddDays(1);
|
||||||
|
break;
|
||||||
|
case RequestLimitType.Week:
|
||||||
|
|
||||||
|
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7));
|
||||||
|
// Needed, due to a bug which would cause all episode counts to be 0
|
||||||
|
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
||||||
|
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
||||||
|
count = limit - (zeroEpisodeCount + episodeCount);
|
||||||
|
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7))
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = oldestRequestedAt.AddDays(7);
|
||||||
|
break;
|
||||||
|
case RequestLimitType.Month:
|
||||||
|
filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddMonths(-1));
|
||||||
|
// Needed, due to a bug which would cause all episode counts to be 0
|
||||||
|
zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();
|
||||||
|
episodeCount = await filteredLog.Where(x => x.EpisodeCount != 0).Select(x => x.EpisodeCount).SumAsync();
|
||||||
|
count = limit - (zeroEpisodeCount + episodeCount);
|
||||||
|
|
||||||
|
oldestRequestedAt = await log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddMonths(-1))
|
||||||
|
.OrderBy(x => x.RequestDate)
|
||||||
|
.Select(x => x.RequestDate)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
nextRequest = oldestRequestedAt.AddMonths(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RequestQuotaCountModel()
|
||||||
|
{
|
||||||
|
HasLimit = true,
|
||||||
|
Limit = limit,
|
||||||
|
Remaining = count < 0 ? 0 : count,
|
||||||
|
NextRequest = DateTime.SpecifyKind(nextRequest, DateTimeKind.Utc),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,6 +69,7 @@ using Ombi.Api.CloudService;
|
||||||
using Ombi.Api.RottenTomatoes;
|
using Ombi.Api.RottenTomatoes;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Ombi.Core.Services;
|
||||||
|
|
||||||
namespace Ombi.DependencyInjection
|
namespace Ombi.DependencyInjection
|
||||||
{
|
{
|
||||||
|
@ -88,34 +89,34 @@ namespace Ombi.DependencyInjection
|
||||||
|
|
||||||
public static void RegisterEngines(this IServiceCollection services)
|
public static void RegisterEngines(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<IMovieEngine, MovieSearchEngine>();
|
services.AddScoped<IMovieEngine, MovieSearchEngine>();
|
||||||
services.AddTransient<IMovieRequestEngine, MovieRequestEngine>();
|
services.AddScoped<IMovieRequestEngine, MovieRequestEngine>();
|
||||||
services.AddTransient<ITvRequestEngine, TvRequestEngine>();
|
services.AddScoped<ITvRequestEngine, TvRequestEngine>();
|
||||||
services.AddTransient<ITvSearchEngine, TvSearchEngine>();
|
services.AddScoped<ITvSearchEngine, TvSearchEngine>();
|
||||||
services.AddTransient<IRuleEvaluator, RuleEvaluator>();
|
services.AddScoped<IRuleEvaluator, RuleEvaluator>();
|
||||||
services.AddTransient<IUserStatsEngine, UserStatsEngine>();
|
services.AddScoped<IUserStatsEngine, UserStatsEngine>();
|
||||||
services.AddTransient<IMovieSender, MovieSender>();
|
services.AddScoped<IMovieSender, MovieSender>();
|
||||||
services.AddTransient<IRecentlyAddedEngine, RecentlyAddedEngine>();
|
services.AddScoped<IRecentlyAddedEngine, RecentlyAddedEngine>();
|
||||||
services.AddTransient<IMusicSearchEngine, MusicSearchEngine>();
|
services.AddScoped<IMusicSearchEngine, MusicSearchEngine>();
|
||||||
services.AddTransient<IMusicRequestEngine, MusicRequestEngine>();
|
services.AddScoped<IMusicRequestEngine, MusicRequestEngine>();
|
||||||
services.AddTransient<ITvSender, TvSender>();
|
services.AddScoped<ITvSender, TvSender>();
|
||||||
services.AddTransient<IMusicSender, MusicSender>();
|
services.AddScoped<IMusicSender, MusicSender>();
|
||||||
services.AddTransient<IMassEmailSender, MassEmailSender>();
|
services.AddScoped<IMassEmailSender, MassEmailSender>();
|
||||||
services.AddTransient<IPlexOAuthManager, PlexOAuthManager>();
|
services.AddScoped<IPlexOAuthManager, PlexOAuthManager>();
|
||||||
services.AddTransient<IVoteEngine, VoteEngine>();
|
services.AddScoped<IVoteEngine, VoteEngine>();
|
||||||
services.AddTransient<IDemoMovieSearchEngine, DemoMovieSearchEngine>();
|
services.AddScoped<IDemoMovieSearchEngine, DemoMovieSearchEngine>();
|
||||||
services.AddTransient<IDemoTvSearchEngine, DemoTvSearchEngine>();
|
services.AddScoped<IDemoTvSearchEngine, DemoTvSearchEngine>();
|
||||||
services.AddTransient<IUserDeletionEngine, UserDeletionEngine>();
|
services.AddScoped<IUserDeletionEngine, UserDeletionEngine>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterEnginesV2(this IServiceCollection services)
|
public static void RegisterEnginesV2(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<IMultiSearchEngine, MultiSearchEngine>();
|
services.AddScoped<IMultiSearchEngine, MultiSearchEngine>();
|
||||||
services.AddTransient<IMovieEngineV2, MovieSearchEngineV2>();
|
services.AddScoped<IMovieEngineV2, MovieSearchEngineV2>();
|
||||||
services.AddTransient<ITVSearchEngineV2, TvSearchEngineV2>();
|
services.AddScoped<ITVSearchEngineV2, TvSearchEngineV2>();
|
||||||
services.AddTransient<ICalendarEngine, CalendarEngine>();
|
services.AddScoped<ICalendarEngine, CalendarEngine>();
|
||||||
services.AddTransient<IMusicSearchEngineV2, MusicSearchEngineV2>();
|
services.AddScoped<IMusicSearchEngineV2, MusicSearchEngineV2>();
|
||||||
services.AddTransient<IIssuesEngine, IssuesEngine>();
|
services.AddScoped<IIssuesEngine, IssuesEngine>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterHttp(this IServiceCollection services)
|
public static void RegisterHttp(this IServiceCollection services)
|
||||||
|
@ -138,40 +139,40 @@ namespace Ombi.DependencyInjection
|
||||||
public static void RegisterApi(this IServiceCollection services)
|
public static void RegisterApi(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddScoped<IApi, Api.Api>(s => new Api.Api(s.GetRequiredService<ILogger<Api.Api>>(), s.GetRequiredService<IHttpClientFactory>().CreateClient("OmbiClient")));
|
services.AddScoped<IApi, Api.Api>(s => new Api.Api(s.GetRequiredService<ILogger<Api.Api>>(), s.GetRequiredService<IHttpClientFactory>().CreateClient("OmbiClient")));
|
||||||
services.AddTransient<IMovieDbApi, Api.TheMovieDb.TheMovieDbApi>();
|
services.AddScoped<IMovieDbApi, Api.TheMovieDb.TheMovieDbApi>();
|
||||||
services.AddTransient<IPlexApi, PlexApi>();
|
services.AddScoped<IPlexApi, PlexApi>();
|
||||||
services.AddTransient<IEmbyApi, EmbyApi>();
|
services.AddScoped<IEmbyApi, EmbyApi>();
|
||||||
services.AddTransient<IJellyfinApi, JellyfinApi>();
|
services.AddScoped<IJellyfinApi, JellyfinApi>();
|
||||||
services.AddTransient<ISonarrApi, SonarrApi>();
|
services.AddScoped<ISonarrApi, SonarrApi>();
|
||||||
services.AddTransient<ISonarrV3Api, SonarrV3Api>();
|
services.AddScoped<ISonarrV3Api, SonarrV3Api>();
|
||||||
services.AddTransient<ISlackApi, SlackApi>();
|
services.AddScoped<ISlackApi, SlackApi>();
|
||||||
services.AddTransient<ITvMazeApi, TvMazeApi>();
|
services.AddScoped<ITvMazeApi, TvMazeApi>();
|
||||||
services.AddTransient<ITraktApi, TraktApi>();
|
services.AddScoped<ITraktApi, TraktApi>();
|
||||||
services.AddTransient<IRadarrApi, RadarrApi>();
|
services.AddScoped<IRadarrApi, RadarrApi>();
|
||||||
services.AddTransient<IRadarrV3Api, RadarrV3Api>();
|
services.AddScoped<IRadarrV3Api, RadarrV3Api>();
|
||||||
services.AddTransient<IDiscordApi, DiscordApi>();
|
services.AddScoped<IDiscordApi, DiscordApi>();
|
||||||
services.AddTransient<IPushbulletApi, PushbulletApi>();
|
services.AddScoped<IPushbulletApi, PushbulletApi>();
|
||||||
services.AddTransient<IOmbiService, OmbiService>();
|
services.AddScoped<IOmbiService, OmbiService>();
|
||||||
services.AddTransient<IFanartTvApi, FanartTvApi>();
|
services.AddScoped<IFanartTvApi, FanartTvApi>();
|
||||||
services.AddTransient<IPushoverApi, PushoverApi>();
|
services.AddScoped<IPushoverApi, PushoverApi>();
|
||||||
services.AddTransient<IGotifyApi, GotifyApi>();
|
services.AddScoped<IGotifyApi, GotifyApi>();
|
||||||
services.AddTransient<IWebhookApi, WebhookApi>();
|
services.AddScoped<IWebhookApi, WebhookApi>();
|
||||||
services.AddTransient<IMattermostApi, MattermostApi>();
|
services.AddScoped<IMattermostApi, MattermostApi>();
|
||||||
services.AddTransient<ICouchPotatoApi, CouchPotatoApi>();
|
services.AddScoped<ICouchPotatoApi, CouchPotatoApi>();
|
||||||
services.AddTransient<IDogNzbApi, DogNzbApi>();
|
services.AddScoped<IDogNzbApi, DogNzbApi>();
|
||||||
services.AddTransient<ITelegramApi, TelegramApi>();
|
services.AddScoped<ITelegramApi, TelegramApi>();
|
||||||
services.AddTransient<IGithubApi, GithubApi>();
|
services.AddScoped<IGithubApi, GithubApi>();
|
||||||
services.AddTransient<ISickRageApi, SickRageApi>();
|
services.AddScoped<ISickRageApi, SickRageApi>();
|
||||||
services.AddTransient<IAppVeyorApi, AppVeyorApi>();
|
services.AddScoped<IAppVeyorApi, AppVeyorApi>();
|
||||||
services.AddTransient<IOneSignalApi, OneSignalApi>();
|
services.AddScoped<IOneSignalApi, OneSignalApi>();
|
||||||
services.AddTransient<ILidarrApi, LidarrApi>();
|
services.AddScoped<ILidarrApi, LidarrApi>();
|
||||||
services.AddTransient<IGroupMeApi, GroupMeApi>();
|
services.AddScoped<IGroupMeApi, GroupMeApi>();
|
||||||
services.AddTransient<IMusicBrainzApi, MusicBrainzApi>();
|
services.AddScoped<IMusicBrainzApi, MusicBrainzApi>();
|
||||||
services.AddTransient<IWhatsAppApi, WhatsAppApi>();
|
services.AddScoped<IWhatsAppApi, WhatsAppApi>();
|
||||||
services.AddTransient<ICloudMobileNotification, CloudMobileNotification>();
|
services.AddScoped<ICloudMobileNotification, CloudMobileNotification>();
|
||||||
services.AddTransient<IEmbyApiFactory, EmbyApiFactory>();
|
services.AddScoped<IEmbyApiFactory, EmbyApiFactory>();
|
||||||
services.AddTransient<IJellyfinApiFactory, JellyfinApiFactory>();
|
services.AddScoped<IJellyfinApiFactory, JellyfinApiFactory>();
|
||||||
services.AddTransient<IRottenTomatoesApi, RottenTomatoesApi>();
|
services.AddScoped<IRottenTomatoesApi, RottenTomatoesApi>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterStore(this IServiceCollection services) {
|
public static void RegisterStore(this IServiceCollection services) {
|
||||||
|
@ -201,26 +202,27 @@ namespace Ombi.DependencyInjection
|
||||||
}
|
}
|
||||||
public static void RegisterServices(this IServiceCollection services)
|
public static void RegisterServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<IRequestServiceMain, RequestService>();
|
services.AddScoped<IRequestServiceMain, RequestService>();
|
||||||
services.AddTransient<INotificationService, NotificationService>();
|
services.AddScoped<INotificationService, NotificationService>();
|
||||||
services.AddTransient<IEmailProvider, GenericEmailProvider>();
|
services.AddScoped<IEmailProvider, GenericEmailProvider>();
|
||||||
services.AddTransient<INotificationHelper, NotificationHelper>();
|
services.AddScoped<INotificationHelper, NotificationHelper>();
|
||||||
services.AddSingleton<ICacheService, CacheService>();
|
services.AddSingleton<ICacheService, CacheService>();
|
||||||
services.AddSingleton<IMediaCacheService, MediaCacheService>();
|
services.AddSingleton<IMediaCacheService, MediaCacheService>();
|
||||||
services.AddScoped<IImageService, ImageService>();
|
services.AddScoped<IImageService, ImageService>();
|
||||||
|
services.AddSingleton<IRequestLimitService, RequestLimitService>();
|
||||||
|
|
||||||
services.AddTransient<IDiscordNotification, DiscordNotification>();
|
services.AddScoped<IDiscordNotification, DiscordNotification>();
|
||||||
services.AddTransient<IEmailNotification, EmailNotification>();
|
services.AddScoped<IEmailNotification, EmailNotification>();
|
||||||
services.AddTransient<IPushbulletNotification, PushbulletNotification>();
|
services.AddScoped<IPushbulletNotification, PushbulletNotification>();
|
||||||
services.AddTransient<ISlackNotification, SlackNotification>();
|
services.AddScoped<ISlackNotification, SlackNotification>();
|
||||||
services.AddTransient<ISlackNotification, SlackNotification>();
|
services.AddScoped<ISlackNotification, SlackNotification>();
|
||||||
services.AddTransient<IMattermostNotification, MattermostNotification>();
|
services.AddScoped<IMattermostNotification, MattermostNotification>();
|
||||||
services.AddTransient<IPushoverNotification, PushoverNotification>();
|
services.AddScoped<IPushoverNotification, PushoverNotification>();
|
||||||
services.AddTransient<IGotifyNotification, GotifyNotification>();
|
services.AddScoped<IGotifyNotification, GotifyNotification>();
|
||||||
services.AddTransient<IWebhookNotification, WebhookNotification>();
|
services.AddScoped<IWebhookNotification, WebhookNotification>();
|
||||||
services.AddTransient<ITelegramNotification, TelegramNotification>();
|
services.AddScoped<ITelegramNotification, TelegramNotification>();
|
||||||
services.AddTransient<ILegacyMobileNotification, LegacyMobileNotification>();
|
services.AddScoped<ILegacyMobileNotification, LegacyMobileNotification>();
|
||||||
services.AddTransient<IChangeLogProcessor, ChangeLogProcessor>();
|
services.AddScoped<IChangeLogProcessor, ChangeLogProcessor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterJobs(this IServiceCollection services)
|
public static void RegisterJobs(this IServiceCollection services)
|
||||||
|
@ -228,35 +230,35 @@ namespace Ombi.DependencyInjection
|
||||||
services.AddSingleton<QuartzJobRunner>();
|
services.AddSingleton<QuartzJobRunner>();
|
||||||
services.AddSingleton<IJobFactory, IoCJobFactory>();
|
services.AddSingleton<IJobFactory, IoCJobFactory>();
|
||||||
|
|
||||||
services.AddTransient<IPlexContentSync, PlexContentSync>();
|
services.AddSingleton<IPlexContentSync, PlexContentSync>();
|
||||||
services.AddTransient<IEmbyContentSync, EmbyContentSync>();
|
services.AddSingleton<IEmbyContentSync, EmbyContentSync>();
|
||||||
services.AddTransient<IEmbyEpisodeSync, EmbyEpisodeSync>();
|
services.AddSingleton<IEmbyEpisodeSync, EmbyEpisodeSync>();
|
||||||
services.AddTransient<IEmbyAvaliabilityChecker, EmbyAvaliabilityChecker>();
|
services.AddSingleton<IEmbyAvaliabilityChecker, EmbyAvaliabilityChecker>();
|
||||||
services.AddTransient<IJellyfinContentSync, JellyfinContentSync>();
|
services.AddSingleton<IJellyfinContentSync, JellyfinContentSync>();
|
||||||
services.AddTransient<IJellyfinEpisodeSync, JellyfinEpisodeSync>();
|
services.AddSingleton<IJellyfinEpisodeSync, JellyfinEpisodeSync>();
|
||||||
services.AddTransient<IJellyfinAvaliabilityChecker, JellyfinAvaliabilityChecker>();
|
services.AddSingleton<IJellyfinAvaliabilityChecker, JellyfinAvaliabilityChecker>();
|
||||||
services.AddTransient<IPlexEpisodeSync, PlexEpisodeSync>();
|
services.AddSingleton<IPlexEpisodeSync, PlexEpisodeSync>();
|
||||||
services.AddTransient<IPlexAvailabilityChecker, PlexAvailabilityChecker>();
|
services.AddSingleton<IPlexAvailabilityChecker, PlexAvailabilityChecker>();
|
||||||
services.AddTransient<IRadarrSync, RadarrSync>();
|
services.AddSingleton<IRadarrSync, RadarrSync>();
|
||||||
services.AddTransient<ISonarrSync, SonarrSync>();
|
services.AddSingleton<ISonarrSync, SonarrSync>();
|
||||||
services.AddTransient<IOmbiAutomaticUpdater, OmbiAutomaticUpdater>();
|
services.AddSingleton<IOmbiAutomaticUpdater, OmbiAutomaticUpdater>();
|
||||||
services.AddTransient<IPlexUserImporter, PlexUserImporter>();
|
services.AddSingleton<IPlexUserImporter, PlexUserImporter>();
|
||||||
services.AddTransient<IEmbyUserImporter, EmbyUserImporter>();
|
services.AddSingleton<IEmbyUserImporter, EmbyUserImporter>();
|
||||||
services.AddTransient<IJellyfinUserImporter, JellyfinUserImporter>();
|
services.AddSingleton<IJellyfinUserImporter, JellyfinUserImporter>();
|
||||||
services.AddTransient<IWelcomeEmail, WelcomeEmail>();
|
services.AddSingleton<IWelcomeEmail, WelcomeEmail>();
|
||||||
services.AddTransient<ICouchPotatoSync, CouchPotatoSync>();
|
services.AddSingleton<ICouchPotatoSync, CouchPotatoSync>();
|
||||||
services.AddTransient<IProcessProvider, ProcessProvider>();
|
services.AddSingleton<IProcessProvider, ProcessProvider>();
|
||||||
services.AddTransient<ISickRageSync, SickRageSync>();
|
services.AddSingleton<ISickRageSync, SickRageSync>();
|
||||||
services.AddTransient<IRefreshMetadata, RefreshMetadata>();
|
services.AddSingleton<IRefreshMetadata, RefreshMetadata>();
|
||||||
services.AddTransient<INewsletterJob, NewsletterJob>();
|
services.AddSingleton<INewsletterJob, NewsletterJob>();
|
||||||
services.AddTransient<ILidarrAlbumSync, LidarrAlbumSync>();
|
services.AddSingleton<ILidarrAlbumSync, LidarrAlbumSync>();
|
||||||
services.AddTransient<ILidarrArtistSync, LidarrArtistSync>();
|
services.AddSingleton<ILidarrArtistSync, LidarrArtistSync>();
|
||||||
services.AddTransient<ILidarrAvailabilityChecker, LidarrAvailabilityChecker>();
|
services.AddSingleton<ILidarrAvailabilityChecker, LidarrAvailabilityChecker>();
|
||||||
services.AddTransient<IIssuesPurge, IssuesPurge>();
|
services.AddSingleton<IIssuesPurge, IssuesPurge>();
|
||||||
services.AddTransient<IResendFailedRequests, ResendFailedRequests>();
|
services.AddSingleton<IResendFailedRequests, ResendFailedRequests>();
|
||||||
services.AddTransient<IMediaDatabaseRefresh, MediaDatabaseRefresh>();
|
services.AddSingleton<IMediaDatabaseRefresh, MediaDatabaseRefresh>();
|
||||||
services.AddTransient<IArrAvailabilityChecker, ArrAvailabilityChecker>();
|
services.AddSingleton<IArrAvailabilityChecker, ArrAvailabilityChecker>();
|
||||||
services.AddTransient<IAutoDeleteRequests, AutoDeleteRequests>();
|
services.AddSingleton<IAutoDeleteRequests, AutoDeleteRequests>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ using Ombi.Core.Engine;
|
||||||
using Ombi.Core.Engine.Interfaces;
|
using Ombi.Core.Engine.Interfaces;
|
||||||
using Ombi.Core.Helpers;
|
using Ombi.Core.Helpers;
|
||||||
using Ombi.Core.Models.UI;
|
using Ombi.Core.Models.UI;
|
||||||
|
using Ombi.Core.Services;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
using Ombi.Core.Settings.Models.External;
|
using Ombi.Core.Settings.Models.External;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
|
@ -68,6 +69,7 @@ namespace Ombi.Controllers.V1
|
||||||
ITvRequestEngine tvRequestEngine,
|
ITvRequestEngine tvRequestEngine,
|
||||||
IMusicRequestEngine musicEngine,
|
IMusicRequestEngine musicEngine,
|
||||||
IUserDeletionEngine deletionEngine,
|
IUserDeletionEngine deletionEngine,
|
||||||
|
IRequestLimitService requestLimitService,
|
||||||
ICacheService cacheService)
|
ICacheService cacheService)
|
||||||
{
|
{
|
||||||
UserManager = user;
|
UserManager = user;
|
||||||
|
@ -96,11 +98,13 @@ namespace Ombi.Controllers.V1
|
||||||
_userQualityProfiles = userProfiles;
|
_userQualityProfiles = userProfiles;
|
||||||
MusicRequestEngine = musicEngine;
|
MusicRequestEngine = musicEngine;
|
||||||
_deletionEngine = deletionEngine;
|
_deletionEngine = deletionEngine;
|
||||||
|
_requestLimitService = requestLimitService;
|
||||||
_cacheService = cacheService;
|
_cacheService = cacheService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OmbiUserManager UserManager { get; }
|
private OmbiUserManager UserManager { get; }
|
||||||
private readonly IUserDeletionEngine _deletionEngine;
|
private readonly IUserDeletionEngine _deletionEngine;
|
||||||
|
private readonly IRequestLimitService _requestLimitService;
|
||||||
private readonly ICacheService _cacheService;
|
private readonly ICacheService _cacheService;
|
||||||
|
|
||||||
private RoleManager<IdentityRole> RoleManager { get; }
|
private RoleManager<IdentityRole> RoleManager { get; }
|
||||||
|
@ -422,17 +426,17 @@ namespace Ombi.Controllers.V1
|
||||||
|
|
||||||
if (vm.EpisodeRequestLimit > 0)
|
if (vm.EpisodeRequestLimit > 0)
|
||||||
{
|
{
|
||||||
vm.EpisodeRequestQuota = await TvRequestEngine.GetRemainingRequests(user);
|
vm.EpisodeRequestQuota = await _requestLimitService.GetRemainingTvRequests(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.MovieRequestLimit > 0)
|
if (vm.MovieRequestLimit > 0)
|
||||||
{
|
{
|
||||||
vm.MovieRequestQuota = await MovieRequestEngine.GetRemainingRequests(user);
|
vm.MovieRequestQuota = await _requestLimitService.GetRemainingMovieRequests(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.MusicRequestLimit > 0)
|
if (vm.MusicRequestLimit > 0)
|
||||||
{
|
{
|
||||||
vm.MusicRequestQuota = await MusicRequestEngine.GetRemainingRequests(user);
|
vm.MusicRequestQuota = await _requestLimitService.GetRemainingMusicRequests(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the quality profiles
|
// Get the quality profiles
|
||||||
|
|
|
@ -10,6 +10,7 @@ using Ombi.Core.Engine;
|
||||||
using Ombi.Core.Models;
|
using Ombi.Core.Models;
|
||||||
using Ombi.Core.Models.Requests;
|
using Ombi.Core.Models.Requests;
|
||||||
using Ombi.Core.Models.UI;
|
using Ombi.Core.Models.UI;
|
||||||
|
using Ombi.Core.Services;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||||
|
@ -22,16 +23,18 @@ namespace Ombi.Controllers.V1
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class MusicRequestController : ControllerBase
|
public class MusicRequestController : ControllerBase
|
||||||
{
|
{
|
||||||
public MusicRequestController(IMusicRequestEngine engine, IVoteEngine voteEngine, ILogger<MusicRequestController> log)
|
public MusicRequestController(IMusicRequestEngine engine, IVoteEngine voteEngine, ILogger<MusicRequestController> log, IRequestLimitService requestLimitService)
|
||||||
{
|
{
|
||||||
_engine = engine;
|
_engine = engine;
|
||||||
_voteEngine = voteEngine;
|
_voteEngine = voteEngine;
|
||||||
_log = log;
|
_log = log;
|
||||||
|
_requestLimitService = requestLimitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IMusicRequestEngine _engine;
|
private readonly IMusicRequestEngine _engine;
|
||||||
private readonly IVoteEngine _voteEngine;
|
private readonly IVoteEngine _voteEngine;
|
||||||
private readonly ILogger _log;
|
private readonly ILogger _log;
|
||||||
|
private readonly IRequestLimitService _requestLimitService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets album requests.
|
/// Gets album requests.
|
||||||
|
@ -169,7 +172,7 @@ namespace Ombi.Controllers.V1
|
||||||
[HttpGet("remaining")]
|
[HttpGet("remaining")]
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingMusicRequests()
|
public async Task<RequestQuotaCountModel> GetRemainingMusicRequests()
|
||||||
{
|
{
|
||||||
return await _engine.GetRemainingRequests();
|
return await _requestLimitService.GetRemainingMusicRequests();
|
||||||
}
|
}
|
||||||
private string GetApiAlias()
|
private string GetApiAlias()
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ using Ombi.Core.Engine.Interfaces;
|
||||||
using Ombi.Core.Models;
|
using Ombi.Core.Models;
|
||||||
using Ombi.Core.Models.Requests;
|
using Ombi.Core.Models.Requests;
|
||||||
using Ombi.Core.Models.UI;
|
using Ombi.Core.Models.UI;
|
||||||
|
using Ombi.Core.Services;
|
||||||
using Ombi.Models;
|
using Ombi.Models;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
@ -23,13 +24,16 @@ namespace Ombi.Controllers.V1
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class RequestController : ControllerBase
|
public class RequestController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly IRequestLimitService _requestLimitService;
|
||||||
|
|
||||||
public RequestController(IMovieRequestEngine engine, ITvRequestEngine tvRequestEngine, IVoteEngine vote,
|
public RequestController(IMovieRequestEngine engine, ITvRequestEngine tvRequestEngine, IVoteEngine vote,
|
||||||
ILogger<RequestController> log)
|
ILogger<RequestController> log, IRequestLimitService requestLimitService)
|
||||||
{
|
{
|
||||||
MovieRequestEngine = engine;
|
MovieRequestEngine = engine;
|
||||||
TvRequestEngine = tvRequestEngine;
|
TvRequestEngine = tvRequestEngine;
|
||||||
VoteEngine = vote;
|
VoteEngine = vote;
|
||||||
Log = log;
|
Log = log;
|
||||||
|
_requestLimitService = requestLimitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMovieRequestEngine MovieRequestEngine { get; }
|
private IMovieRequestEngine MovieRequestEngine { get; }
|
||||||
|
@ -523,7 +527,7 @@ namespace Ombi.Controllers.V1
|
||||||
[HttpGet("movie/remaining")]
|
[HttpGet("movie/remaining")]
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingMovieRequests()
|
public async Task<RequestQuotaCountModel> GetRemainingMovieRequests()
|
||||||
{
|
{
|
||||||
return await MovieRequestEngine.GetRemainingRequests();
|
return await _requestLimitService.GetRemainingMovieRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -532,7 +536,7 @@ namespace Ombi.Controllers.V1
|
||||||
[HttpGet("tv/remaining")]
|
[HttpGet("tv/remaining")]
|
||||||
public async Task<RequestQuotaCountModel> GetRemainingTvRequests()
|
public async Task<RequestQuotaCountModel> GetRemainingTvRequests()
|
||||||
{
|
{
|
||||||
return await TvRequestEngine.GetRemainingRequests();
|
return await _requestLimitService.GetRemainingTvRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetApiAlias()
|
private string GetApiAlias()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue