| | | 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<List<UserStorageConfig>> GetAllActiveAsync(CancellationToken ct); |
| | | 11 | | Task<List<UserStorageConfig>> GetActiveByUserIdAsync(Guid userId, CancellationToken ct); |
| | | 12 | | Task<List<UserStorageConfig>> GetByUserIdAsync(Guid userId, CancellationToken ct); |
| | | 13 | | void Add(UserStorageConfig config); |
| | | 14 | | void Remove(UserStorageConfig config); |
| | | 15 | | } |
| | | 16 | | |
| | 13 | 17 | | public sealed class EfUserStorageConfigRepository(AnichronDbContext db) : IUserStorageConfigRepository |
| | | 18 | | { |
| | | 19 | | public Task<UserStorageConfig?> FindByIdAsync(Guid configId, CancellationToken ct) |
| | 3 | 20 | | => db.StorageConfigs.FirstOrDefaultAsync(s => s.Id == configId, ct); |
| | | 21 | | |
| | | 22 | | public Task<UserStorageConfig?> FindByRootPathAsync(string rootPath, CancellationToken ct) |
| | 4 | 23 | | => db.StorageConfigs.FirstOrDefaultAsync(s => s.RootPath == rootPath, ct); |
| | | 24 | | |
| | | 25 | | public Task<List<UserStorageConfig>> GetAllActiveAsync(CancellationToken ct) |
| | 2 | 26 | | => db.StorageConfigs.Where(s => s.IsActive).ToListAsync(ct); |
| | | 27 | | |
| | | 28 | | public Task<List<UserStorageConfig>> GetActiveByUserIdAsync(Guid userId, CancellationToken ct) |
| | 2 | 29 | | => db.StorageConfigs.Where(s => s.UserId == userId && s.IsActive).ToListAsync(ct); |
| | | 30 | | |
| | | 31 | | public Task<List<UserStorageConfig>> GetByUserIdAsync(Guid userId, CancellationToken ct) |
| | 2 | 32 | | => db.StorageConfigs.Where(s => s.UserId == userId).ToListAsync(ct); |
| | | 33 | | |
| | | 34 | | public void Add(UserStorageConfig config) |
| | 1 | 35 | | => db.StorageConfigs.Add(config); |
| | | 36 | | |
| | | 37 | | public void Remove(UserStorageConfig config) |
| | 1 | 38 | | => db.StorageConfigs.Remove(config); |
| | | 39 | | } |