Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Data Structure): Fixed crashes due to missing record IDs in DB an… #67

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AnalysisData.EAV.Dto;
using AnalysisData.EAV.Repository.Abstraction;
using AnalysisData.EAV.Service;
using AnalysisData.Exception;
using Microsoft.AspNetCore.Mvc;

namespace AnalysisData.EAV.Controllers;
Expand Down Expand Up @@ -33,12 +35,12 @@ public async Task<IActionResult> GetUsersAsync([FromQuery] string username)
}

[HttpPost("AccessFileToUser")]
public async Task<IActionResult> AccessFileToUser([FromBody] List<string> userGuidIdes,[FromQuery] int fileId)
public async Task<IActionResult> AccessFileToUser([FromBody] AccessFileToUserDto request)
{
await _filePermissionService.AccessFileToUser(userGuidIdes, fileId);
return Ok(new
await _filePermissionService.AccessFileToUser(request.UserGuidIds.ToList(), request.FileId);
return Ok(new
{
massage = "success"
message = "success"
});
}

Expand Down
7 changes: 7 additions & 0 deletions AnalysisData/AnalysisData/EAV/Dto/AccessFileToUserDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AnalysisData.EAV.Dto;

public class AccessFileToUserDto
{
public IEnumerable<string> UserGuidIds { get; set; }
public int FileId { get; set; }
}
22 changes: 11 additions & 11 deletions AnalysisData/AnalysisData/EAV/Dto/PaginatedListDto.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace AnalysisData.EAV.Dto;

public class PaginatedListDto
public class PaginatedListDto
{
public List<string> PaginateList { get; }
public int PageIndex { get; }
public int TotalCount { get; }
public string TypeCategory { get; }

public PaginatedListDto(List<string> items, int pageIndex, int totalCount, string typeCategory)
public PaginatedListDto(List<PaginationNodeDto> items, int pageIndex, int totalItems, string categoryName)
{
PaginateList = items;
Items = items;
PageIndex = pageIndex;
TotalCount = totalCount;
TypeCategory = typeCategory;
}
TotalItems = totalItems;
CategoryName = categoryName;
}

public List<PaginationNodeDto> Items { get; set; }
public int PageIndex { get; set; }
public int TotalItems { get; set; }
public string CategoryName { get; set; }
}
1 change: 1 addition & 0 deletions AnalysisData/AnalysisData/EAV/Dto/PaginationNodeDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace AnalysisData.EAV.Dto;

public class PaginationNodeDto
{
public int Id { get; set; }
public string EntityName { get; set; }
}
2 changes: 1 addition & 1 deletion AnalysisData/AnalysisData/EAV/Dto/UploadDataDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace AnalysisData.EAV.Dto;

public class UploadDataDto
{
public string Id { get; set; }
public int Id { get; set; }
public string Category { get; set; }
public string FileName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
return await _context.UserFiles.FirstOrDefaultAsync(x => x.UserId.ToString() == userId);
}

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.UserFiles
.Include(x =>x.User)
Expand All @@ -58,11 +58,6 @@

public async Task GrantUserAccess(List<string> userIds,int fileId)
{
var file = await GetByFileIdAsync(fileId);
if (file is null)
{
throw new FileNotFoundException();
}
foreach (var userId in userIds)
{
var userFile = new UserFile() { UserId = Guid.Parse(userId), FileId = fileId };
Expand All @@ -76,6 +71,4 @@
await DeleteByUserIdAsync(userId);
}
}


}
33 changes: 27 additions & 6 deletions AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public class FilePermissionService : IFilePermissionService
private readonly IFileUploadedRepository _fileUploadedRepository;
private readonly IUserRepository _userRepository;
private readonly IUserFileRepository _userFileRepository;
private readonly IUploadDataRepository _uploadDataRepository;

public FilePermissionService(IFileUploadedRepository fileUploadedRepository,IUserRepository userRepository, IUserFileRepository userFileRepository)
public FilePermissionService(IFileUploadedRepository fileUploadedRepository,IUserRepository userRepository, IUserFileRepository userFileRepository, IUploadDataRepository uploadDataRepository)
{
_fileUploadedRepository = fileUploadedRepository;
_userRepository = userRepository;
_userFileRepository = userFileRepository;
_uploadDataRepository = uploadDataRepository;
}


Expand All @@ -29,7 +31,7 @@ public async Task<PaginatedFilesDto> GetFilesPagination(int page, int limit)

