1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

added repo base

This commit is contained in:
kay.one 2013-02-03 22:27:58 -08:00
parent 9e4bb278ef
commit 34038245eb
2 changed files with 45 additions and 29 deletions

View File

@ -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<string> 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]

View File

@ -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<RootDir> All();
RootDir Get(int rootFolderId);
RootDir Add(RootDir rootFolder);
[ID]
public int Id;
}
public interface IBasicRepository<TModel>
{
List<TModel> All();
TModel Get(int rootFolderId);
TModel Add(TModel rootFolder);
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)
{
_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)
{
}
}