mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Done most on #59
This commit is contained in:
parent
0585ff73ec
commit
c7ac8a7d99
32 changed files with 345 additions and 2283 deletions
|
@ -26,11 +26,13 @@
|
|||
#endregion
|
||||
using System;
|
||||
|
||||
using Dapper.Contrib.Extensions;
|
||||
|
||||
namespace PlexRequests.Store.Models
|
||||
{
|
||||
[Table("Logs")]
|
||||
public class LogEntity : Entity
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public string Level { get; set; }
|
||||
public string Logger { get; set; }
|
||||
|
|
|
@ -58,17 +58,17 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="DbConfiguration.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="IRequestRepository.cs" />
|
||||
<Compile Include="ISettingsRepository.cs" />
|
||||
<Compile Include="Repository\IRequestRepository.cs" />
|
||||
<Compile Include="Repository\ISettingsRepository.cs" />
|
||||
<Compile Include="ISqliteConfiguration.cs" />
|
||||
<Compile Include="IRepository.cs" />
|
||||
<Compile Include="Repository\IRepository.cs" />
|
||||
<Compile Include="Models\GlobalSettings.cs" />
|
||||
<Compile Include="Models\LogEntity.cs" />
|
||||
<Compile Include="Models\RequestBlobs.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repository\SettingsJsonRepository.cs" />
|
||||
<Compile Include="Repository\RequestJsonRepository.cs" />
|
||||
<Compile Include="GenericRepository.cs" />
|
||||
<Compile Include="Repository\GenericRepository.cs" />
|
||||
<Compile Include="RequestedModel.cs" />
|
||||
<Compile Include="UserEntity.cs" />
|
||||
<Compile Include="UsersModel.cs" />
|
||||
|
|
|
@ -34,20 +34,23 @@ using NLog;
|
|||
|
||||
using PlexRequests.Helpers;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public class GenericRepository<T> : IRepository<T> where T : Entity
|
||||
{
|
||||
public GenericRepository(ISqliteConfiguration config)
|
||||
private ICacheProvider Cache { get; }
|
||||
public GenericRepository(ISqliteConfiguration config, ICacheProvider cache)
|
||||
{
|
||||
Config = config;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private ISqliteConfiguration Config { get; set; }
|
||||
private ISqliteConfiguration Config { get; }
|
||||
public long Insert(T entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var cnn = Config.DbConnection())
|
||||
{
|
||||
cnn.Open();
|
||||
|
@ -57,12 +60,14 @@ namespace PlexRequests.Store
|
|||
|
||||
public IEnumerable<T> GetAll()
|
||||
{
|
||||
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
var result = db.GetAll<T>();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public T Get(string id)
|
||||
|
@ -72,15 +77,23 @@ namespace PlexRequests.Store
|
|||
|
||||
public T Get(int id)
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return db.Get<T>(id);
|
||||
}
|
||||
var key = "Get" + id;
|
||||
var item = Cache.GetOrSet(
|
||||
key,
|
||||
() =>
|
||||
{
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
return db.Get<T>(id);
|
||||
}
|
||||
});
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Delete(T entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var db = Config.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
|
@ -90,6 +103,7 @@ namespace PlexRequests.Store
|
|||
|
||||
public bool Update(T entity)
|
||||
{
|
||||
ResetCache();
|
||||
Log.Trace("Updating entity");
|
||||
Log.Trace(entity.DumpJson());
|
||||
using (var db = Config.DbConnection())
|
||||
|
@ -101,6 +115,7 @@ namespace PlexRequests.Store
|
|||
|
||||
public bool UpdateAll(IEnumerable<T> entity)
|
||||
{
|
||||
ResetCache();
|
||||
Log.Trace("Updating all entities");
|
||||
var result = new HashSet<bool>();
|
||||
|
||||
|
@ -114,5 +129,11 @@ namespace PlexRequests.Store
|
|||
}
|
||||
return result.All(x => true);
|
||||
}
|
||||
|
||||
private void ResetCache()
|
||||
{
|
||||
Cache.Remove("Get");
|
||||
Cache.Remove("GetAll");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
#endregion
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
|
@ -28,7 +28,7 @@ using System.Collections.Generic;
|
|||
|
||||
using PlexRequests.Store.Models;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public interface IRequestRepository
|
||||
{
|
|
@ -28,7 +28,7 @@ using System.Collections.Generic;
|
|||
|
||||
using PlexRequests.Store.Models;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public interface ISettingsRepository
|
||||
{
|
|
@ -30,6 +30,8 @@ using System.Linq;
|
|||
|
||||
using Dapper.Contrib.Extensions;
|
||||
|
||||
using PlexRequests.Store.Repository;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
{
|
||||
public class UserRepository<T> : IRepository<T> where T : UserEntity
|
||||
|
|
|
@ -33,5 +33,6 @@ namespace PlexRequests.Store
|
|||
{
|
||||
public byte[] Hash { get; set; }
|
||||
public byte[] Salt { get; set; }
|
||||
public string[] Claims { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue