big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-11-17 13:14:05 +02:00
parent 22529c26ec
commit e7ea5a8ded
38 changed files with 808 additions and 157 deletions
@@ -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);
}
}