| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Core.Data.Repository; |
| | | 5 | | |
| | | 6 | | public interface IUserStorageConfigRepository |
| | | 7 | | { |
| | | 8 | | Task<UserStorageConfig?> FindByIdAsync(Guid configId, CancellationToken ct); |
| | | 9 | | Task<UserStorageConfig?> FindByRootPathAsync(string rootPath, CancellationToken ct); |
| | | 10 | | Task<string[]> GetAllRootPathsAsync(CancellationToken ct); |
| | | 11 | | Task<List<UserStorageConfig>> GetAllActiveAsync(CancellationToken ct); |
| | | 12 | | Task<List<UserStorageConfig>> GetActiveByUserIdAsync(Guid userId, CancellationToken ct); |
| | | 13 | | Task<bool> AnyActiveByUserIdAsync(Guid userId, CancellationToken ct); |
| | | 14 | | Task<List<UserStorageConfig>> GetByUserIdAsync(Guid userId, CancellationToken ct); |
| | | 15 | | void Add(UserStorageConfig config); |
| | | 16 | | void Remove(UserStorageConfig config); |
| | | 17 | | } |
| | | 18 | | |
| | 92 | 19 | | public sealed class EfUserStorageConfigRepository(AnichronDbContext db) : IUserStorageConfigRepository |
| | | 20 | | { |
| | | 21 | | public Task<UserStorageConfig?> FindByIdAsync(Guid configId, CancellationToken ct) |
| | 76 | 22 | | => db.StorageConfigs.FirstOrDefaultAsync(s => s.Id == configId, ct); |
| | | 23 | | |
| | | 24 | | public Task<UserStorageConfig?> FindByRootPathAsync(string rootPath, CancellationToken ct) |
| | 4 | 25 | | => db.StorageConfigs.FirstOrDefaultAsync(s => s.RootPath == rootPath, ct); |
| | | 26 | | |
| | | 27 | | public Task<string[]> GetAllRootPathsAsync(CancellationToken ct) |
| | 0 | 28 | | => db.StorageConfigs.Select(s => s.RootPath).ToArrayAsync(ct); |
| | | 29 | | |
| | | 30 | | public Task<List<UserStorageConfig>> GetAllActiveAsync(CancellationToken ct) |
| | 2 | 31 | | => db.StorageConfigs.Where(s => s.IsActive).ToListAsync(ct); |
| | | 32 | | |
| | | 33 | | public Task<List<UserStorageConfig>> GetActiveByUserIdAsync(Guid userId, CancellationToken ct) |
| | 2 | 34 | | => ActiveOf(userId).ToListAsync(ct); |
| | | 35 | | |
| | | 36 | | public Task<bool> AnyActiveByUserIdAsync(Guid userId, CancellationToken ct) |
| | 4 | 37 | | => ActiveOf(userId).AnyAsync(ct); |
| | | 38 | | |
| | | 39 | | internal IQueryable<UserStorageConfig> ActiveOf(Guid userId) |
| | 7 | 40 | | => db.StorageConfigs.Where(s => s.UserId == userId && s.IsActive); |
| | | 41 | | |
| | | 42 | | public Task<List<UserStorageConfig>> GetByUserIdAsync(Guid userId, CancellationToken ct) |
| | 2 | 43 | | => db.StorageConfigs.Where(s => s.UserId == userId).ToListAsync(ct); |
| | | 44 | | |
| | | 45 | | public void Add(UserStorageConfig config) |
| | 1 | 46 | | => db.StorageConfigs.Add(config); |
| | | 47 | | |
| | | 48 | | public void Remove(UserStorageConfig config) |
| | 1 | 49 | | => db.StorageConfigs.Remove(config); |
| | | 50 | | } |