A lot of clean up and added a new Image api #865

This commit is contained in:
Jamie.Rees 2017-08-01 16:14:47 +01:00
commit 1eb18b3187
32 changed files with 454 additions and 61 deletions

View file

@ -23,7 +23,7 @@ namespace Ombi.Store.Context
DbSet<NotificationTemplates> NotificationTemplates { get; set; }
DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
void Seed();
DbSet<Audit> Audit { get; set; }
DbSet<MovieRequests> MovieRequests { get; set; }
DbSet<TvRequests> TvRequests { get; set; }
DbSet<ChildRequests> ChildRequests { get; set; }

View file

@ -34,6 +34,8 @@ namespace Ombi.Store.Context
public DbSet<MovieIssues> MovieIssues { get; set; }
public DbSet<TvIssues> TvIssues { get; set; }
public DbSet<Audit> Audit { get; set; }
public DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@ -44,6 +46,30 @@ namespace Ombi.Store.Context
public void Seed()
{
// Add the tokens
var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
if (fanArt == null)
{
ApplicationConfigurations.Add(new ApplicationConfiguration
{
Type = ConfigurationTypes.FanartTv,
Value = "4b6d983efa54d8f45c68432521335f15"
});
SaveChanges();
}
var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
if (movieDb == null)
{
ApplicationConfigurations.Add(new ApplicationConfiguration
{
Type = ConfigurationTypes.TheMovieDb,
Value = "b8eabaf5608b88d0298aa189dd90bf00"
});
SaveChanges();
}
// Check if templates exist
var templates = NotificationTemplates.ToList();
if (templates.Any())

View file

@ -13,5 +13,7 @@ namespace Ombi.Store.Entities
{
Url,
Port,
FanartTv,
TheMovieDb
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace Ombi.Store.Entities
{
[Table("Audit")]
public class Audit : Entity
{
public DateTime DateTime { get; set; }
public string Description { get; set; }
public AuditType AuditType { get; set; }
public AuditArea AuditArea { get; set; }
public string User { get; set; }
}
public enum AuditType
{
None,
Created,
Updated,
Deleted,
Approved,
Denied,
Success,
Fail,
Added
}
public enum AuditArea
{
Authentication,
User,
TvRequest,
MovieRequest,
}
}

View file

@ -10,7 +10,7 @@ using Ombi.Helpers;
namespace Ombi.Store.Migrations
{
[DbContext(typeof(OmbiContext))]
[Migration("20170728131851_Inital")]
[Migration("20170801143617_Inital")]
partial class Inital
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -139,6 +139,26 @@ namespace Ombi.Store.Migrations
b.ToTable("ApplicationConfiguration");
});
modelBuilder.Entity("Ombi.Store.Entities.Audit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AuditArea");
b.Property<int>("AuditType");
b.Property<DateTime>("DateTime");
b.Property<string>("Description");
b.Property<string>("User");
b.HasKey("Id");
b.ToTable("Audit");
});
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
{
b.Property<int>("Id")

View file

@ -50,6 +50,23 @@ namespace Ombi.Store.Migrations
table.PrimaryKey("PK_ApplicationConfiguration", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Audit",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
AuditArea = table.Column<int>(nullable: false),
AuditType = table.Column<int>(nullable: false),
DateTime = table.Column<DateTime>(nullable: false),
Description = table.Column<string>(nullable: true),
User = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Audit", x => x.Id);
});
migrationBuilder.CreateTable(
name: "GlobalSettings",
columns: table => new
@ -545,6 +562,9 @@ namespace Ombi.Store.Migrations
migrationBuilder.DropTable(
name: "ApplicationConfiguration");
migrationBuilder.DropTable(
name: "Audit");
migrationBuilder.DropTable(
name: "GlobalSettings");

View file

@ -138,6 +138,26 @@ namespace Ombi.Store.Migrations
b.ToTable("ApplicationConfiguration");
});
modelBuilder.Entity("Ombi.Store.Entities.Audit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AuditArea");
b.Property<int>("AuditType");
b.Property<DateTime>("DateTime");
b.Property<string>("Description");
b.Property<string>("User");
b.HasKey("Id");
b.ToTable("Audit");
});
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
{
b.Property<int>("Id")

View file

@ -0,0 +1,23 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Store.Context;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public class ApplicationConfigRepository : IApplicationConfigRepository
{
public ApplicationConfigRepository(IOmbiContext ctx)
{
Ctx = ctx;
}
private IOmbiContext Ctx { get; }
public async Task<ApplicationConfiguration> Get(ConfigurationTypes type)
{
return await Ctx.ApplicationConfigurations.FirstOrDefaultAsync(x => x.Type == type);
}
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Ombi.Store.Context;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public class AuditRepository : IAuditRepository
{
public AuditRepository(IOmbiContext ctx)
{
Ctx = ctx;
}
private IOmbiContext Ctx { get; }
public async Task Record(AuditType type, AuditArea area, string description)
{
await Record(type, area, description, string.Empty);
}
public async Task Record(AuditType type, AuditArea area, string description, string user)
{
await Ctx.Audit.AddAsync(new Audit
{
User = user,
AuditArea = area,
AuditType = type,
DateTime = DateTime.UtcNow,
Description = description
});
await Ctx.SaveChangesAsync();
}
}
}

View file

@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public interface IApplicationConfigRepository
{
Task<ApplicationConfiguration> Get(ConfigurationTypes type);
}
}

View file

@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Ombi.Store.Entities;
namespace Ombi.Store.Repository
{
public interface IAuditRepository
{
Task Record(AuditType type, AuditArea area, string description);
Task Record(AuditType type, AuditArea area, string description, string user);
}
}