#1464 added the Plex episode cacher

#865
This commit is contained in:
Jamie.Rees 2017-08-23 16:00:13 +01:00
commit 0e6462bbd5
31 changed files with 410 additions and 33 deletions

View file

@ -15,6 +15,7 @@ namespace Ombi.Store.Context
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
DbSet<GlobalSettings> Settings { get; set; }
DbSet<PlexContent> PlexContent { get; set; }
DbSet<PlexEpisode> PlexEpisode { get; set; }
DbSet<RadarrCache> RadarrCache { get; set; }
DatabaseFacade Database { get; }
EntityEntry<T> Entry<T>(T entry) where T : class;

View file

@ -26,6 +26,7 @@ namespace Ombi.Store.Context
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
public DbSet<GlobalSettings> Settings { get; set; }
public DbSet<PlexContent> PlexContent { get; set; }
public DbSet<PlexEpisode> PlexEpisode { get; set; }
public DbSet<RadarrCache> RadarrCache { get; set; }
public DbSet<MovieRequests> MovieRequests { get; set; }

View file

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Ombi.Store.Entities
{
[Table("PlexEpisode")]
public class PlexEpisode : Entity
{
public int EpisodeNumber { get; set; }
public int SeasonNumber { get; set; }
public string Key { get; set; } // RatingKey
public string Title { get; set; }
/// <summary>
/// The Show key
/// </summary>
/// <value>
/// The parent key.
/// </value>
public string ParentKey { get; set; }
/// <summary>
/// The Series key
/// </summary>
/// <value>
/// The grandparent key.
/// </value>
public string GrandparentKey { get; set; }
}
}

View file

@ -10,7 +10,7 @@ using Ombi.Helpers;
namespace Ombi.Store.Migrations
{
[DbContext(typeof(OmbiContext))]
[Migration("20170811145836_Inital")]
[Migration("20170823144220_Inital")]
partial class Inital
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -271,6 +271,28 @@ namespace Ombi.Store.Migrations
b.ToTable("PlexContent");
});
modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("EpisodeNumber");
b.Property<string>("GrandparentKey");
b.Property<string>("Key");
b.Property<string>("ParentKey");
b.Property<int>("SeasonNumber");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("PlexEpisode");
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{
b.Property<int>("Id")

View file

@ -144,6 +144,24 @@ namespace Ombi.Store.Migrations
table.PrimaryKey("PK_PlexContent", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PlexEpisode",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
EpisodeNumber = table.Column<int>(nullable: false),
GrandparentKey = table.Column<string>(nullable: true),
Key = table.Column<string>(nullable: true),
ParentKey = table.Column<string>(nullable: true),
SeasonNumber = table.Column<int>(nullable: false),
Title = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PlexEpisode", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RadarrCache",
columns: table => new
@ -596,6 +614,9 @@ namespace Ombi.Store.Migrations
migrationBuilder.DropTable(
name: "NotificationTemplates");
migrationBuilder.DropTable(
name: "PlexEpisode");
migrationBuilder.DropTable(
name: "PlexSeasonsContent");

View file

@ -270,6 +270,28 @@ namespace Ombi.Store.Migrations
b.ToTable("PlexContent");
});
modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("EpisodeNumber");
b.Property<string>("GrandparentKey");
b.Property<string>("Key");
b.Property<string>("ParentKey");
b.Property<int>("SeasonNumber");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("PlexEpisode");
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{
b.Property<int>("Id")

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ombi.Store.Entities;
@ -13,5 +14,9 @@ namespace Ombi.Store.Repository
Task<PlexContent> Get(string providerId);
Task<PlexContent> GetByKey(string key);
Task Update(PlexContent existingContent);
IQueryable<PlexEpisode> GetAllEpisodes();
Task<PlexEpisode> Add(PlexEpisode content);
Task<PlexEpisode> GetEpisodeByKey(string key);
Task AddRange(IEnumerable<PlexEpisode> content);
}
}

View file

@ -26,6 +26,7 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Store.Context;
@ -81,5 +82,26 @@ namespace Ombi.Store.Repository
Db.PlexContent.Update(existingContent);
await Db.SaveChangesAsync();
}
public IQueryable<PlexEpisode> GetAllEpisodes()
{
return Db.PlexEpisode.AsQueryable();
}
public async Task<PlexEpisode> Add(PlexEpisode content)
{
await Db.PlexEpisode.AddAsync(content);
await Db.SaveChangesAsync();
return content;
}
public async Task<PlexEpisode> GetEpisodeByKey(string key)
{
return await Db.PlexEpisode.FirstOrDefaultAsync(x => x.Key == key);
}
public async Task AddRange(IEnumerable<PlexEpisode> content)
{
Db.PlexEpisode.AddRange(content);
await Db.SaveChangesAsync();
}
}
}

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -50,6 +51,10 @@ namespace Ombi.Store.Repository
public GlobalSettings Get(string pageName)
{
var entity = Db.Settings.FirstOrDefault(x => x.SettingsName == pageName);
if (entity == null)
{
throw new ArgumentNullException($"The setting {pageName} does not exist");
}
Db.Entry(entity).Reload();
return entity;
}