Skip to content

Commit

Permalink
fix(accessfile):debug structure of return
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirRezaZahedi committed Aug 28, 2024
1 parent 6bf5734 commit 25178c2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion AnalysisData/AnalysisData.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">C:\Users\kimia\AppData\Local\JetBrains\Rider2024.1\resharper-host\temp\Rider\vAny\CoverageData\_AnalysisData.-35481945\Snapshot\snapshot.utdcvr</s:String>




Expand Down
14 changes: 11 additions & 3 deletions AnalysisData/AnalysisData/EAV/Controllers/FileAccessController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AnalysisData.EAV.Repository.Abstraction;
using AnalysisData.EAV.Service;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -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")]
Expand All @@ -30,7 +33,7 @@ public async Task<IActionResult> GetUsersAsync([FromQuery] string username)
}

[HttpPost("AccessFileToUser")]
public async Task<IActionResult> AccessFileToUser([FromBody] List<string> userGuidIdes,int fileId)
public async Task<IActionResult> AccessFileToUser([FromBody] List<string> userGuidIdes,[FromQuery] int fileId)
{
await _filePermissionService.AccessFileToUser(userGuidIdes, fileId);
return Ok(new
Expand All @@ -40,8 +43,13 @@ public async Task<IActionResult> AccessFileToUser([FromBody] List<string> userGu
}

[HttpGet("WhoAccessToThisFile")]
public async Task<IActionResult> WhoAccessToThisFile([FromQuery] string fileId)
public async Task<IActionResult> 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);
}
Expand Down
7 changes: 7 additions & 0 deletions AnalysisData/AnalysisData/EAV/Dto/UserWhoAccessThisFileDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AnalysisData.EAV.Dto;

public class UserWhoAccessThisFileDto
{
public Guid Id { get; set; }
public string UserName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IUserFileRepository
Task<IEnumerable<UserFile>> GetAllAsync();
Task<UserFile?> GetByUserIdAsync(string userId);
Task<IEnumerable<string>> GetUsersIdAccessToInputFile(string fileId);
Task<IEnumerable<UserFile?>> GetByFileIdAsync(string fileId);
Task<IEnumerable<UserFile?>> GetByFileIdAsync(int fileId);
Task DeleteByUserIdAsync(string userId);
Task RevokeUserAccess(List<string> userIds);
Task GrantUserAccess(List<string> userIds, int fileId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public async Task<IEnumerable<UserFile>> GetAllAsync()
return await _context.UserFiles.FirstOrDefaultAsync(x => x.UserId.ToString() == userId);
}

public async Task<IEnumerable<UserFile?>> GetByFileIdAsync(string fileId)
public async Task<IEnumerable<UserFile>> GetByFileIdAsync(int fileId)

Check warning on line 34 in AnalysisData/AnalysisData/EAV/Repository/UserFileRepository.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of reference types in return type of 'Task<IEnumerable<UserFile>> UserFileRepository.GetByFileIdAsync(int fileId)' doesn't match implicitly implemented member 'Task<IEnumerable<UserFile?>> IUserFileRepository.GetByFileIdAsync(int fileId)'.
{
return await _context.Set<UserFile>()
.Where(u => u.FileId.ToString() == fileId)
return await _context.UserFiles
.Include(x =>x.User)
.Where(u => u.FileId == fileId)
.ToListAsync();
}

Expand All @@ -57,7 +58,7 @@ public async Task DeleteByUserIdAsync(string userId)

public async Task GrantUserAccess(List<string> userIds,int fileId)
{
var file = await GetByFileIdAsync(fileId.ToString());
var file = await GetByFileIdAsync(fileId);
if (file is null)
{
throw new FileNotFoundException();
Expand Down
21 changes: 11 additions & 10 deletions AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,26 @@ public async Task<PaginatedFilesDto> GetFilesPagination(int page, int limit)
public async Task<List<UserAccessDto>> 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<IEnumerable<UserFile>> WhoAccessThisFile(string fileId)
public async Task<IEnumerable<UserWhoAccessThisFileDto>> 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<string> inputUserGuidIds,int fileId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface IFilePermissionService
{
Task<PaginatedFilesDto> GetFilesPagination(int page, int limit);
Task<List<UserAccessDto>> GetUserForAccessingFile(string username);
Task<IEnumerable<UserFile>> WhoAccessThisFile(string fileId);
Task<IEnumerable<UserWhoAccessThisFileDto>> WhoAccessThisFile(int fileId);
Task AccessFileToUser(List<string> inputUserIds, int fileId);
}

0 comments on commit 25178c2

Please sign in to comment.