mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-11-24 08:42:19 +02:00
added repo base
This commit is contained in:
parent
9e4bb278ef
commit
34038245eb
@ -1,26 +1,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Core.RootFolders;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Repository
|
namespace NzbDrone.Core.Repository
|
||||||
{
|
{
|
||||||
public interface IRootDir
|
|
||||||
{
|
|
||||||
int Id { get; set; }
|
|
||||||
string Path { get; set; }
|
|
||||||
|
|
||||||
[ResultColumn]
|
|
||||||
ulong FreeSpace { get; set; }
|
|
||||||
|
|
||||||
[Ignore]
|
|
||||||
List<string> UnmappedFolders { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[TableName("RootDirs")]
|
[TableName("RootDirs")]
|
||||||
[PrimaryKey("Id", autoIncrement = true)]
|
[PrimaryKey("Id", autoIncrement = true)]
|
||||||
public class RootDir : IRootDir
|
public class RootDir : BaseModel
|
||||||
{
|
{
|
||||||
public virtual int Id { get; set; }
|
|
||||||
|
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
[ResultColumn]
|
[ResultColumn]
|
||||||
|
@ -1,45 +1,73 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Eloquera.Client;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.RootFolders
|
namespace NzbDrone.Core.RootFolders
|
||||||
{
|
{
|
||||||
public interface IRootFolderRepository
|
|
||||||
|
public abstract class BaseModel
|
||||||
{
|
{
|
||||||
List<RootDir> All();
|
[ID]
|
||||||
RootDir Get(int rootFolderId);
|
public int Id;
|
||||||
RootDir Add(RootDir rootFolder);
|
}
|
||||||
|
|
||||||
|
public interface IBasicRepository<TModel>
|
||||||
|
{
|
||||||
|
List<TModel> All();
|
||||||
|
TModel Get(int rootFolderId);
|
||||||
|
TModel Add(TModel rootFolder);
|
||||||
void Delete(int rootFolderId);
|
void Delete(int rootFolderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RootFolderRepository : IRootFolderRepository
|
|
||||||
|
public abstract class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : BaseModel, new()
|
||||||
{
|
{
|
||||||
private readonly EloqueraDb _db;
|
|
||||||
|
|
||||||
public RootFolderRepository(EloqueraDb db)
|
|
||||||
|
public BasicRepository(EloqueraDb eloqueraDb)
|
||||||
{
|
{
|
||||||
_db = db;
|
EloqueraDb = eloqueraDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RootDir> All()
|
protected EloqueraDb EloqueraDb { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public List<TModel> All()
|
||||||
{
|
{
|
||||||
return _db.AsQueryable<RootDir>().ToList();
|
return EloqueraDb.AsQueryable<TModel>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RootDir Get(int rootFolderId)
|
public TModel Get(int rootFolderId)
|
||||||
{
|
{
|
||||||
return _db.AsQueryable<RootDir>().Single(c => c.Id == rootFolderId);
|
return EloqueraDb.AsQueryable<TModel>().Single(c => c.Id == rootFolderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RootDir Add(RootDir rootFolder)
|
public TModel Add(TModel rootFolder)
|
||||||
{
|
{
|
||||||
return _db.Insert(rootFolder);
|
return EloqueraDb.Insert(rootFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete(int rootFolderId)
|
public void Delete(int rootFolderId)
|
||||||
{
|
{
|
||||||
_db.Delete(Get(rootFolderId));
|
var itemToDelete = Get(rootFolderId);
|
||||||
|
EloqueraDb.Delete(itemToDelete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IRootFolderRepository : IBasicRepository<RootDir>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically.
|
||||||
|
public class RootFolderRepository : BasicRepository<RootDir>, IRootFolderRepository
|
||||||
|
{
|
||||||
|
public RootFolderRepository(EloqueraDb eloqueraDb)
|
||||||
|
: base(eloqueraDb)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user