mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:16:30 +00:00
big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using LinqToDB;
|
||||
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class AnnotationRepository : IAnnotationRepository
|
||||
{
|
||||
private readonly IDbFactory _dbFactory;
|
||||
|
||||
public AnnotationRepository(IDbFactory dbFactory)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
}
|
||||
|
||||
public async Task<List<Annotation>> GetByMediaHashAsync(string hash, CancellationToken ct = default)
|
||||
{
|
||||
return await _dbFactory.Run(async db =>
|
||||
await db.GetTable<Annotation>()
|
||||
.Where(x => x.MediaHash == hash)
|
||||
.ToListAsync(ct));
|
||||
}
|
||||
|
||||
public async Task<Annotation?> GetByNameAsync(string name, CancellationToken ct = default)
|
||||
{
|
||||
return await _dbFactory.Run(async db =>
|
||||
await db.GetTable<Annotation>()
|
||||
.FirstOrDefaultAsync(x => x.Name == name, ct));
|
||||
}
|
||||
|
||||
public async Task<List<Annotation>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
return await _dbFactory.Run(async db =>
|
||||
await db.GetTable<Annotation>().ToListAsync(ct));
|
||||
}
|
||||
|
||||
public async Task SaveAsync(Annotation annotation, CancellationToken ct = default)
|
||||
{
|
||||
await _dbFactory.RunWrite(async db =>
|
||||
{
|
||||
await db.InsertOrReplaceAsync(annotation, token: ct);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(List<string> names, CancellationToken ct = default)
|
||||
{
|
||||
await _dbFactory.DeleteAnnotations(names, ct);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user