mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 14:10:50 -07:00
Switched over to the new service
This commit is contained in:
parent
f5cb4d6879
commit
5f26aecb98
8 changed files with 30 additions and 28 deletions
|
@ -34,8 +34,8 @@ namespace PlexRequests.Core
|
||||||
{
|
{
|
||||||
long AddRequest(int providerId, RequestedModel model);
|
long AddRequest(int providerId, RequestedModel model);
|
||||||
bool CheckRequest(int providerId);
|
bool CheckRequest(int providerId);
|
||||||
void DeleteRequest(int tmdbId);
|
void DeleteRequest(RequestedModel request);
|
||||||
void UpdateRequest(RequestedModel model);
|
bool UpdateRequest(RequestedModel model);
|
||||||
RequestedModel Get(int id);
|
RequestedModel Get(int id);
|
||||||
IEnumerable<RequestedModel> GetAll();
|
IEnumerable<RequestedModel> GetAll();
|
||||||
bool BatchUpdate(List<RequestedModel> model);
|
bool BatchUpdate(List<RequestedModel> model);
|
||||||
|
|
|
@ -44,6 +44,9 @@ namespace PlexRequests.Core
|
||||||
private IRequestRepository Repo { get; }
|
private IRequestRepository Repo { get; }
|
||||||
public long AddRequest(int providerId, RequestedModel model)
|
public long AddRequest(int providerId, RequestedModel model)
|
||||||
{
|
{
|
||||||
|
var latestId = Repo.GetAll().OrderByDescending(x => x.Id).Select(x => x.Id).FirstOrDefault();
|
||||||
|
var newId = latestId + 1;
|
||||||
|
model.Id = newId;
|
||||||
var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId};
|
var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId};
|
||||||
|
|
||||||
return Repo.Insert(entity);
|
return Repo.Insert(entity);
|
||||||
|
@ -55,16 +58,16 @@ namespace PlexRequests.Core
|
||||||
return blobs.Any(x => x.ProviderId == providerId);
|
return blobs.Any(x => x.ProviderId == providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteRequest(int tmdbId)
|
public void DeleteRequest(RequestedModel request)
|
||||||
{
|
{
|
||||||
var blob = Repo.GetAll().FirstOrDefault(x => x.ProviderId == tmdbId);
|
var blob = Repo.Get(request.Id);
|
||||||
Repo.Delete(blob);
|
Repo.Delete(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRequest(RequestedModel model)
|
public bool UpdateRequest(RequestedModel model)
|
||||||
{
|
{
|
||||||
var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId, Id = model.Id};
|
var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId, Id = model.Id};
|
||||||
Repo.Update(entity);
|
return Repo.Update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestedModel Get(int id)
|
public RequestedModel Get(int id)
|
||||||
|
@ -85,7 +88,7 @@ namespace PlexRequests.Core
|
||||||
|
|
||||||
public bool BatchUpdate(List<RequestedModel> model)
|
public bool BatchUpdate(List<RequestedModel> model)
|
||||||
{
|
{
|
||||||
var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ReturnBytes(m), ProviderId = m.ProviderId }).ToList();
|
var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id}).ToList();
|
||||||
return Repo.UpdateAll(entities);
|
return Repo.UpdateAll(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,16 +50,15 @@ namespace PlexRequests.Core
|
||||||
return Repo.GetAll().Any(x => x.ProviderId == providerId);
|
return Repo.GetAll().Any(x => x.ProviderId == providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteRequest(int tmdbId)
|
public void DeleteRequest(RequestedModel model)
|
||||||
{
|
{
|
||||||
var entity = Repo.GetAll().FirstOrDefault(x => x.ProviderId == tmdbId);
|
var entity = Repo.Get(model.Id);
|
||||||
Repo.Delete(entity);
|
Repo.Delete(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRequest(RequestedModel model)
|
public bool UpdateRequest(RequestedModel model)
|
||||||
{
|
{
|
||||||
|
return Repo.Update(model);
|
||||||
Repo.Update(model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -53,7 +53,8 @@ namespace PlexRequests.Store.Repository
|
||||||
ResetCache();
|
ResetCache();
|
||||||
using (var con = Db.DbConnection())
|
using (var con = Db.DbConnection())
|
||||||
{
|
{
|
||||||
return con.Insert(entity);
|
var id = con.Insert(entity);
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace PlexRequests.UI
|
||||||
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
|
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
|
||||||
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
|
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
|
||||||
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
|
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
|
||||||
container.Register<IRequestService, RequestService>();
|
container.Register<IRequestService, JsonRequestService>();
|
||||||
|
|
||||||
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
|
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
|
||||||
container.Register<IConfigurationReader, ConfigurationReader>();
|
container.Register<IConfigurationReader, ConfigurationReader>();
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace PlexRequests.UI.Modules
|
||||||
public class ApprovalModule : BaseModule
|
public class ApprovalModule : BaseModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public ApprovalModule(IRepository<RequestedModel> service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
|
public ApprovalModule(IRequestService service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
|
||||||
ISettingsService<SonarrSettings> sonarrSettings) : base("approval")
|
ISettingsService<SonarrSettings> sonarrSettings) : base("approval")
|
||||||
{
|
{
|
||||||
this.RequiresAuthentication();
|
this.RequiresAuthentication();
|
||||||
|
@ -59,12 +59,12 @@ namespace PlexRequests.UI.Modules
|
||||||
Post["/approveall"] = x => ApproveAll();
|
Post["/approveall"] = x => ApproveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRepository<RequestedModel> Service { get; set; }
|
private IRequestService Service { get; }
|
||||||
|
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private ISettingsService<SonarrSettings> SonarrSettings { get; set; }
|
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||||
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||||
private ISonarrApi SonarrApi { get; set; }
|
private ISonarrApi SonarrApi { get; }
|
||||||
private ICouchPotatoApi CpApi { get; }
|
private ICouchPotatoApi CpApi { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -135,7 +135,7 @@ namespace PlexRequests.UI.Modules
|
||||||
request.Approved = true;
|
request.Approved = true;
|
||||||
|
|
||||||
// Update the record
|
// Update the record
|
||||||
var inserted = Service.Update(request);
|
var inserted = Service.UpdateRequest(request);
|
||||||
|
|
||||||
return Response.AsJson(inserted
|
return Response.AsJson(inserted
|
||||||
? new JsonResponseModel {Result = true}
|
? new JsonResponseModel {Result = true}
|
||||||
|
@ -195,7 +195,7 @@ namespace PlexRequests.UI.Modules
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var result = Service.UpdateAll(updatedRequests); return Response.AsJson(result
|
var result = Service.BatchUpdate(updatedRequests); return Response.AsJson(result
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
: new JsonResponseModel { Result = false, Message = "We could not approve all of the requests. Please try again or check the logs." });
|
: new JsonResponseModel { Result = false, Message = "We could not approve all of the requests. Please try again or check the logs." });
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace PlexRequests.UI.Modules
|
||||||
public class RequestsModule : BaseModule
|
public class RequestsModule : BaseModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public RequestsModule(IRepository<RequestedModel> service, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<PlexSettings> plex) : base("requests")
|
public RequestsModule(IRequestService service, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<PlexSettings> plex) : base("requests")
|
||||||
{
|
{
|
||||||
Service = service;
|
Service = service;
|
||||||
PrSettings = prSettings;
|
PrSettings = prSettings;
|
||||||
|
@ -64,7 +64,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Post["/addnote"] = _ => AddNote((int)Request.Form.requestId, (string)Request.Form.noteArea);
|
Post["/addnote"] = _ => AddNote((int)Request.Form.requestId, (string)Request.Form.noteArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRepository<RequestedModel> Service { get; }
|
private IRequestService Service { get; }
|
||||||
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
||||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentEntity = Service.Get(requestid);
|
var currentEntity = Service.Get(requestid);
|
||||||
Service.Delete(currentEntity);
|
Service.DeleteRequest(currentEntity);
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ namespace PlexRequests.UI.Modules
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
|
|
||||||
|
|
||||||
var result = Service.Update(originalRequest);
|
var result = Service.UpdateRequest(originalRequest);
|
||||||
return Response.AsJson(result
|
return Response.AsJson(result
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
: new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
: new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
||||||
|
@ -186,7 +186,7 @@ namespace PlexRequests.UI.Modules
|
||||||
originalRequest.Issues = IssueState.None;
|
originalRequest.Issues = IssueState.None;
|
||||||
originalRequest.OtherMessage = string.Empty;
|
originalRequest.OtherMessage = string.Empty;
|
||||||
|
|
||||||
var result = Service.Update(originalRequest);
|
var result = Service.UpdateRequest(originalRequest);
|
||||||
return Response.AsJson(result
|
return Response.AsJson(result
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
: new JsonResponseModel { Result = false, Message = "Could not clear issue, please try again or check the logs" });
|
: new JsonResponseModel { Result = false, Message = "Could not clear issue, please try again or check the logs" });
|
||||||
|
@ -202,7 +202,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
originalRequest.Available = available;
|
originalRequest.Available = available;
|
||||||
|
|
||||||
var result = Service.Update(originalRequest);
|
var result = Service.UpdateRequest(originalRequest);
|
||||||
return Response.AsJson(result
|
return Response.AsJson(result
|
||||||
? new { Result = true, Available = available, Message = string.Empty }
|
? new { Result = true, Available = available, Message = string.Empty }
|
||||||
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
|
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
|
||||||
|
@ -218,7 +218,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
originalRequest.AdminNote = noteArea;
|
originalRequest.AdminNote = noteArea;
|
||||||
|
|
||||||
var result = Service.Update(originalRequest);
|
var result = Service.UpdateRequest(originalRequest);
|
||||||
return Response.AsJson(result
|
return Response.AsJson(result
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
: new JsonResponseModel { Result = false, Message = "Could not update the notes, please try again or check the logs" });
|
: new JsonResponseModel { Result = false, Message = "Could not update the notes, please try again or check the logs" });
|
||||||
|
|
|
@ -71,7 +71,6 @@ namespace PlexRequests.UI
|
||||||
if (string.IsNullOrEmpty(uri))
|
if (string.IsNullOrEmpty(uri))
|
||||||
uri = GetStartupUri();
|
uri = GetStartupUri();
|
||||||
|
|
||||||
;
|
|
||||||
var options = new StartOptions(uri)
|
var options = new StartOptions(uri)
|
||||||
{
|
{
|
||||||
ServerFactory = "Microsoft.Owin.Host.HttpListener"
|
ServerFactory = "Microsoft.Owin.Host.HttpListener"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue