diff --git a/AsbCloudApp/Repositories/IFileCategoryRepository.cs b/AsbCloudApp/Repositories/IFileCategoryRepository.cs deleted file mode 100644 index 7e64b024..00000000 --- a/AsbCloudApp/Repositories/IFileCategoryRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data; -using AsbCloudApp.Services; - -namespace AsbCloudApp.Repositories; - -/// -/// Репозиторий для работы с категориями файлов -/// -public interface IFileCategoryRepository : ICrudRepository -{ - /// - /// Получение всех записей по идентификатору типа - /// - /// - /// - /// - Task> GetAllAsync(int idType, CancellationToken cancellationToken); -} \ No newline at end of file diff --git a/AsbCloudApp/Repositories/IManualDirectoryRepository.cs b/AsbCloudApp/Repositories/IManualDirectoryRepository.cs new file mode 100644 index 00000000..0db9d90f --- /dev/null +++ b/AsbCloudApp/Repositories/IManualDirectoryRepository.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using AsbCloudApp.Data.Manuals; +using AsbCloudApp.Services; + +namespace AsbCloudApp.Repositories; + +/// +/// Репозиторий для работы с директориямиы хранящими инструкциями +/// +public interface IManualDirectoryRepository : ICrudRepository +{ + /// + /// Получение дерева директорий + /// + /// + /// + Task> GetTreeAsync(CancellationToken cancellationToken); + + /// + /// Получение одной директории по параметрам + /// + /// + /// + /// + /// + Task GetOrDefaultAsync(string name, int? idParent, CancellationToken cancellationToken); + + /// + /// Проверка директории на существование + /// + /// + /// + /// + Task IsExistsAsync(int id, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/AsbCloudApp/Repositories/IManualFolderRepository.cs b/AsbCloudApp/Repositories/IManualFolderRepository.cs deleted file mode 100644 index d7b86182..00000000 --- a/AsbCloudApp/Repositories/IManualFolderRepository.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.Manuals; -using AsbCloudApp.Services; - -namespace AsbCloudApp.Repositories; - -/// -/// Репозиторий для работы с папки хранящими инструкциями -/// -public interface IManualFolderRepository : ICrudRepository -{ - /// - /// Получение дерева каталога папок - /// - /// - /// - /// - Task> GetTreeAsync(int idCategory, CancellationToken cancellationToken); - - /// - /// Получение одной папки по параметрам - /// - /// - /// - /// - /// - /// - Task GetOrDefaultAsync(string name, int? idParent, int idCategory, CancellationToken cancellationToken); -} \ No newline at end of file diff --git a/AsbCloudApp/Repositories/IManualRepository.cs b/AsbCloudApp/Repositories/IManualRepository.cs deleted file mode 100644 index d5d98c04..00000000 --- a/AsbCloudApp/Repositories/IManualRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.Manuals; -using AsbCloudApp.Services; - -namespace AsbCloudApp.Repositories; - -/// -/// Репозиторий для инструкций -/// -public interface IManualRepository : ICrudRepository -{ - /// - /// Получение инструкций, которые не добавлены в папку - /// - /// - /// - /// - Task> GetManualsWithoutFolderAsync(int idCategory, CancellationToken cancellationToken); -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 6b72eea2..1ff736f5 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -23,8 +23,10 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; +using AsbCloudApp.Data.Manuals; using AsbCloudApp.Services.AutoGeneratedDailyReports; using AsbCloudApp.Services.Notifications; +using AsbCloudDb.Model.Manuals; using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; namespace AsbCloudInfrastructure @@ -222,10 +224,9 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient, CrudRepositoryBase>(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Repository/FileCategoryRepository.cs b/AsbCloudInfrastructure/Repository/FileCategoryRepository.cs deleted file mode 100644 index 703817e4..00000000 --- a/AsbCloudInfrastructure/Repository/FileCategoryRepository.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data; -using AsbCloudApp.Repositories; -using AsbCloudDb.Model; -using Mapster; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Caching.Memory; - -namespace AsbCloudInfrastructure.Repository; - -public class FileCategoryRepository : CrudCacheRepositoryBase, IFileCategoryRepository -{ - public FileCategoryRepository(IAsbCloudDbContext dbContext, IMemoryCache memoryCache) : base(dbContext, memoryCache) - { - } - - public FileCategoryRepository(IAsbCloudDbContext dbContext, IMemoryCache memoryCache, - Func, IQueryable> makeQuery) : base(dbContext, memoryCache, makeQuery) - { - } - - public async Task> GetAllAsync(int idType, CancellationToken cancellationToken) - { - return await dbContext.FileCategories.Where(f => f.IdType == idType) - .Select(f => f.Adapt()) - .ToArrayAsync(cancellationToken); - } -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/FileStorageRepository.cs b/AsbCloudInfrastructure/Repository/FileStorageRepository.cs index ea6268eb..30729144 100644 --- a/AsbCloudInfrastructure/Repository/FileStorageRepository.cs +++ b/AsbCloudInfrastructure/Repository/FileStorageRepository.cs @@ -36,17 +36,15 @@ public class FileStorageRepository : IFileStorageRepository public void DeleteDirectory(string path) { - var fullPath = Path.Combine(RootPath, path); - - if (!Directory.Exists(fullPath)) + if (!Directory.Exists(path)) return; - foreach (var file in Directory.GetFiles(fullPath)) + foreach (var file in Directory.GetFiles(path)) { File.Delete(file); } - Directory.Delete(fullPath, true); + Directory.Delete(path, true); } public void DeleteFile(string fileName) diff --git a/AsbCloudInfrastructure/Repository/ManualDirectoryRepository.cs b/AsbCloudInfrastructure/Repository/ManualDirectoryRepository.cs new file mode 100644 index 00000000..6bae4f28 --- /dev/null +++ b/AsbCloudInfrastructure/Repository/ManualDirectoryRepository.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using AsbCloudApp.Data.Manuals; +using AsbCloudApp.Repositories; +using AsbCloudDb.Model; +using AsbCloudDb.Model.Manuals; +using Mapster; +using Microsoft.EntityFrameworkCore; + +namespace AsbCloudInfrastructure.Repository; + +public class ManualDirectoryRepository : CrudRepositoryBase, IManualDirectoryRepository +{ + public ManualDirectoryRepository(IAsbCloudDbContext context) : base(context) + { + } + + public async Task> GetTreeAsync(CancellationToken cancellationToken) + { + var directories = await dbContext.ManualDirectories + .Include(m => m.Manuals) + .Include(m => m.Parent) + .AsNoTracking() + .ToArrayAsync(cancellationToken); + + return BuildTree(directories).Select(x => x.Adapt()); + } + + public async Task GetOrDefaultAsync(string name, int? idParent, CancellationToken cancellationToken) + { + var entity = await dbContext.ManualDirectories + .AsNoTracking() + .FirstOrDefaultAsync(m => m.Name == name && + m.IdParent == idParent, cancellationToken); + + if (entity is null) + return null; + + return Convert(entity); + } + + public Task IsExistsAsync(int id, CancellationToken cancellationToken) => + dbContext.ManualDirectories.AnyAsync(d => d.Id == id, cancellationToken); + + private IEnumerable BuildTree(IEnumerable directories) + { + var directoryDict = directories.ToDictionary(f => f.Id); + + foreach (var directory in directories) + { + if (directory.IdParent.HasValue && directoryDict.TryGetValue(directory.IdParent.Value, out var parent)) + { + parent.Children ??= new List(); + parent.Children.Add(directory); + } + } + + return directories.Where(f => f.IdParent == null); + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/ManualFolderRepository.cs b/AsbCloudInfrastructure/Repository/ManualFolderRepository.cs deleted file mode 100644 index 456dca13..00000000 --- a/AsbCloudInfrastructure/Repository/ManualFolderRepository.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.Manuals; -using AsbCloudApp.Repositories; -using AsbCloudDb.Model; -using AsbCloudDb.Model.Manuals; -using Mapster; -using Microsoft.EntityFrameworkCore; - -namespace AsbCloudInfrastructure.Repository; - -public class ManualFolderRepository : CrudRepositoryBase, IManualFolderRepository -{ - public ManualFolderRepository(IAsbCloudDbContext context) : base(context) - { - } - - public async Task> GetTreeAsync(int idCategory, - CancellationToken cancellationToken) - { - var folders = await dbContext.ManualFolders - .Where(m => m.IdCategory == idCategory) - .AsNoTracking() - .Include(m => m.Manuals) - .Include(m => m.Parent) - .ToArrayAsync(cancellationToken); - - return BuildTree(folders).Select(x => x.Adapt()); - } - - public async Task GetOrDefaultAsync(string name, int? idParent, int idCategory, - CancellationToken cancellationToken) - { - var entity = await dbContext.ManualFolders - .AsNoTracking() - .FirstOrDefaultAsync(m => m.Name == name && - m.IdCategory == idCategory && - m.IdParent == idParent, cancellationToken); - - if (entity is null) - return null; - - return Convert(entity); - } - - private IEnumerable BuildTree(IEnumerable folders) - { - var folderDict = folders.ToDictionary(f => f.Id); - - foreach (var folder in folders) - { - if (folder.IdParent.HasValue && folderDict.TryGetValue(folder.IdParent.Value, out var parent)) - { - parent.Children ??= new List(); - parent.Children.Add(folder); - } - } - - return folders.Where(f => f.IdParent == null); - } -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/ManualRepository.cs b/AsbCloudInfrastructure/Repository/ManualRepository.cs deleted file mode 100644 index a23d8714..00000000 --- a/AsbCloudInfrastructure/Repository/ManualRepository.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.Manuals; -using AsbCloudApp.Repositories; -using AsbCloudDb.Model; -using AsbCloudDb.Model.Manuals; -using Mapster; -using Microsoft.EntityFrameworkCore; - -namespace AsbCloudInfrastructure.Repository; - -public class ManualRepository : CrudRepositoryBase, IManualRepository -{ - public ManualRepository(IAsbCloudDbContext context) : base(context) - { - } - - public ManualRepository(IAsbCloudDbContext context, Func, IQueryable> makeQuery) - : base(context, makeQuery) - { - } - - public async Task> GetManualsWithoutFolderAsync(int idCategory, CancellationToken cancellationToken) - { - return await dbContext.Manuals.Where(m => m.IdCategory == idCategory && - m.IdFolder == null) - .Select(m => m.Adapt()) - .ToArrayAsync(cancellationToken); - } -} \ No newline at end of file