From 25178c23c878a9b36ee99ec13381d117c6e666ad Mon Sep 17 00:00:00 2001 From: AmirReza Date: Wed, 28 Aug 2024 22:24:26 +0330 Subject: [PATCH] fix(accessfile):debug structure of return --- .../AnalysisData.sln.DotSettings.user | 2 +- .../EAV/Controllers/FileAccessController.cs | 14 ++++++++++--- .../EAV/Dto/UserWhoAccessThisFileDto.cs | 7 +++++++ .../Abstraction/IUserFileRepository.cs | 2 +- .../EAV/Repository/UserFileRepository.cs | 9 ++++---- .../EAV/Service/FilePermissionService.cs | 21 ++++++++++--------- .../EAV/Service/IFilePermissionService.cs | 2 +- 7 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 AnalysisData/AnalysisData/EAV/Dto/UserWhoAccessThisFileDto.cs diff --git a/AnalysisData/AnalysisData.sln.DotSettings.user b/AnalysisData/AnalysisData.sln.DotSettings.user index 7a59510..6420aaa 100644 --- a/AnalysisData/AnalysisData.sln.DotSettings.user +++ b/AnalysisData/AnalysisData.sln.DotSettings.user @@ -1,5 +1,5 @@  - C:\Users\kimia\AppData\Local\JetBrains\Rider2024.1\resharper-host\temp\Rider\vAny\CoverageData\_AnalysisData.-35481945\Snapshot\snapshot.utdcvr + diff --git a/AnalysisData/AnalysisData/EAV/Controllers/FileAccessController.cs b/AnalysisData/AnalysisData/EAV/Controllers/FileAccessController.cs index 18e2638..ff60e9f 100644 --- a/AnalysisData/AnalysisData/EAV/Controllers/FileAccessController.cs +++ b/AnalysisData/AnalysisData/EAV/Controllers/FileAccessController.cs @@ -1,3 +1,4 @@ +using AnalysisData.EAV.Repository.Abstraction; using AnalysisData.EAV.Service; using Microsoft.AspNetCore.Mvc; @@ -9,10 +10,12 @@ namespace AnalysisData.EAV.Controllers; public class FileAccessController : ControllerBase { private readonly IFilePermissionService _filePermissionService; + private readonly IUserFileRepository _userFileRepository; - public FileAccessController(IFilePermissionService filePermissionService) + public FileAccessController(IFilePermissionService filePermissionService, IUserFileRepository userFileRepository) { _filePermissionService = filePermissionService; + _userFileRepository = userFileRepository; } [HttpGet("GetFileForAccessingFile")] @@ -30,7 +33,7 @@ public async Task GetUsersAsync([FromQuery] string username) } [HttpPost("AccessFileToUser")] - public async Task AccessFileToUser([FromBody] List userGuidIdes,int fileId) + public async Task AccessFileToUser([FromBody] List userGuidIdes,[FromQuery] int fileId) { await _filePermissionService.AccessFileToUser(userGuidIdes, fileId); return Ok(new @@ -40,8 +43,13 @@ public async Task AccessFileToUser([FromBody] List userGu } [HttpGet("WhoAccessToThisFile")] - public async Task WhoAccessToThisFile([FromQuery] string fileId) + public async Task WhoAccessToThisFile([FromQuery] int fileId) { + var file = await _userFileRepository.GetByFileIdAsync(fileId); + if (file is null) + { + throw new FileNotFoundException(); + } var result = await _filePermissionService.WhoAccessThisFile(fileId); return Ok(result); } diff --git a/AnalysisData/AnalysisData/EAV/Dto/UserWhoAccessThisFileDto.cs b/AnalysisData/AnalysisData/EAV/Dto/UserWhoAccessThisFileDto.cs new file mode 100644 index 0000000..a10fd89 --- /dev/null +++ b/AnalysisData/AnalysisData/EAV/Dto/UserWhoAccessThisFileDto.cs @@ -0,0 +1,7 @@ +namespace AnalysisData.EAV.Dto; + +public class UserWhoAccessThisFileDto +{ + public Guid Id { get; set; } + public string UserName { get; set; } +} \ No newline at end of file diff --git a/AnalysisData/AnalysisData/EAV/Repository/Abstraction/IUserFileRepository.cs b/AnalysisData/AnalysisData/EAV/Repository/Abstraction/IUserFileRepository.cs index 4b9ed1f..c4f997a 100644 --- a/AnalysisData/AnalysisData/EAV/Repository/Abstraction/IUserFileRepository.cs +++ b/AnalysisData/AnalysisData/EAV/Repository/Abstraction/IUserFileRepository.cs @@ -8,7 +8,7 @@ public interface IUserFileRepository Task> GetAllAsync(); Task GetByUserIdAsync(string userId); Task> GetUsersIdAccessToInputFile(string fileId); - Task> GetByFileIdAsync(string fileId); + Task> GetByFileIdAsync(int fileId); Task DeleteByUserIdAsync(string userId); Task RevokeUserAccess(List userIds); Task GrantUserAccess(List userIds, int fileId); diff --git a/AnalysisData/AnalysisData/EAV/Repository/UserFileRepository.cs b/AnalysisData/AnalysisData/EAV/Repository/UserFileRepository.cs index 1db6327..32ea0f3 100644 --- a/AnalysisData/AnalysisData/EAV/Repository/UserFileRepository.cs +++ b/AnalysisData/AnalysisData/EAV/Repository/UserFileRepository.cs @@ -31,10 +31,11 @@ public async Task> GetAllAsync() return await _context.UserFiles.FirstOrDefaultAsync(x => x.UserId.ToString() == userId); } - public async Task> GetByFileIdAsync(string fileId) + public async Task> GetByFileIdAsync(int fileId) { - return await _context.Set() - .Where(u => u.FileId.ToString() == fileId) + return await _context.UserFiles + .Include(x =>x.User) + .Where(u => u.FileId == fileId) .ToListAsync(); } @@ -57,7 +58,7 @@ public async Task DeleteByUserIdAsync(string userId) public async Task GrantUserAccess(List userIds,int fileId) { - var file = await GetByFileIdAsync(fileId.ToString()); + var file = await GetByFileIdAsync(fileId); if (file is null) { throw new FileNotFoundException(); diff --git a/AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs b/AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs index 482a1d7..3171568 100644 --- a/AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs +++ b/AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs @@ -46,25 +46,26 @@ public async Task GetFilesPagination(int page, int limit) public async Task> GetUserForAccessingFile(string username) { var users =await _userRepository.GetUsersContainSearchInput(username); + if (users.Count() == 0) + { + throw new UserNotFoundException(); + } var result = users.Select(x => new UserAccessDto() { Id = x.Id.ToString(), UserName = x.Username, FirstName = x.FirstName, LastName = x.LastName }); - if (!result.Any()) - { - throw new UserNotFoundException(); - } return result.ToList(); } - public async Task> WhoAccessThisFile(string fileId) + public async Task> WhoAccessThisFile(int fileId) { - var files =await _userFileRepository.GetByFileIdAsync(fileId); - if (!files.Any()) + var users =await _userFileRepository.GetByFileIdAsync(fileId); + var usersDtos = users.Select(user => new UserWhoAccessThisFileDto() { - throw new UserNotFoundException(); - } - return files.ToList(); + Id = user.User.Id, + UserName = user.User.Username + }); + return usersDtos; } public async Task AccessFileToUser(List inputUserGuidIds,int fileId) diff --git a/AnalysisData/AnalysisData/EAV/Service/IFilePermissionService.cs b/AnalysisData/AnalysisData/EAV/Service/IFilePermissionService.cs index d2dea2c..3bab1e2 100644 --- a/AnalysisData/AnalysisData/EAV/Service/IFilePermissionService.cs +++ b/AnalysisData/AnalysisData/EAV/Service/IFilePermissionService.cs @@ -8,6 +8,6 @@ public interface IFilePermissionService { Task GetFilesPagination(int page, int limit); Task> GetUserForAccessingFile(string username); - Task> WhoAccessThisFile(string fileId); + Task> WhoAccessThisFile(int fileId); Task AccessFileToUser(List inputUserIds, int fileId); } \ No newline at end of file