Availability Checker #1464 #865

This commit is contained in:
Jamie.Rees 2017-08-24 16:15:39 +01:00
commit 385d206287
24 changed files with 255 additions and 82 deletions

View file

@ -45,6 +45,16 @@ namespace Ombi.Store.Context
optionsBuilder.UseSqlite("Data Source=Ombi.db");
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<PlexEpisode>()
.HasOne(p => p.Series)
.WithMany(b => b.Episodes)
.HasPrincipalKey(x => x.Key)
.HasForeignKey(p => p.GrandparentKey);
base.OnModelCreating(builder);
}
public void Seed()
{

View file

@ -45,11 +45,13 @@ namespace Ombi.Store.Entities
/// Only used for TV Shows
/// </summary>
public virtual ICollection<PlexSeasonsContent> Seasons { get; set; }
public ICollection<PlexEpisode> Episodes { get; set; }
/// <summary>
/// Plex's internal ID for this item
/// </summary>
public string Key { get; set; }
public int Key { get; set; }
public DateTime AddedAt { get; set; }
}

View file

@ -7,21 +7,24 @@ namespace Ombi.Store.Entities
{
public int EpisodeNumber { get; set; }
public int SeasonNumber { get; set; }
public string Key { get; set; } // RatingKey
public int Key { get; set; } // RatingKey
public string Title { get; set; }
/// <summary>
/// The Show key
/// The Season key
/// </summary>
/// <value>
/// The parent key.
/// </value>
public string ParentKey { get; set; }
public int ParentKey { get; set; }
/// <summary>
/// The Series key
/// </summary>
/// <value>
/// The grandparent key.
/// </value>
public string GrandparentKey { get; set; }
public int GrandparentKey { get; set; }
public PlexContent Series { get; set; }
}
}

View file

@ -10,7 +10,7 @@ using Ombi.Helpers;
namespace Ombi.Store.Migrations
{
[DbContext(typeof(OmbiContext))]
[Migration("20170823144220_Inital")]
[Migration("20170824133349_Inital")]
partial class Inital
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -254,7 +254,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("AddedAt");
b.Property<string>("Key");
b.Property<int>("Key");
b.Property<string>("ProviderId");
@ -278,11 +278,11 @@ namespace Ombi.Store.Migrations
b.Property<int>("EpisodeNumber");
b.Property<string>("GrandparentKey");
b.Property<int>("GrandparentKey");
b.Property<string>("Key");
b.Property<int>("Key");
b.Property<string>("ParentKey");
b.Property<int>("ParentKey");
b.Property<int>("SeasonNumber");
@ -290,6 +290,8 @@ namespace Ombi.Store.Migrations
b.HasKey("Id");
b.HasIndex("GrandparentKey");
b.ToTable("PlexEpisode");
});
@ -568,6 +570,15 @@ namespace Ombi.Store.Migrations
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b =>
{
b.HasOne("Ombi.Store.Entities.PlexContent", "Series")
.WithMany("Episodes")
.HasForeignKey("GrandparentKey")
.HasPrincipalKey("Key")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{
b.HasOne("Ombi.Store.Entities.PlexContent")

View file

@ -132,7 +132,7 @@ namespace Ombi.Store.Migrations
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
AddedAt = table.Column<DateTime>(nullable: false),
Key = table.Column<string>(nullable: true),
Key = table.Column<int>(nullable: false),
ProviderId = table.Column<string>(nullable: true),
ReleaseYear = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true),
@ -142,24 +142,7 @@ namespace Ombi.Store.Migrations
constraints: table =>
{
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);
table.UniqueConstraint("AK_PlexContent_Key", x => x.Key);
});
migrationBuilder.CreateTable(
@ -334,6 +317,30 @@ namespace Ombi.Store.Migrations
onDelete: ReferentialAction.Restrict);
});
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<int>(nullable: false),
Key = table.Column<int>(nullable: false),
ParentKey = table.Column<int>(nullable: false),
SeasonNumber = table.Column<int>(nullable: false),
Title = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PlexEpisode", x => x.Id);
table.ForeignKey(
name: "FK_PlexEpisode_PlexContent_GrandparentKey",
column: x => x.GrandparentKey,
principalTable: "PlexContent",
principalColumn: "Key",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlexSeasonsContent",
columns: table => new
@ -529,6 +536,11 @@ namespace Ombi.Store.Migrations
column: "NormalizedUserName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PlexEpisode_GrandparentKey",
table: "PlexEpisode",
column: "GrandparentKey");
migrationBuilder.CreateIndex(
name: "IX_PlexSeasonsContent_PlexContentId",
table: "PlexSeasonsContent",

View file

@ -253,7 +253,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("AddedAt");
b.Property<string>("Key");
b.Property<int>("Key");
b.Property<string>("ProviderId");
@ -277,11 +277,11 @@ namespace Ombi.Store.Migrations
b.Property<int>("EpisodeNumber");
b.Property<string>("GrandparentKey");
b.Property<int>("GrandparentKey");
b.Property<string>("Key");
b.Property<int>("Key");
b.Property<string>("ParentKey");
b.Property<int>("ParentKey");
b.Property<int>("SeasonNumber");
@ -289,6 +289,8 @@ namespace Ombi.Store.Migrations
b.HasKey("Id");
b.HasIndex("GrandparentKey");
b.ToTable("PlexEpisode");
});
@ -567,6 +569,15 @@ namespace Ombi.Store.Migrations
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b =>
{
b.HasOne("Ombi.Store.Entities.PlexContent", "Series")
.WithMany("Episodes")
.HasForeignKey("GrandparentKey")
.HasPrincipalKey("Key")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{
b.HasOne("Ombi.Store.Entities.PlexContent")

View file

@ -12,11 +12,12 @@ namespace Ombi.Store.Repository
Task<bool> ContentExists(string providerId);
Task<IEnumerable<PlexContent>> GetAll();
Task<PlexContent> Get(string providerId);
Task<PlexContent> GetByKey(string key);
Task<PlexContent> GetByKey(int key);
Task Update(PlexContent existingContent);
IQueryable<PlexEpisode> GetAllEpisodes();
Task<PlexEpisode> Add(PlexEpisode content);
Task<PlexEpisode> GetEpisodeByKey(string key);
Task<PlexEpisode> GetEpisodeByKey(int key);
Task AddRange(IEnumerable<PlexEpisode> content);
IQueryable<PlexContent> Get();
}
}