var paginatedFiles = files.Select(x => new UploadDataDto()
{
Id = x.Id.ToString(),
Id = x.Id,
FileName = x.FileName,
Category = x.Category.Name,
UploadDate = x.UploadDate,
Expand Down Expand Up @@ -68,19 +70,38 @@ public async Task<IEnumerable<UserWhoAccessThisFileDto>> WhoAccessThisFile(int f
return usersDtos;
}

public async Task AccessFileToUser(List<string> inputUserGuidIds,int fileId)
public async Task AccessFileToUser(List<string> inputUserGuidIds, int fileId)
{
var validUserGuids = new List<Guid>();

foreach (var userId in inputUserGuidIds)
{
var user = await _userRepository.GetUserById(Guid.Parse(userId));
if (Guid.TryParse(userId, out Guid parsedGuid))
{
validUserGuids.Add(parsedGuid);
}
else
{
throw new GuidNotCorrectFormat();
}
}

foreach (var userGuid in validUserGuids)
{
var user = await _userRepository.GetUserById(userGuid);
if (user is null)
{
throw new UserNotFoundException();
}
}
if (await _uploadDataRepository.GetByIdAsync(fileId) is null)
{
throw new NoFileUploadedException();
}
var currentAccessor = await _userFileRepository.GetUsersIdAccessToInputFile(fileId.ToString());
var newUsers = inputUserGuidIds.Except(currentAccessor).ToList();
var blockAccessToFile = currentAccessor.Except(currentAccessor.Intersect(inputUserGuidIds)).ToList();
var newUsers = validUserGuids.Select(g => g.ToString()).Except(currentAccessor).ToList();
var blockAccessToFile = currentAccessor.Except(currentAccessor.Intersect(validUserGuids.Select(g => g.ToString()))).ToList();

await _userFileRepository.RevokeUserAccess(blockAccessToFile);
await _userFileRepository.GrantUserAccess(newUsers, fileId);
}
Expand Down
6 changes: 3 additions & 3 deletions AnalysisData/AnalysisData/EAV/Service/GraphServiceEav.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public GraphServiceEav(IGraphNodeRepository graphNodeRepository, IGraphEdgeRepos
_graphEdgeRepository = graphEdgeRepository;
}

public async Task<PaginatedListDto> GetNodesPaginationAsync(ClaimsPrincipal claimsPrincipal,int pageIndex, int pageSize, int? categoryId = null)
public async Task<PaginatedListDto> GetNodesPaginationAsync(ClaimsPrincipal claimsPrincipal, int pageIndex, int pageSize, int? categoryId = null)
{
var valueNodes = await GetEntityNodesForPaginationAsync(claimsPrincipal,categoryId);
var valueNodes = await GetEntityNodesForPaginationAsync(claimsPrincipal, categoryId);

string categoryName = null;
if (categoryId.HasValue)
Expand All @@ -43,6 +43,7 @@ public async Task<PaginatedListDto> GetNodesPaginationAsync(ClaimsPrincipal clai

var groupedNodes = valueNodes.Select(g => new PaginationNodeDto
{
Id = g.Id,
EntityName = g.Name,
})
.ToList();
Expand All @@ -51,7 +52,6 @@ public async Task<PaginatedListDto> GetNodesPaginationAsync(ClaimsPrincipal clai
var items = groupedNodes
.Skip(pageIndex * pageSize)
.Take(pageSize)
.Select(x => x.EntityName) // Extract EntityName to match List<string>
.ToList();

return new PaginatedListDto(items, pageIndex, count, categoryName);
Expand Down
11 changes: 10 additions & 1 deletion AnalysisData/AnalysisData/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion AnalysisData/AnalysisData/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@
<value>Node not found Exception ! </value>
</data>
<data name="NoFileUploadedException" xml:space="preserve">
<value>No file uploaded exception !</value>
<value>No file uploaded !</value>
</data>
<data name="EdgeNotFoundException" xml:space="preserve">
<value>Edge not found exception !</value>
</data>
<data name="DuplicateRoleException" xml:space="preserve">
<value>We have this role in db ! </value>
</data>
<data name="GuidNotCorrectFormat" xml:space="preserve">
<value>id not in correct format!</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AnalysisData.Exception;

public class GuidNotCorrectFormat : ServiceException
{
public GuidNotCorrectFormat() : base(Resources.GuidNotCorrectFormat,StatusCodes.Status401Unauthorized)
{
}
}
Loading