Skip to content

Commit

Permalink
fix(filePermission):return pageIndex (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirRezaZahedi authored Aug 28, 2024
1 parent 5279be8 commit aacc9a0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
8 changes: 8 additions & 0 deletions AnalysisData/AnalysisData/EAV/Dto/PaginatedFilesDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AnalysisData.EAV.Dto;

public class PaginatedFilesDto
{
public List<UploadDataDto> Items { get; set; }
public int TotalCount { get; set; }
public int PageIndex { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ public FileUploadedRepository(ApplicationDbContext context)
_context = context;
}

public async Task<int> GetTotalFilesCountAsync()
{
return await _context.FileUploadedDb.CountAsync();
}

public async Task<IEnumerable<UploadedFile>> GetFileUploadedInDb(int page, int limit)
{
return await _context.FileUploadedDb.Include(x => x.Category).Skip((page) * limit).Take(limit).ToListAsync();
return await _context.FileUploadedDb
.Include(x => x.Category)
.Skip(page * limit)
.Take(limit)
.ToListAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace AnalysisData.EAV.Repository.FileUploadedRepository;
public interface IFileUploadedRepository
{
Task<IEnumerable<UploadedFile>> GetFileUploadedInDb(int page, int limit);
Task<int> GetTotalFilesCountAsync();
}
21 changes: 16 additions & 5 deletions AnalysisData/AnalysisData/EAV/Service/FilePermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ public FilePermissionService(IFileUploadedRepository fileUploadedRepository,IUse
}


public async Task<List<UploadDataDto>> GetFilesPagination(int page, int limit)
public async Task<PaginatedFilesDto> GetFilesPagination(int page, int limit)
{
var totalFilesCount = await _fileUploadedRepository.GetTotalFilesCountAsync();
var files = await _fileUploadedRepository.GetFileUploadedInDb(page, limit);
var paginationFiles = files.Select(x => new UploadDataDto()

var paginatedFiles = files.Select(x => new UploadDataDto()
{
Id = x.Id.ToString() ,FileName = x.FileName , Category = x.Category.Name, UploadDate = x.UploadDate,
});
return paginationFiles.ToList();
Id = x.Id.ToString(),
FileName = x.FileName,
Category = x.Category.Name,
UploadDate = x.UploadDate,
}).ToList();

return new PaginatedFilesDto
{
Items = paginatedFiles,
TotalCount = totalFilesCount,
PageIndex = page
};
}

public async Task<List<UserAccessDto>> GetUserForAccessingFile(string username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AnalysisData.EAV.Service;

public interface IFilePermissionService
{
Task<List<UploadDataDto>> GetFilesPagination(int page, int limit);
Task<PaginatedFilesDto> GetFilesPagination(int page, int limit);
Task<List<UserAccessDto>> GetUserForAccessingFile(string username);
Task<IEnumerable<UserFile>> WhoAccessThisFile(string fileId);
Task AccessFileToUser(List<string> inputUserIds, int fileId);
Expand Down

0 comments on commit aacc9a0

Please sign in to comment.