View file

@ -72,7 +72,12 @@ namespace Ombi.Store.Repository
return await Db.PlexContent.FirstOrDefaultAsync(x => x.ProviderId == providerId);
}
public async Task<PlexContent> GetByKey(string key)
public IQueryable<PlexContent> Get()
{
return Db.PlexContent.AsQueryable();
}
public async Task<PlexContent> GetByKey(int key)
{
return await Db.PlexContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key);
}
@ -94,7 +99,7 @@ namespace Ombi.Store.Repository
await Db.SaveChangesAsync();
return content;
}
public async Task<PlexEpisode> GetEpisodeByKey(string key)
public async Task<PlexEpisode> GetEpisodeByKey(int key)
{
return await Db.PlexEpisode.FirstOrDefaultAsync(x => x.Key == key);
}

View file

@ -11,5 +11,6 @@ namespace Ombi.Store.Repository
IQueryable<MovieRequests> Get();
Task<MovieRequests> GetRequest(int theMovieDbId);
Task Update(MovieRequests request);
Task Save();
}
}

View file

@ -15,5 +15,6 @@ namespace Ombi.Store.Repository.Requests
Task Update(TvRequests request);
Task UpdateChild(ChildRequests request);
IQueryable<ChildRequests> GetChild();
Task Save();
}
}

View file

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Store.Context;
@ -46,5 +47,10 @@ namespace Ombi.Store.Repository.Requests
{
await Db.SaveChangesAsync();
}
}
public async Task Save()
{
await Db.SaveChangesAsync();
}
}
}

View file

@ -45,6 +45,11 @@ namespace Ombi.Store.Repository.Requests
.AsQueryable();
}
public async Task Save()
{
await Db.SaveChangesAsync();
}
public async Task<TvRequests> Add(TvRequests request)
{
await Db.TvRequests.AddAsync(request);