This commit is contained in:
@@ -86,7 +86,7 @@ public class HandlerConfig {
|
|||||||
StatisticTokenHandler statisticTokenHandler,
|
StatisticTokenHandler statisticTokenHandler,
|
||||||
StatisticIncomeHandler statisticIncomeHandler,
|
StatisticIncomeHandler statisticIncomeHandler,
|
||||||
MonitoringStatisticHandler monitoringStatisticHandler,
|
MonitoringStatisticHandler monitoringStatisticHandler,
|
||||||
FileEntityHandler file,
|
FileInteranlInfoHandler fileInfo,
|
||||||
UserInfoHandler userInfoHandler
|
UserInfoHandler userInfoHandler
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -102,7 +102,7 @@ public class HandlerConfig {
|
|||||||
map.put(30026, statisticIncomeHandler);
|
map.put(30026, statisticIncomeHandler);
|
||||||
map.put(30027, monitoringStatisticHandler);
|
map.put(30027, monitoringStatisticHandler);
|
||||||
map.put(30029, statisticComplaintHandler);
|
map.put(30029, statisticComplaintHandler);
|
||||||
map.put(20005, file);
|
map.put(40001, fileInfo);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@@ -110,14 +110,12 @@ public class HandlerConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public Map<Integer, RequestHandler> internalControlHandler(
|
public Map<Integer, RequestHandler> internalControlHandler(
|
||||||
ControlComplaintHandler controlComplaintHandler,
|
ControlComplaintHandler controlComplaintHandler,
|
||||||
UserInfoHandler userInfoHandler,
|
UserInfoHandler userInfoHandler
|
||||||
FileEntityHandler file
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Map<Integer, RequestHandler> map = new HashMap<>();
|
Map<Integer, RequestHandler> map = new HashMap<>();
|
||||||
map.put(30014, userInfoHandler);
|
map.put(30014, userInfoHandler);
|
||||||
map.put(30030, controlComplaintHandler);
|
map.put(30030, controlComplaintHandler);
|
||||||
map.put(20005, file);
|
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
return handleReviewAppeal(request, fileRequest);
|
return handleReviewAppeal(request, fileRequest);
|
||||||
case "user_appeals":
|
case "user_appeals":
|
||||||
return handleGetUserAppeals(request, fileRequest);
|
return handleGetUserAppeals(request, fileRequest);
|
||||||
case "files_for_moderation":
|
|
||||||
return handleGetFilesForModeration(request, fileRequest);
|
|
||||||
case "change_permission":
|
case "change_permission":
|
||||||
return handleChangePermission(request, fileRequest);
|
return handleChangePermission(request, fileRequest);
|
||||||
default:
|
default:
|
||||||
@@ -295,52 +293,6 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
Map.of("file_status", newStatus, "file_id", fileId));
|
Map.of("file_status", newStatus, "file_id", fileId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
|
||||||
// try {
|
|
||||||
// Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
|
||||||
// int page = fileRequest.getPage() != null ? fileRequest.getPage() : 1;
|
|
||||||
// int pageSize = fileRequest.getPageSize() != null ? fileRequest.getPageSize() : 20;
|
|
||||||
// String fileRequestSortBy = fileRequest.getSortBy();
|
|
||||||
// String sortBy = !fileRequestSortBy.equals("") ? fileRequest.getSortBy(): "createdAt";
|
|
||||||
// sortBy = sortBy.equals("fileName") ? "originalFileName" : sortBy;
|
|
||||||
//
|
|
||||||
// String sortOrder = fileRequest.getSortOrder();
|
|
||||||
// Sort.Direction direction = (sortOrder != null && sortOrder.equalsIgnoreCase("desc"))
|
|
||||||
// ? Sort.Direction.DESC
|
|
||||||
// : Sort.Direction.ASC;
|
|
||||||
// Sort sort = Sort.by(direction, sortBy);
|
|
||||||
//
|
|
||||||
// Pageable pageable = PageRequest.of(page, pageSize, sort);
|
|
||||||
// FileResponse userFiles = fileEntityService.getUserFiles(userId, pageable, request.getVersion());
|
|
||||||
//
|
|
||||||
// FileListResponse response = FileListResponse.builder()
|
|
||||||
// .files(userFiles.getFiles())
|
|
||||||
// .totalCount(userFiles.getTotalCount())
|
|
||||||
// .totalSize(userFiles.getTotalSize())
|
|
||||||
// .formattedTotalSize(fileEntityService.formatFileSize(userFiles.getTotalSize()))
|
|
||||||
// .page(page)
|
|
||||||
// .pageSize(pageSize)
|
|
||||||
// .sortBy(sortBy)
|
|
||||||
// .sortOrder(sortOrder)
|
|
||||||
// .build();
|
|
||||||
//
|
|
||||||
// return new BaseResponse(request.getMsgId(),
|
|
||||||
// MessageCode.SUCCESS.getCode(),
|
|
||||||
// MessageCode.SUCCESS.getDescription(),
|
|
||||||
// response);
|
|
||||||
//
|
|
||||||
// } catch (NotFoundAuthToken e) {
|
|
||||||
// return new BaseResponse(request.getMsgId(),
|
|
||||||
// MessageCode.INVALID_TOKEN.getCode(),
|
|
||||||
// "Authentication required", null);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("Error searching files", e);
|
|
||||||
// return new BaseResponse(request.getMsgId(),
|
|
||||||
// MessageCode.FILE_UPLOAD_ERROR.getCode(),
|
|
||||||
// "Failed to search files: " + e.getMessage(), null);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
try {
|
try {
|
||||||
Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
||||||
@@ -405,73 +357,6 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
|
||||||
* try {
|
|
||||||
* Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
|
||||||
* int page = fileRequest.getPage() != null ? fileRequest.getPage() : 1;
|
|
||||||
* int pageSize = fileRequest.getPageSize() != null ? fileRequest.getPageSize() : 20;
|
|
||||||
*
|
|
||||||
* String sortBy = fileRequest.getSortBy() != null ? fileRequest.getSortBy() : "fileName";
|
|
||||||
* SortOrder sortOrder = SortOrder.fromString(fileRequest.getSortOrder());
|
|
||||||
*
|
|
||||||
* FileResponse allFiles = fileEntityService.getUserFiles(userId, 1, 1000, request.getVersion());
|
|
||||||
*
|
|
||||||
* String searchQuery = fileRequest.getQuery() != null ? fileRequest.getQuery().toLowerCase().trim() : "";
|
|
||||||
* String[] searchTerms = searchQuery.split("\\s+");
|
|
||||||
* String filterType = fileRequest.getType();
|
|
||||||
* String dateFilter = fileRequest.getDateFilter();
|
|
||||||
*
|
|
||||||
* List<FileEntityResponse> filteredFiles = allFiles.getFiles().stream()
|
|
||||||
* .filter(f -> matchesSearch(f, searchTerms, searchQuery, filterType))
|
|
||||||
* .filter(f -> matchesDateFilter(f, dateFilter))
|
|
||||||
* .collect(Collectors.toList());
|
|
||||||
*
|
|
||||||
* Comparator<FileEntityResponse> comparator = getComparator(sortBy, sortOrder);
|
|
||||||
* filteredFiles.sort(comparator);
|
|
||||||
*
|
|
||||||
* int start = (page - 1) * pageSize;
|
|
||||||
* int end = Math.min(start + pageSize, filteredFiles.size());
|
|
||||||
*
|
|
||||||
* if (start >= filteredFiles.size()) {
|
|
||||||
* return createEmptyResponse(request, page, pageSize, sortBy, sortOrder.getValue());
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* List<FileEntityResponse> paginatedFiles = filteredFiles.subList(start, end);
|
|
||||||
* long totalSize = paginatedFiles.stream()
|
|
||||||
* .mapToLong(FileEntityResponse::getFileSize)
|
|
||||||
* .sum();
|
|
||||||
*
|
|
||||||
* FileListResponse response = FileListResponse.builder()
|
|
||||||
* .files(paginatedFiles)
|
|
||||||
* .totalCount(filteredFiles.size())
|
|
||||||
* .totalSize(totalSize)
|
|
||||||
* .formattedTotalSize(fileEntityService.formatFileSize(totalSize))
|
|
||||||
* .page(page)
|
|
||||||
* .pageSize(pageSize)
|
|
||||||
* .sortBy(sortBy)
|
|
||||||
* .sortOrder(sortOrder.getValue())
|
|
||||||
* .build();
|
|
||||||
*
|
|
||||||
* return new BaseResponse(request.getMsgId(),
|
|
||||||
* MessageCode.SUCCESS.getCode(),
|
|
||||||
* MessageCode.SUCCESS.getDescription(),
|
|
||||||
* response);
|
|
||||||
*
|
|
||||||
* } catch (NotFoundAuthToken e) {
|
|
||||||
* return new BaseResponse(request.getMsgId(),
|
|
||||||
* MessageCode.INVALID_TOKEN.getCode(),
|
|
||||||
* "Authentication required", null);
|
|
||||||
* } catch (Exception e) {
|
|
||||||
* log.error("Error searching files", e);
|
|
||||||
* return new BaseResponse(request.getMsgId(),
|
|
||||||
* MessageCode.FILE_UPLOAD_ERROR.getCode(),
|
|
||||||
* "Failed to search files: " + e.getMessage(), null);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
private boolean matchesDateFilter(FileEntityResponse file, String dateFilter) {
|
private boolean matchesDateFilter(FileEntityResponse file, String dateFilter) {
|
||||||
if (dateFilter == null || dateFilter.isEmpty()) {
|
if (dateFilter == null || dateFilter.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1012,72 +897,6 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseResponse handleGetFilesForModeration(BaseRequest request, FileEntityRequest fileRequest) {
|
|
||||||
try {
|
|
||||||
//TODO
|
|
||||||
// authService.useAdminAuthToken(fileRequest.getToken());
|
|
||||||
|
|
||||||
int page = fileRequest.getPage() != null ? fileRequest.getPage() : 1;
|
|
||||||
int pageSize = fileRequest.getPageSize() != null ? fileRequest.getPageSize() : 20;
|
|
||||||
|
|
||||||
Page<FileEntity> files = moderationService.getFilesForModeration(page - 1, pageSize);
|
|
||||||
|
|
||||||
List<Map<String, Object>> filesWithInfo = files.getContent().stream()
|
|
||||||
.map(file -> {
|
|
||||||
FileModerationInfo info = moderationService.getFileModerationInfo(file.getId());
|
|
||||||
|
|
||||||
Map<String, Object> fileMap = new HashMap<>();
|
|
||||||
fileMap.put("fileId", file.getId());
|
|
||||||
fileMap.put("fileName", file.getOriginalFileName());
|
|
||||||
fileMap.put("userId", file.getUserId());
|
|
||||||
fileMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
|
|
||||||
|
|
||||||
Map<String, Object> moderationInfoMap = new HashMap<>();
|
|
||||||
moderationInfoMap.put("hasActiveAppeal", info != null && info.getHasActiveAppeal());
|
|
||||||
|
|
||||||
if (info != null && info.getActiveAppeal() != null) {
|
|
||||||
Map<String, Object> appealInfoMap = new HashMap<>();
|
|
||||||
appealInfoMap.put("appealId", info.getActiveAppeal().getAppealId());
|
|
||||||
appealInfoMap.put("status", info.getActiveAppeal().getStatus());
|
|
||||||
appealInfoMap.put("createdAt", info.getActiveAppeal().getCreatedAt());
|
|
||||||
moderationInfoMap.put("appealInfo", appealInfoMap);
|
|
||||||
} else {
|
|
||||||
moderationInfoMap.put("appealInfo", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
fileMap.put("moderationInfo", moderationInfoMap);
|
|
||||||
|
|
||||||
return fileMap;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
Map<String, Object> response = Map.of(
|
|
||||||
"files", filesWithInfo,
|
|
||||||
"totalCount", files.getTotalElements(),
|
|
||||||
"totalPages", files.getTotalPages(),
|
|
||||||
"currentPage", page,
|
|
||||||
"pageSize", pageSize
|
|
||||||
);
|
|
||||||
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
|
||||||
MessageCode.SUCCESS.getCode(),
|
|
||||||
MessageCode.SUCCESS.getDescription(),
|
|
||||||
response);
|
|
||||||
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
|
||||||
MessageCode.ACCESS_DENIED.getCode(),
|
|
||||||
"Admin access required",
|
|
||||||
null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error getting files for moderation", e);
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
|
||||||
MessageCode.INVALID_FIELD.getCode(),
|
|
||||||
"Failed to get files: " + e.getMessage(),
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BaseResponse handleGetFileModerationInfo(BaseRequest request, FileEntityRequest fileRequest) {
|
private BaseResponse handleGetFileModerationInfo(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package ru.soune.nocopy.handler;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.soune.nocopy.dto.BaseRequest;
|
||||||
|
import ru.soune.nocopy.dto.BaseResponse;
|
||||||
|
import ru.soune.nocopy.dto.MessageCode;
|
||||||
|
import ru.soune.nocopy.dto.file.ActionResponse;
|
||||||
|
import ru.soune.nocopy.dto.file.AppealResponse;
|
||||||
|
import ru.soune.nocopy.dto.file.FileEntityRequest;
|
||||||
|
import ru.soune.nocopy.dto.file.FileModerationInfo;
|
||||||
|
import ru.soune.nocopy.entity.file.FileEntity;
|
||||||
|
import ru.soune.nocopy.service.file.moderation.ModerationService;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FileInteranlInfoHandler implements RequestHandler {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private final ModerationService moderationService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||||
|
try {
|
||||||
|
FileEntityRequest fileRequest = objectMapper.convertValue(
|
||||||
|
request.getMessageBody(), FileEntityRequest.class);
|
||||||
|
|
||||||
|
String action = fileRequest.getAction();
|
||||||
|
switch (action) {
|
||||||
|
case "files_for_moderation":
|
||||||
|
return handleGetFilesForModeration(request, fileRequest);
|
||||||
|
case "all_appeals":
|
||||||
|
return handleGetAllAppeals(request, fileRequest);
|
||||||
|
default:
|
||||||
|
ActionResponse response = ActionResponse.builder()
|
||||||
|
.action(action)
|
||||||
|
.availableActions(Arrays.asList(
|
||||||
|
"files_for_moderation"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.INVALID_ACTION.getCode(),
|
||||||
|
"Invalid action: " + action,
|
||||||
|
response);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in FileEntityHandler", e);
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.FILE_UPLOAD_ERROR.getCode(),
|
||||||
|
"Handler error: " + e.getMessage(),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BaseResponse handleGetFilesForModeration(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
|
try {
|
||||||
|
int page = fileRequest.getPage() != null ? fileRequest.getPage() : 0;
|
||||||
|
int pageSize = fileRequest.getPageSize() != null ? fileRequest.getPageSize() : 20;
|
||||||
|
|
||||||
|
Page<FileEntity> files = moderationService.getFilesForModeration(page, pageSize, fileRequest.getSortBy(),
|
||||||
|
fileRequest.getSortOrder());
|
||||||
|
|
||||||
|
List<Map<String, Object>> filesWithInfo = files.getContent().stream()
|
||||||
|
.map(file -> {
|
||||||
|
FileModerationInfo info = moderationService.getFileModerationInfo(file.getId());
|
||||||
|
|
||||||
|
Map<String, Object> fileMap = new HashMap<>();
|
||||||
|
fileMap.put("fileId", file.getId());
|
||||||
|
fileMap.put("fileName", file.getOriginalFileName());
|
||||||
|
fileMap.put("userId", file.getUserId());
|
||||||
|
fileMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
|
||||||
|
|
||||||
|
Map<String, Object> moderationInfoMap = new HashMap<>();
|
||||||
|
moderationInfoMap.put("hasActiveAppeal", info != null && info.getHasActiveAppeal());
|
||||||
|
|
||||||
|
if (info != null && info.getActiveAppeal() != null) {
|
||||||
|
Map<String, Object> appealInfoMap = new HashMap<>();
|
||||||
|
appealInfoMap.put("appealId", info.getActiveAppeal().getAppealId());
|
||||||
|
appealInfoMap.put("status", info.getActiveAppeal().getStatus());
|
||||||
|
appealInfoMap.put("createdAt", info.getActiveAppeal().getCreatedAt());
|
||||||
|
moderationInfoMap.put("appealInfo", appealInfoMap);
|
||||||
|
} else {
|
||||||
|
moderationInfoMap.put("appealInfo", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileMap.put("moderationInfo", moderationInfoMap);
|
||||||
|
|
||||||
|
return fileMap;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<String, Object> response = Map.of(
|
||||||
|
"files", filesWithInfo,
|
||||||
|
"totalCount", files.getTotalElements(),
|
||||||
|
"totalPages", files.getTotalPages(),
|
||||||
|
"currentPage", page,
|
||||||
|
"pageSize", pageSize
|
||||||
|
);
|
||||||
|
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.SUCCESS.getCode(),
|
||||||
|
MessageCode.SUCCESS.getDescription(),
|
||||||
|
response);
|
||||||
|
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.ACCESS_DENIED.getCode(),
|
||||||
|
"Admin access required",
|
||||||
|
null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error getting files for moderation", e);
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.INVALID_FIELD.getCode(),
|
||||||
|
"Failed to get files: " + e.getMessage(),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private BaseResponse handleGetAllAppeals(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
|
try {
|
||||||
|
int page = fileRequest.getPage() != null ? fileRequest.getPage() : 0;
|
||||||
|
int pageSize = fileRequest.getPageSize() != null ? fileRequest.getPageSize() : 20;
|
||||||
|
|
||||||
|
Page<AppealResponse> appeals = moderationService.getAllAppeals(page, pageSize, fileRequest.getSortBy(),
|
||||||
|
fileRequest.getSortOrder());
|
||||||
|
|
||||||
|
Map<String, Object> response = Map.of(
|
||||||
|
"appeals", appeals.getContent(),
|
||||||
|
"totalCount", appeals.getTotalElements(),
|
||||||
|
"totalPages", appeals.getTotalPages(),
|
||||||
|
"currentPage", page,
|
||||||
|
"pageSize", pageSize);
|
||||||
|
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.SUCCESS.getCode(),
|
||||||
|
MessageCode.SUCCESS.getDescription(),
|
||||||
|
response);
|
||||||
|
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.INVALID_TOKEN.getCode(),
|
||||||
|
"Authentication required",
|
||||||
|
null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error getting user appeals", e);
|
||||||
|
return new BaseResponse(request.getMsgId(),
|
||||||
|
MessageCode.INVALID_FIELD.getCode(),
|
||||||
|
"Failed to get appeals: " + e.getMessage(),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -228,9 +228,22 @@ public class ModerationService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Transactional(readOnly = true)
|
||||||
* Получение апелляций пользователя
|
public Page<FileEntity> getFilesForModeration(int page, int size, String sortDirection, String sortBy) {
|
||||||
*/
|
if (sortDirection == null || sortDirection.isEmpty()) {
|
||||||
|
sortDirection = "desc";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortBy == null || sortBy.isEmpty()) {
|
||||||
|
sortBy = "createdAt";
|
||||||
|
}
|
||||||
|
|
||||||
|
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.fromString(sortDirection), sortBy));
|
||||||
|
|
||||||
|
return fileEntityRepository.findByStatusIn(Arrays.asList(FileStatus.MODERATION, FileStatus.BLOCKED), pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Page<AppealResponse> getUserAppeals(Long userId, int page, int size) {
|
public Page<AppealResponse> getUserAppeals(Long userId, int page, int size) {
|
||||||
Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending());
|
Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending());
|
||||||
@@ -238,6 +251,23 @@ public class ModerationService {
|
|||||||
.map(this::convertToResponse);
|
.map(this::convertToResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Page<AppealResponse> getAllAppeals(int page, int size, String sortDirection, String sortBy) {
|
||||||
|
if (sortDirection == null || sortDirection.isEmpty()) {
|
||||||
|
sortDirection = "desc";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortBy == null || sortBy.isEmpty()) {
|
||||||
|
sortBy = "createdAt";
|
||||||
|
}
|
||||||
|
|
||||||
|
Pageable pageable = PageRequest.of(page, size,
|
||||||
|
Sort.by(Sort.Direction.fromString(sortDirection), sortBy));
|
||||||
|
|
||||||
|
return fileAppealRepository.findAll(pageable)
|
||||||
|
.map(this::convertToResponse);
|
||||||
|
}
|
||||||
|
|
||||||
private AppealResponse convertToResponse(FileAppeal appeal) {
|
private AppealResponse convertToResponse(FileAppeal appeal) {
|
||||||
return AppealResponse.builder()
|
return AppealResponse.builder()
|
||||||
.appealId(appeal.getId())
|
.appealId(appeal.getId())
|
||||||
|
|||||||
Reference in New Issue
Block a user