This commit is contained in:
@@ -3,6 +3,8 @@ package ru.soune.nocopy.service.file;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.dto.file.FileEntityResponse;
|
||||
@@ -104,6 +106,34 @@ public class FileEntityService {
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileResponse getUserFiles(Long userId, Pageable pageable, int version) {
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
List<User> users = user.getCompany() != null ?
|
||||
userRepository.findByCompanyId(user.getCompany().getId()) : List.of(user);
|
||||
List<FileStatus> statusesForSearch = List.of(FileStatus.ACTIVE, FileStatus.BLOCKED, FileStatus.MODERATION);
|
||||
|
||||
Page<FileEntity> files = fileEntityRepository.findFiles(users.stream().map(User::getId).toList(),
|
||||
statusesForSearch, pageable);
|
||||
|
||||
Long totalSize = fileEntityRepository.sumFileSize(
|
||||
users.stream().map(User::getId).toList(),
|
||||
statusesForSearch);
|
||||
|
||||
List<FileEntityResponse> filesToResponse = files.stream()
|
||||
.map(file -> convertToResponse(file, version))
|
||||
.toList();
|
||||
|
||||
return FileResponse.builder()
|
||||
.files(filesToResponse)
|
||||
.totalCount((int) files.getTotalElements())
|
||||
.totalSize(totalSize != null ? totalSize : 0L)
|
||||
.formattedTotalSize(formatFileSize(totalSize != null ? totalSize : 0L))
|
||||
.page(pageable.getPageNumber() + 1)
|
||||
.pageSize(pageable.getPageSize())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileResponse getUserFiles(Long userId, int page, int pageSize, int version) {
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
|
||||
Reference in New Issue
Block a user