mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-22 14:13:36 -07:00
Started on #16, nothing is hooked up yet.
This commit is contained in:
parent
f4a60da40d
commit
07b42ffd50
14 changed files with 355 additions and 12 deletions
65
PlexRequests.Store/IRequestRepository.cs
Normal file
65
PlexRequests.Store/IRequestRepository.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ISettingsRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Collections.Generic;
|
||||
|
||||
using PlexRequests.Store.Models;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
{
|
||||
public interface IRequestRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
long Insert(RequestBlobs entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<RequestBlobs> GetAll();
|
||||
|
||||
RequestBlobs Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Delete(RequestBlobs entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
bool Update(RequestBlobs entity);
|
||||
|
||||
bool UpdateAll(IEnumerable<RequestBlobs> entity);
|
||||
}
|
||||
}
|
38
PlexRequests.Store/Models/RequestBlobs.cs
Normal file
38
PlexRequests.Store/Models/RequestBlobs.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: RequestBlobs.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using Dapper.Contrib.Extensions;
|
||||
|
||||
namespace PlexRequests.Store.Models
|
||||
{
|
||||
[Table("RequestBlobs")]
|
||||
public class RequestBlobs : Entity
|
||||
{
|
||||
public int ProviderId { get; set; }
|
||||
public byte[] Content { get; set; }
|
||||
public RequestType Type { get; set; }
|
||||
}
|
||||
}
|
|
@ -58,13 +58,16 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="DbConfiguration.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="IRequestRepository.cs" />
|
||||
<Compile Include="ISettingsRepository.cs" />
|
||||
<Compile Include="ISqliteConfiguration.cs" />
|
||||
<Compile Include="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\JsonRepository.cs" />
|
||||
<Compile Include="Repository\SettingsJsonRepository.cs" />
|
||||
<Compile Include="Repository\RequestJsonRepository.cs" />
|
||||
<Compile Include="SettingsModel.cs" />
|
||||
<Compile Include="GenericRepository.cs" />
|
||||
<Compile Include="RequestedModel.cs" />
|
||||
|
|
127
PlexRequests.Store/Repository/RequestJsonRepository.cs
Normal file
127
PlexRequests.Store/Repository/RequestJsonRepository.cs
Normal file
|
@ -0,0 +1,127 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: SettingsJsonRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Dapper.Contrib.Extensions;
|
||||
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Store.Models;
|
||||
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public class RequestJsonRepository : IRequestRepository
|
||||
{
|
||||
private ICacheProvider Cache { get; }
|
||||
|
||||
private string TypeName { get; }
|
||||
public RequestJsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
{
|
||||
Db = config;
|
||||
Cache = cacheProvider;
|
||||
TypeName = typeof(RequestJsonRepository).Name;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration Db { get; }
|
||||
|
||||
public long Insert(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RequestBlobs> GetAll()
|
||||
{
|
||||
var key = TypeName + "GetAll";
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.GetAll<RequestBlobs>();
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public RequestBlobs Get(int id)
|
||||
{
|
||||
var key = TypeName + "Get";
|
||||
var item = Cache.GetOrSet(key, () =>
|
||||
{
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
var page = con.Get<RequestBlobs>(id);
|
||||
return page;
|
||||
}
|
||||
}, 5);
|
||||
return item;
|
||||
}
|
||||
|
||||
public bool Delete(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Delete(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(RequestBlobs entity)
|
||||
{
|
||||
ResetCache();
|
||||
using (var con = Db.DbConnection())
|
||||
{
|
||||
return con.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCache()
|
||||
{
|
||||
Cache.Remove("Get");
|
||||
Cache.Remove(TypeName + "GetAll");
|
||||
}
|
||||
|
||||
public bool UpdateAll(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
var result = new HashSet<bool>();
|
||||
|
||||
using (var db = Db.DbConnection())
|
||||
{
|
||||
db.Open();
|
||||
foreach (var e in entity)
|
||||
{
|
||||
result.Add(db.Update(e));
|
||||
}
|
||||
}
|
||||
return result.All(x => true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: JsonRepository.cs
|
||||
// File: SettingsJsonRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
@ -34,16 +34,16 @@ using PlexRequests.Store.Models;
|
|||
|
||||
namespace PlexRequests.Store.Repository
|
||||
{
|
||||
public class JsonRepository : ISettingsRepository
|
||||
public class SettingsJsonRepository : ISettingsRepository
|
||||
{
|
||||
private ICacheProvider Cache { get; set; }
|
||||
|
||||
private string TypeName { get; set; }
|
||||
public JsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
public SettingsJsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider)
|
||||
{
|
||||
Db = config;
|
||||
Cache = cacheProvider;
|
||||
TypeName = typeof(JsonRepository).Name;
|
||||
TypeName = typeof(SettingsJsonRepository).Name;
|
||||
}
|
||||
|
||||
private ISqliteConfiguration Db { get; set; }
|
|
@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS Settings
|
|||
PlexAuthToken varchar(50)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Requested
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -45,6 +46,14 @@ CREATE TABLE IF NOT EXISTS GlobalSettings
|
|||
Content varchar(100) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS RequestBlobs
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ProviderId INTEGER NOT NULL,
|
||||
Type INTEGER NOT NULL,
|
||||
Content BLOB NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Log
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue