diff --git a/NzbDrone.Core/Repository/RootDir.cs b/NzbDrone.Core/Repository/RootDir.cs index 7cb43d9e4..6e6383374 100644 --- a/NzbDrone.Core/Repository/RootDir.cs +++ b/NzbDrone.Core/Repository/RootDir.cs @@ -1,26 +1,14 @@ using System.Collections.Generic; +using NzbDrone.Core.RootFolders; using PetaPoco; namespace NzbDrone.Core.Repository { - public interface IRootDir - { - int Id { get; set; } - string Path { get; set; } - - [ResultColumn] - ulong FreeSpace { get; set; } - - [Ignore] - List UnmappedFolders { get; set; } - } [TableName("RootDirs")] [PrimaryKey("Id", autoIncrement = true)] - public class RootDir : IRootDir + public class RootDir : BaseModel { - public virtual int Id { get; set; } - public string Path { get; set; } [ResultColumn] diff --git a/NzbDrone.Core/RootFolders/RootFolderRepository.cs b/NzbDrone.Core/RootFolders/RootFolderRepository.cs index 3492c6a15..ff3f7dd7c 100644 --- a/NzbDrone.Core/RootFolders/RootFolderRepository.cs +++ b/NzbDrone.Core/RootFolders/RootFolderRepository.cs @@ -1,45 +1,73 @@ using System.Collections.Generic; +using Eloquera.Client; using NzbDrone.Core.Datastore; using NzbDrone.Core.Repository; using System.Linq; namespace NzbDrone.Core.RootFolders { - public interface IRootFolderRepository + + public abstract class BaseModel { - List All(); - RootDir Get(int rootFolderId); - RootDir Add(RootDir rootFolder); + [ID] + public int Id; + } + + public interface IBasicRepository + { + List All(); + TModel Get(int rootFolderId); + TModel Add(TModel rootFolder); void Delete(int rootFolderId); } - public class RootFolderRepository : IRootFolderRepository + + public abstract class BasicRepository : IBasicRepository where TModel : BaseModel, new() { - private readonly EloqueraDb _db; - public RootFolderRepository(EloqueraDb db) + + public BasicRepository(EloqueraDb eloqueraDb) { - _db = db; + EloqueraDb = eloqueraDb; } - public List All() + protected EloqueraDb EloqueraDb { get; private set; } + + + public List All() { - return _db.AsQueryable().ToList(); + return EloqueraDb.AsQueryable().ToList(); } - public RootDir Get(int rootFolderId) + public TModel Get(int rootFolderId) { - return _db.AsQueryable().Single(c => c.Id == rootFolderId); + return EloqueraDb.AsQueryable().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) { - _db.Delete(Get(rootFolderId)); + var itemToDelete = Get(rootFolderId); + EloqueraDb.Delete(itemToDelete); + } + } + + public interface IRootFolderRepository : IBasicRepository + { + + } + + + //This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically. + public class RootFolderRepository : BasicRepository, IRootFolderRepository + { + public RootFolderRepository(EloqueraDb eloqueraDb) + : base(eloqueraDb) + { } }