Compare commits
82
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7c3bbe07a | ||
|
|
0f71f5d58b | ||
|
|
4ffd830f09 | ||
|
|
4fdd14f81d | ||
|
|
8f2127bed5 | ||
|
|
b71ba527d2 | ||
|
|
e71ce9bc10 | ||
|
|
d8f6a08a2f | ||
|
|
077902f4ab | ||
|
|
5f063354e6 | ||
|
|
48a83591da | ||
|
|
724e72c71a | ||
|
|
f4fc1f26a7 | ||
|
|
6bffd5b385 | ||
|
|
283f0b9e6f | ||
|
|
a9eda37aad | ||
|
|
ecd42ce263 | ||
|
|
9d33c7532a | ||
|
|
0f2908b037 | ||
|
|
37abdeca9a | ||
|
|
e87c14198b | ||
|
|
8bc95efa2b | ||
|
|
051f1ef5d4 | ||
|
|
549d248cb7 | ||
|
|
9a3a8bde05 | ||
|
|
ad4850414a | ||
|
|
3d2c7ecb05 | ||
|
|
51170891ce | ||
|
|
d775802a99 | ||
|
|
dfb1fca8cd | ||
|
|
3f375d3b12 | ||
|
|
a7b9f22939 | ||
|
|
e78f882417 | ||
|
|
2445b70c7a | ||
|
|
41ac8933e9 | ||
|
|
7af909c4f2 | ||
|
|
976d1f751e | ||
|
|
dbef82d896 | ||
|
|
7e1877ffc3 | ||
|
|
8ce07c6b81 | ||
|
|
fa1892585a | ||
|
|
6d6721fb0a | ||
|
|
535be69840 | ||
|
|
fdea57d947 | ||
|
|
0aa7f5c865 | ||
|
|
067b967a17 | ||
|
|
9a8a4a72f4 | ||
|
|
964910ec69 | ||
|
|
547e70ecdd | ||
|
|
78b97b48c9 | ||
|
|
4e0579c952 | ||
|
|
57dcc12cf2 | ||
|
|
a01adfc848 | ||
|
|
8965ffdd1f | ||
|
|
a21eb899b3 | ||
|
|
95ebcf0241 | ||
|
|
a3e6e0091a | ||
|
|
2f38a7c455 | ||
|
|
17aa52d4ac | ||
|
|
8eb0772196 | ||
|
|
c1782cf59b | ||
|
|
46cf252699 | ||
|
|
ebcb68135b | ||
|
|
e68ad3d3d3 | ||
|
|
12e001211b | ||
|
|
40f8effb31 | ||
|
|
69c3d876ae | ||
|
|
610415951d | ||
|
|
9ca116856c | ||
|
|
86db70caf4 | ||
|
|
0b2ef108ca | ||
|
|
0fbe725eb9 | ||
|
|
29cdbb887f | ||
|
|
2bf5e99fbb | ||
|
|
655e8f0844 | ||
|
|
31aa1c0545 | ||
|
|
97d6c8317e | ||
|
|
a42f3e8ed8 | ||
|
|
46c75deacb | ||
|
|
4930a73762 | ||
|
|
726da25ddf | ||
|
|
a9b7b7ca6e |
@@ -9,5 +9,6 @@ interface Referral {
|
||||
val totalIncome: Int
|
||||
val availableIncome: Int
|
||||
val holdBalance: Int
|
||||
val spentBalance: Int
|
||||
val active: Boolean
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class ReferralService(
|
||||
override val totalIncome = 0
|
||||
override val availableIncome = 0
|
||||
override val holdBalance: Int = 0
|
||||
override val spentBalance: Int = 0
|
||||
override val active: Boolean = false
|
||||
}
|
||||
|
||||
@@ -59,7 +60,8 @@ class ReferralService(
|
||||
totalIncome = referral.totalIncome,
|
||||
availableIncome = referral.availableIncome,
|
||||
holdBalance = referral.holdBalance,
|
||||
referralLink = referral.referralLink
|
||||
referralLink = referral.referralLink,
|
||||
spentBalance = referral.spentBalance,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@ data class ReferralStat(
|
||||
val availableIncome: Int,
|
||||
val holdBalance: Int,
|
||||
val referralLink: String,
|
||||
val spentBalance: Int,
|
||||
)
|
||||
@@ -20,6 +20,10 @@ import java.util.Collections;
|
||||
@AllArgsConstructor
|
||||
public class ApplicationConfig {
|
||||
|
||||
// private final FileEntityRepository fileEntityRepository;
|
||||
|
||||
// private final FileUtil fileUtil;
|
||||
|
||||
@Bean
|
||||
PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
@@ -36,6 +40,9 @@ public class ApplicationConfig {
|
||||
AudioFilePathProvider audioFilePathProvider,
|
||||
DocumentLocalSearch documentLocalSearch) {
|
||||
|
||||
// List<FileProtector.FileInfo> initialFiles = loadProcessingFile();
|
||||
|
||||
//TODO инициализация файлов при создании
|
||||
return new com.vrt.NoCopyFileService(
|
||||
Collections.emptyList(),
|
||||
fileProvider,
|
||||
@@ -47,5 +54,13 @@ public class ApplicationConfig {
|
||||
documentLocalSearch
|
||||
);
|
||||
}
|
||||
|
||||
// private List<FileProtector.FileInfo> loadProcessingFile() {
|
||||
// List<FileEntity> byProtectionStatus =
|
||||
// fileEntityRepository.findByProtectionStatus(ProtectionStatus.PROCESSING);
|
||||
//
|
||||
// return byProtectionStatus.stream().map(fileEntity ->
|
||||
// fileUtil.createFileInfo(fileEntity, null)).toList();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,12 @@ public class HandlerConfig {
|
||||
ViolationHandler violationHandler,
|
||||
ViolationStatisticsHandler violationStatisticsHandler,
|
||||
GlobalSearchHandler globalSearchHandler,
|
||||
ViolationNotionHandler violationNotionHandler
|
||||
ViolationNotionHandler violationNotionHandler,
|
||||
ComplaintEntityHandler complaintEntityHandler,
|
||||
UserInfoHandler userInfoHandler,
|
||||
NotificationHandler notificationHandler,
|
||||
UserVerificationHandler userVerificationHandler,
|
||||
LawCaseHandler lawCaseHandler
|
||||
) {
|
||||
Map<Integer, RequestHandler> map = new HashMap<>();
|
||||
map.put(20001, login);
|
||||
@@ -56,6 +61,11 @@ public class HandlerConfig {
|
||||
map.put(30010, violationStatisticsHandler);
|
||||
map.put(30011, globalSearchHandler);
|
||||
map.put(30012, violationNotionHandler);
|
||||
map.put(30013, complaintEntityHandler);
|
||||
map.put(30014, userInfoHandler);
|
||||
map.put(30015, notificationHandler);
|
||||
map.put(30016, userVerificationHandler);
|
||||
map.put(30017, lawCaseHandler);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,9 @@ import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.FileSimilarityService;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.file.ProtectionsLimitService;
|
||||
import ru.soune.nocopy.service.file.*;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
import ru.soune.nocopy.service.file.FileUploadService;
|
||||
import ru.soune.nocopy.service.user.moderation.UserVerificationService;
|
||||
import ru.soune.nocopy.util.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
@@ -77,6 +75,10 @@ public class ApiController {
|
||||
|
||||
private final CheckCounterService checkCounterService;
|
||||
|
||||
private final ZipService zipService;
|
||||
|
||||
private final UserVerificationService userVerificationService;
|
||||
|
||||
@PostMapping("/v{version}/data")
|
||||
public ResponseEntity<?> handlePostRequest(@RequestBody BaseRequest request,
|
||||
@PathVariable("version") int version) {
|
||||
@@ -165,6 +167,44 @@ public class ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/v{version}/private/files/chunk")
|
||||
public ResponseEntity<BaseResponse> uploadChunk(
|
||||
@RequestParam(value = "upload_id", required = false) String uploadId,
|
||||
@RequestParam(value = "chunk_number", required = false) Integer chunkNumber,
|
||||
@RequestParam(value = "chunk", required = false) MultipartFile chunk,
|
||||
@RequestParam(value = "last_file") Boolean last_file,
|
||||
@RequestParam(value = "token") String token) {
|
||||
try {
|
||||
if (chunk == null || chunk.isEmpty()) {
|
||||
return buildErrorResponse(uploadId, chunkNumber, "Chunk file null or empty");
|
||||
}
|
||||
if (uploadId == null || uploadId.isBlank()) {
|
||||
return buildErrorResponse(uploadId, chunkNumber, "Upload Id is required");
|
||||
}
|
||||
if (chunkNumber == null || chunkNumber < 0) {
|
||||
return buildErrorResponse(uploadId, chunkNumber, "Valid chunk number is required");
|
||||
}
|
||||
|
||||
Long userId = authService.useUserAuthToken(token);
|
||||
|
||||
UploadProgressResponse uploadProgressResponse = fileUploadService.uploadPassportChunk(uploadId, chunkNumber,
|
||||
chunk, userId);
|
||||
|
||||
if (last_file) {
|
||||
zipService.createAndSplitZip(userId,
|
||||
fileEntityService.getAllUserFiles(userId, List.of(FileStatus.PRIVATE)));
|
||||
}
|
||||
|
||||
return buildSuccessResponse(uploadId, chunkNumber, chunk,
|
||||
fileEntityService.findFileIdByPath(uploadProgressResponse.getFilePath()));
|
||||
}catch (FileFormatException e){
|
||||
return buildErrorResponse(uploadId, chunkNumber, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("Error uploading chunk", e);
|
||||
return buildErrorResponse(uploadId, chunkNumber, "Failed to upload chunk: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private final NoCopyFileService noCopyFileService;
|
||||
|
||||
@GetMapping("/v{version}/files/{fileId}/similar")
|
||||
@@ -391,6 +431,18 @@ public class ApiController {
|
||||
|
||||
Long userId = authService.useUserAuthToken(tokenHeader);
|
||||
FileEntityResponse entityResponse = fileEntityService.getById(fileId, version);
|
||||
FileStatus status = entityResponse.getStatus();
|
||||
|
||||
if (status.equals(FileStatus.BLOCKED) || status.equals(FileStatus.DELETED) ||
|
||||
status.equals(FileStatus.REMOVED)) {
|
||||
Map<String, Object> errorData = new HashMap<>();
|
||||
errorData.put("fileId", entityResponse.getId());
|
||||
|
||||
return ResponseEntity.ok().body(new BaseResponse(20004,
|
||||
MessageCode.FILE_IS_BLOCKED.getCode(),
|
||||
MessageCode.FILE_IS_BLOCKED.getDescription(),
|
||||
errorData));
|
||||
}
|
||||
|
||||
User fileUser = userRepository.findById(entityResponse.getUserId()).orElseThrow();
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package ru.soune.nocopy.controller;
|
||||
|
||||
import com.vrt.NoCopyFileService;
|
||||
import com.vrt.fileprotection.FileProtector;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -15,6 +17,8 @@ import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.file.FileStorageService;
|
||||
import ru.soune.nocopy.service.file.ImageResizeService;
|
||||
import ru.soune.nocopy.service.file.ZipService;
|
||||
import ru.soune.nocopy.util.FileUtil;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URLEncoder;
|
||||
@@ -28,23 +32,25 @@ import java.nio.file.Paths;
|
||||
@RestController
|
||||
@RequestMapping("/api/files")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private FileStorageService fileStorageService;
|
||||
|
||||
@Autowired
|
||||
private FileEntityRepository fileRepository;
|
||||
|
||||
@Autowired
|
||||
private CheckCounterService checkCounterService;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private ImageResizeService imageResizeService;
|
||||
|
||||
private NoCopyFileService noCopyFileService;
|
||||
|
||||
private FileUtil fileUtil;
|
||||
|
||||
private ZipService zipService;
|
||||
|
||||
@GetMapping("/public/{fileId}")
|
||||
public ResponseEntity<Resource> getPublicFile(@PathVariable String fileId) {
|
||||
try {
|
||||
@@ -145,4 +151,33 @@ public class FileController {
|
||||
.ok()
|
||||
.body(protectedFileCheck);
|
||||
}
|
||||
|
||||
@PostMapping("protect/{fileId}/{convertTo}")
|
||||
public ResponseEntity<FileProtector.FileInfo> convert(@PathVariable String fileId, @PathVariable String convertTo) {
|
||||
FileEntity file = fileRepository.findByFileId(fileId);
|
||||
FileProtector.FileInfo fileInfo = fileUtil.createFileInfo(file, convertTo);
|
||||
|
||||
noCopyFileService.addFile(fileInfo);
|
||||
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.body(fileInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/download/user-passport/archive/{userId}")
|
||||
public ResponseEntity<byte[]> downloadPassportZip(@PathVariable Long userId) {
|
||||
try {
|
||||
byte[] zipBytes = zipService.assembleZipFromSplitFiles(userId);
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=passport_" + userId + ".zip")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(zipBytes.length)
|
||||
.body(zipBytes);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to assemble passport for user {}", userId, e);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,17 @@ import ru.soune.nocopy.entity.payout.PayoutRequest;
|
||||
import ru.soune.nocopy.entity.payout.PayoutType;
|
||||
import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.InsufficientFundsException;
|
||||
import ru.soune.nocopy.exception.InvalidPayoutMethodException;
|
||||
import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.exception.PendingPayoutExistsException;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.service.payout.PayoutMethodService;
|
||||
import ru.soune.nocopy.service.payout.PayoutRequestService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -40,8 +44,8 @@ public class PayoutController {
|
||||
Create payout
|
||||
*/
|
||||
@PostMapping("/create-request")
|
||||
public ResponseEntity<PayoutRequest> createPayoutRequest(@RequestHeader("Authorization") String tokenHeader,
|
||||
@Valid @RequestBody PayoutRequestDTO request) {
|
||||
public ResponseEntity<?> createPayoutRequest(@RequestHeader("Authorization") String tokenHeader,
|
||||
@Valid @RequestBody PayoutRequestDTO request) {
|
||||
String token = tokenHeader.replace("Bearer ", "");
|
||||
|
||||
Optional<AuthToken> tokenOptional = authTokenRepository.findByToken(token);
|
||||
@@ -50,9 +54,12 @@ public class PayoutController {
|
||||
|
||||
User user = authToken.getUser();
|
||||
|
||||
PayoutRequest payoutRequest = payoutRequestService.createPayoutRequest(user.getId(), request);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(payoutRequest);
|
||||
try {
|
||||
PayoutRequest payoutRequest = payoutRequestService.createPayoutRequest(user.getId(), request);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(payoutRequest);
|
||||
} catch (InsufficientFundsException | PendingPayoutExistsException | InvalidPayoutMethodException e) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,9 +2,11 @@ package ru.soune.nocopy.dto;
|
||||
|
||||
public enum MessageCode {
|
||||
SUCCESS(0, "Operation successful"),
|
||||
SUCCESS_MODERATION(0, "File moderated successfully"),
|
||||
REG_EMAIL_EXISTS(1, "Email already registered"),
|
||||
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
|
||||
REFERRAL_LINK_IS_NOT_EXIST(1, "Refferal link is not exist"),
|
||||
FILE_IS_BLOCKED(1, "File is blocked,deleted or removed"),
|
||||
INVALID_FIELD(2, "Invalid field"),
|
||||
MAIL_VERIFIED_NULL(2, "Mail verified null"),
|
||||
INVALID_TOKEN(2, "Token not found or time expired"),
|
||||
@@ -17,6 +19,7 @@ public enum MessageCode {
|
||||
FILE_DELETE(2, "File was deleted"),
|
||||
USER_NOT_HAD_PERMISSION(2, "User not have permission for file"),
|
||||
USER_NOT_VERIFIED(2, "User not verified"),
|
||||
LAW_CASE_NOT_FOUND(4, "Law case not found"),
|
||||
PERMISSION_NOT_FOUND(2, "Permission not found"),
|
||||
USER_NOT_FOUND(2, "User not found"),
|
||||
FILE_DOWNLOAD_ERROR_NOT_CORRECT_FIELD(2, "Not correct field"),
|
||||
@@ -24,8 +27,10 @@ public enum MessageCode {
|
||||
IMAGE_FOUND_ERROR(2, "Image found error"),
|
||||
INVALID_JSON_BODY(2, "Invalid fields in JSON object"),
|
||||
INCOMPLETE_UPLOAD(2, "Not load all chunks"),
|
||||
USER_NOT_HAVE_TOKEN(2, "Not have tokens"),
|
||||
MSG_ID_NOT_FOUND(4, "Message id not found"),
|
||||
FILE_ENTITY_ERROR(2, "File entity error"),
|
||||
NOT_VALID_FIELD(2, "Not valid field"),
|
||||
ACCESS_DENIED(2, "Access denied"),
|
||||
AUTH_EMAIL_NOT_FOUND(4, "Email not found"),
|
||||
AUTH_EMAIL_OR_TOKEN_NOT_FOUND(4, "Email or Token not found "),
|
||||
@@ -51,11 +56,15 @@ public enum MessageCode {
|
||||
MONITORING_TYPE_NOT_FOUND(4, "Monitoring type not found"),
|
||||
ERROR_TARIFF_INFO(2, "Erorr with tariff info"),
|
||||
FILE_FOR_SEARCH_NOT_VALID(2, "File for search unsupported"),
|
||||
ILLEGAL_STATE(2, "File is not in moderation state"),
|
||||
NOT_VALID_FILE_TYPE_OR_COUNT_FILE(2, "Cost for file type not found, count is negative or files count" +
|
||||
"more than max valid"),
|
||||
USER_NOT_ACTIVE(2, "User not active"),
|
||||
NOTION_NOT_FOUND(4, "Notion not found"),
|
||||
MESSAGE_IS_REQUIRED_FOR_NOTION(4, "Message is required for notion");
|
||||
NOT_FOUND(4, "Notion not found"),
|
||||
MESSAGE_IS_REQUIRED_FOR_NOTION(4, "Message is required for notion"),
|
||||
USER_VERIFICATIONS_NOT_FOUND(4, "Verifications not found"),
|
||||
ADMIN_USER_NOT_FOUND(4, "Verifications ,user or admin not found");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class BaseResponse {
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("data")
|
||||
private Object data;
|
||||
|
||||
@JsonProperty("error_code")
|
||||
private String errorCode;
|
||||
|
||||
public static BaseResponse success(Object data) {
|
||||
return BaseResponse.builder()
|
||||
.status("SUCCESS")
|
||||
.data(data)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BaseResponse error(String message, String errorCode) {
|
||||
return BaseResponse.builder()
|
||||
.status("ERROR")
|
||||
.message(message)
|
||||
.errorCode(errorCode)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ComplaintRequest {
|
||||
@JsonProperty("action")
|
||||
private String action;
|
||||
|
||||
@JsonProperty("id")
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("violation_id")
|
||||
private Long violationId;
|
||||
|
||||
@JsonProperty("text")
|
||||
private String complaintText;
|
||||
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("page")
|
||||
private Integer page;
|
||||
|
||||
@JsonProperty("size")
|
||||
private Integer size;
|
||||
|
||||
@JsonProperty("sort_by")
|
||||
private String sortBy;
|
||||
|
||||
@JsonProperty("sort_direction")
|
||||
private String sortDirection;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ComplaintResponse {
|
||||
@JsonProperty("id")
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("complaint_text")
|
||||
private String complaintText;
|
||||
|
||||
@JsonProperty("violation_id")
|
||||
private Long violationId;
|
||||
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private String createdAt;
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
private String updatedAt;
|
||||
|
||||
@JsonProperty("not_moderated")
|
||||
private Boolean notModerated;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class LawCasePageResponse {
|
||||
private List<LawCaseResponse> content;
|
||||
private int pageNumber;
|
||||
private int pageSize;
|
||||
private long totalElements;
|
||||
private int totalPages;
|
||||
private boolean last;
|
||||
private boolean first;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class LawCaseRequest {
|
||||
private Long id;
|
||||
//required
|
||||
private String name;
|
||||
//required
|
||||
private String description;
|
||||
private BigDecimal amount;
|
||||
private String priority = LawCasePriority.MIDDLE.toString();
|
||||
private String type;
|
||||
private String lawyer;
|
||||
private String token;
|
||||
private Integer pageSize = 10;
|
||||
private Integer pageNumber = 0;
|
||||
private String sortBy = "createdAt";
|
||||
private String sortDir = "asc";
|
||||
private String action;
|
||||
private LawCaseType filterType;
|
||||
private String filterLawyer;
|
||||
private LawCasePriority filterPriority;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.complaint.LawCase;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class LawCaseResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private BigDecimal amount;
|
||||
private LawCasePriority priority;
|
||||
private LawCaseType type;
|
||||
private String lawyer;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
private int pageNumber;
|
||||
private int pageSize;
|
||||
private long totalElements;
|
||||
private int totalPages;
|
||||
private List<LawCaseResponse> content;
|
||||
|
||||
public static LawCaseResponse fromEntity(LawCase lawCase) {
|
||||
return LawCaseResponse.builder()
|
||||
.id(lawCase.getId())
|
||||
.name(lawCase.getName())
|
||||
.description(lawCase.getDescription())
|
||||
.amount(lawCase.getAmount())
|
||||
.priority(lawCase.getPriority())
|
||||
.type(lawCase.getType())
|
||||
.lawyer(lawCase.getLawyer())
|
||||
.createdAt(lawCase.getCreatedAt())
|
||||
.updatedAt(lawCase.getUpdatedAt())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ru.soune.nocopy.dto.complaint;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PaginatedResponse<T> {
|
||||
private List<T> content;
|
||||
private long totalElements;
|
||||
private int totalPages;
|
||||
private int pageNumber;
|
||||
private int pageSize;
|
||||
private boolean first;
|
||||
private boolean last;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package ru.soune.nocopy.dto.file;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class AppealInfo {
|
||||
private String appealId;
|
||||
private String status;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.soune.nocopy.dto.file;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class AppealRequest {
|
||||
private String fileId;
|
||||
private String appealReason;
|
||||
private String additionalInfo;
|
||||
private String token;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package ru.soune.nocopy.dto.file;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class AppealResponse {
|
||||
private String appealId;
|
||||
private String fileId;
|
||||
private String appealReason;
|
||||
private String additionalInfo;
|
||||
private String status;
|
||||
private String adminComment;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime resolvedAt;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@@ -44,6 +45,30 @@ public class FileEntityRequest {
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
|
||||
@JsonProperty("file_status")
|
||||
private FileStatus fileStatus;
|
||||
|
||||
@JsonProperty("date_filter")
|
||||
private String dateFilter;
|
||||
|
||||
@JsonProperty("comment")
|
||||
private String comment;
|
||||
|
||||
@JsonProperty("appeal_reason")
|
||||
private String appealReason;
|
||||
|
||||
@JsonProperty("additional_info")
|
||||
private String additionalInfo;
|
||||
|
||||
@JsonProperty("appeal_id")
|
||||
private String appealId;
|
||||
|
||||
@JsonProperty("approve")
|
||||
private Boolean approve;
|
||||
|
||||
@JsonProperty("reason_text")
|
||||
private String reasonText;
|
||||
|
||||
@JsonProperty("search_query")
|
||||
private String searchQuery;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.soune.nocopy.dto.file;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class FileModerationInfo {
|
||||
private String fileId;
|
||||
private String fileName;
|
||||
private String ownerName;
|
||||
private String ownerEmail;
|
||||
private FileStatus currentStatus;
|
||||
private LocalDateTime uploadDate;
|
||||
private Boolean hasActiveAppeal;
|
||||
private AppealInfo activeAppeal;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.soune.nocopy.dto.file;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ModerationActionRequest {
|
||||
private String fileId;
|
||||
private FileStatus newStatus;
|
||||
private String comment;
|
||||
private String token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,4 +20,5 @@ public class SimilarFileDTO {
|
||||
LocalDateTime uploadDate;
|
||||
String url;
|
||||
Boolean owner;
|
||||
String fileStatus;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActivateNotificationRequest {
|
||||
private String authToken;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ActiveNotificationsResponse {
|
||||
private List<NotificationDto> notifications;
|
||||
private long unreadCount;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MarkAsReadRequest {
|
||||
private List<Long> notificationIds;
|
||||
private String authToken;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class MarkAsReadResponse {
|
||||
private boolean success;
|
||||
private int updatedCount;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.notification.NotificationStatus;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class NotificationDto {
|
||||
private Long id;
|
||||
private String message;
|
||||
private NotificationType type;
|
||||
private NotificationStatus status;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.soune.nocopy.entity.notification.NotificationStatus;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class NotificationListRequest {
|
||||
private int page = 0;
|
||||
private int size = 10;
|
||||
private String sortBy = "createdAt";
|
||||
private String sortDirection = "DESC";
|
||||
private List<NotificationType> types;
|
||||
private List<NotificationStatus> statuses;
|
||||
private String authToken;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.soune.nocopy.dto.notification;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class NotificationListResponse {
|
||||
private List<NotificationDto> notifications;
|
||||
private int currentPage;
|
||||
private int totalPages;
|
||||
private long totalElements;
|
||||
}
|
||||
@@ -37,4 +37,10 @@ public class RegRequest {
|
||||
|
||||
@JsonProperty("mail_verified")
|
||||
private String mailVerified;
|
||||
|
||||
@JsonProperty("ip")
|
||||
private String ip;
|
||||
|
||||
@JsonProperty("user_agent")
|
||||
private String userAgent;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,5 @@ public class TariffDTO {
|
||||
private int maxFilesCount;
|
||||
private Long diskSize;
|
||||
private Long maxUsers;
|
||||
private String tariffTerm;
|
||||
}
|
||||
|
||||
@@ -49,4 +49,7 @@ public class TariffRequest {
|
||||
|
||||
@JsonProperty("user_token")
|
||||
private String userToken;
|
||||
|
||||
@JsonProperty("tariff_term")
|
||||
private String tariffTerm;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.soune.nocopy.dto.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserAdditionalInfoBody {
|
||||
|
||||
@JsonProperty("action")
|
||||
private String action;
|
||||
|
||||
@JsonProperty("user_id")
|
||||
private Long userId;
|
||||
|
||||
@JsonProperty("ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@JsonProperty("user_agent")
|
||||
private String userAgent;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.soune.nocopy.dto.user.moderation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserVerificationRequest {
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("user_id")
|
||||
private Long userId;
|
||||
|
||||
@JsonProperty("verified")
|
||||
private Boolean verified;
|
||||
|
||||
@JsonProperty("admin_id")
|
||||
private Long adminId;
|
||||
|
||||
@JsonProperty("action")
|
||||
private String action;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.soune.nocopy.dto.user.moderation;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class UserVerificationResponse {
|
||||
private Long userVerificationId;
|
||||
private Long userId;
|
||||
private LocalDateTime updateTime;
|
||||
private String moderationStatus;
|
||||
}
|
||||
@@ -10,6 +10,9 @@ public class ViolationRequest {
|
||||
@JsonProperty("file_id")
|
||||
private String fileId;
|
||||
|
||||
@JsonProperty("violation_id")
|
||||
private Long violationId;
|
||||
|
||||
@JsonProperty("page")
|
||||
private Integer page = 0;
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package ru.soune.nocopy.entity.complaint;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
import ru.soune.nocopy.entity.violation.Violation;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "complaint")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter @Setter
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class ComplaintEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "status")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private ComplaintStatus status;
|
||||
|
||||
@Column(name = "complaint_text", columnDefinition = "TEXT")
|
||||
private String complaintText;
|
||||
|
||||
@Column(name = "email")
|
||||
private String email;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "violation_id")
|
||||
@ToString.Exclude
|
||||
@JsonIgnore
|
||||
private Violation violation;
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
@LastModifiedDate
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "not_moderated_file")
|
||||
private Boolean not_moderated_file;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.soune.nocopy.entity.complaint;
|
||||
|
||||
public enum ComplaintStatus {
|
||||
CREATED, SHOWED, IN_WORK, COMPLETED, CANCELLED
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package ru.soune.nocopy.entity.complaint;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Getter @Setter
|
||||
@Table(name = "law_case")
|
||||
public class LawCase {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
@ToString.Exclude
|
||||
private User user;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(length = 500, name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name = "amount")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Column(name = "priority")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private LawCasePriority priority;
|
||||
|
||||
@Column(name = "type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private LawCaseType type = LawCaseType.ACTIVE;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "lawyer")
|
||||
private String lawyer;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package ru.soune.nocopy.entity.complaint;
|
||||
|
||||
public enum LawCasePriority {
|
||||
CRITICAL("critical"), HIGH("high"),
|
||||
MIDDLE("middle"), LOW("low");
|
||||
|
||||
private String name;
|
||||
|
||||
private LawCasePriority(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.soune.nocopy.entity.complaint;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum LawCaseType {
|
||||
ACTIVE("active"), CLOSED("closed"),
|
||||
COMPLETED("completed");
|
||||
|
||||
private String name;
|
||||
|
||||
private LawCaseType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package ru.soune.nocopy.entity.file;
|
||||
|
||||
public enum AppealStatus {
|
||||
PENDING,
|
||||
IN_REVIEW,
|
||||
APPROVED,
|
||||
REJECTED,
|
||||
EXPIRED
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package ru.soune.nocopy.entity.file;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "file_appeals")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class FileAppeal {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
|
||||
@Column(name = "file_id", nullable = false)
|
||||
private String fileId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "file_id", insertable = false, updatable = false)
|
||||
@ToString.Exclude
|
||||
private FileEntity file;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "appeal_reason", nullable = false, columnDefinition = "TEXT")
|
||||
private String appealReason;
|
||||
|
||||
@Column(name = "additional_info", columnDefinition = "TEXT")
|
||||
private String additionalInfo;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "status", nullable = false)
|
||||
private AppealStatus status;
|
||||
|
||||
@Column(name = "admin_comment", columnDefinition = "TEXT")
|
||||
private String adminComment;
|
||||
|
||||
@Column(name = "moderator_id")
|
||||
private Long moderatorId;
|
||||
|
||||
@Column(name = "moderation_before_status")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private FileStatus moderationBeforeStatus;
|
||||
|
||||
@Column(name = "resolved_at")
|
||||
private LocalDateTime resolvedAt;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.status == null) {
|
||||
this.status = AppealStatus.PENDING;
|
||||
}
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,9 @@ public class FileEntity {
|
||||
@Column(name = "medium_path")
|
||||
private String mediumPath;
|
||||
|
||||
@Column
|
||||
private String newExtension;
|
||||
|
||||
@OneToOne(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
private ImageHashEntity imageHash;
|
||||
@@ -98,7 +101,7 @@ public class FileEntity {
|
||||
}
|
||||
|
||||
if (this.status == null) {
|
||||
this.status = FileStatus.ACTIVE;
|
||||
this.status = FileStatus.MODERATION;
|
||||
}
|
||||
|
||||
if (this.protectionStatus == null) {
|
||||
|
||||
@@ -7,5 +7,9 @@ public enum FileStatus {
|
||||
VIOLATION,
|
||||
CHECKED,
|
||||
ERROR,
|
||||
TEMP
|
||||
TEMP,
|
||||
REMOVED,
|
||||
MODERATION,
|
||||
PRIVATE,
|
||||
BLOCKED
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package ru.soune.nocopy.entity.file.moderation;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "moderation_logs")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class ModerationLog {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
|
||||
@Column(name = "file_id", nullable = false)
|
||||
private String fileId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "file_id", insertable = false, updatable = false)
|
||||
@ToString.Exclude
|
||||
private FileEntity file;
|
||||
|
||||
@Column(name = "moderator_id", nullable = false)
|
||||
private Long moderatorId;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "old_status", nullable = false)
|
||||
private FileStatus oldStatus;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "new_status", nullable = false)
|
||||
private FileStatus newStatus;
|
||||
|
||||
@Column(name = "reason", columnDefinition = "TEXT")
|
||||
private String reason;
|
||||
|
||||
@Column(name = "comment", columnDefinition = "TEXT")
|
||||
private String comment;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ru.soune.nocopy.entity.file.moderation;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@Entity
|
||||
@Builder
|
||||
@Table(name = "moderation_file")
|
||||
@Getter @Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ModerationPassportFile {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "path", nullable = false)
|
||||
private String path;
|
||||
|
||||
@Column(name = "part")
|
||||
private Integer part;
|
||||
|
||||
private String status;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package ru.soune.nocopy.entity.file.moderation;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PassportModerationFileStatus {
|
||||
|
||||
DOWNLOAD("download"),
|
||||
ON_MODERATION("on_moderation"),
|
||||
MODERATED("moderated");
|
||||
|
||||
private final String name;
|
||||
|
||||
PassportModerationFileStatus(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
package ru.soune.nocopy.entity.monitoring;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum MonitoringType {
|
||||
MONITORING_DAILY, MONITORING_WEEKLY, MONITORING_MONTHLY, NONE
|
||||
MONITORING_DAILY(1), MONITORING_WEEKLY(7), MONITORING_MONTHLY(30), NONE(0);
|
||||
|
||||
private final int days;
|
||||
|
||||
MonitoringType(int days) {
|
||||
this.days = days;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package ru.soune.nocopy.entity.notification;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter @Setter
|
||||
@Builder
|
||||
@Table(name = "notifications", indexes = {
|
||||
@Index(name = "idx_user_status", columnList = "user_id, status"),
|
||||
@Index(name = "idx_user_created", columnList = "user_id, created_at DESC")
|
||||
})
|
||||
public class Notification {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt = LocalDateTime.now();
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "notification_type")
|
||||
private NotificationType notificationType;
|
||||
|
||||
@Column(name = "status")
|
||||
private NotificationStatus status = NotificationStatus.NEW;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
@JsonIgnore
|
||||
private User user;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package ru.soune.nocopy.entity.notification;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum NotificationMessage {
|
||||
FILE_SEARCH("notification-file-search");
|
||||
|
||||
private final String messageKey;
|
||||
|
||||
NotificationMessage(String messageKey) {
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.soune.nocopy.entity.notification;
|
||||
|
||||
public enum NotificationStatus {
|
||||
NEW, READIED
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ru.soune.nocopy.entity.notification;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum NotificationType {
|
||||
SEARCH_RESULT("notification-search-result"),
|
||||
MONITORING_RESULT("notification-monitoring-result"),
|
||||
OPERATION_IMPOSSIBLE("notification-operation-impossible"),
|
||||
START_FAILED_NOW("notification-start-failed-now"),
|
||||
START_FAILED_NEXT("notification-start-failed-next"),
|
||||
PAYOUT_RESULT("notification-payout-result"),
|
||||
PAYMENT_RESULT("notification-payment-result"),
|
||||
REFERRAL_DEPOSIT("notification-referral-deposit"),
|
||||
REFERRAL_REGISTERED("notification-referral-registered"),
|
||||
REFERRAL_ACTIVATED("notification-referral-activated"),
|
||||
COMPLAINT_STATUS_CHANGED("notification-complaint-status"),
|
||||
CASE_STATUS_CHANGED("notification-case-status"),
|
||||
INCOMING_MESSAGE("notification-incoming-message"),
|
||||
TARIFF_EXPIRING("notification-tariff-expiring"),
|
||||
TOKEN_NOT_FOUND("notification-token-not-found"),
|
||||
FILE_MODERATION_EVENT("notification-file-moderation"),
|
||||
FILE_ADDED_TO_SYSTEM("notification-file-added"),
|
||||
SEARCH_OPERATION_FAILED("notification-search-operation-filed");
|
||||
|
||||
private final String messageKey;
|
||||
|
||||
NotificationType(String messageKey) {
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,13 @@ public class Payment {
|
||||
@JoinColumn(name = "tariff_id")
|
||||
@JsonIgnore
|
||||
private Tariff tariff;
|
||||
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,8 @@ public class Tariff {
|
||||
|
||||
@Column(name = "tariffAccountType")
|
||||
private String tariffAccountType;
|
||||
|
||||
@Column(name = "tariff_term")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private TariffTimeTerm tariffTerm;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.soune.nocopy.entity.tarif;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public enum TariffTimeTerm {
|
||||
MONTHLY(30, "MONTHLY"),YEAR(365, "YEAR");
|
||||
|
||||
private final Integer days;
|
||||
private final String name;
|
||||
|
||||
TariffTimeTerm(Integer days, String name) {
|
||||
this.days = days;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static List<String> validTerms() {
|
||||
return List.of(MONTHLY.name(), YEAR.name());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package ru.soune.nocopy.entity.tarif;
|
||||
|
||||
|
||||
public enum TariffType {
|
||||
START, BASIC, PRO, ENTERPRISE, DEMO, BUISNES, CORPORAT, STUDIO, FREE, TOKEN_100, TOKEN_500, TOKEN_1000, TOKEN_5000,
|
||||
START, START_YEAR, BASIC, BASIC_YEAR, PRO, PRO_YEAR, ENTERPRISE, ENTERPRISE_YEAR, DEMO, BUISNES, BUISNES_YEAR,
|
||||
CORPORAT, CORPORAT_YEAR, STUDIO, STUDIO_YEAR, FREE, TOKEN_100, TOKEN_500, TOKEN_1000, TOKEN_5000,
|
||||
MONITORING_DAILY, MONITORING_WEEKLY, MONITORING_MONTHLY;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.soune.nocopy.entity.user;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ModerationStatus {
|
||||
NOT_VERIFIED("not_verified") , VERIFICATION_IN_PROGRESS("verification_in_progress"),
|
||||
VERIFIED("verified"), VERIFICATION_FAILED("verification_failed");
|
||||
|
||||
private final String name;
|
||||
|
||||
private ModerationStatus(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,9 @@ public class User {
|
||||
@ToString.Exclude
|
||||
private UserNotActive userNotActive;
|
||||
|
||||
@Column(name = "verification_status")
|
||||
private ModerationStatus verificationStatus = ModerationStatus.NOT_VERIFIED;
|
||||
|
||||
public TariffInfo getActiveTariffInfo() {
|
||||
if (company != null && company.getTariffInfo() != null) {
|
||||
return company.getTariffInfo();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package ru.soune.nocopy.entity.user;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter @Setter
|
||||
@Builder
|
||||
@Table(name = "user_additional_info")
|
||||
public class UserAdditionalInfo {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, name = "register_date")
|
||||
@CreationTimestamp
|
||||
private Timestamp registrationDate;
|
||||
|
||||
@Column(nullable = false, name = "ip")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(nullable = false, name = "user_agent")
|
||||
private String userAgent;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", unique = true, nullable = false)
|
||||
private User user;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ru.soune.nocopy.entity.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserAdditionalInfoAnswer {
|
||||
|
||||
@JsonProperty("id")
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("user_id")
|
||||
private Long userId;
|
||||
|
||||
@JsonProperty("ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@JsonProperty("user_agent")
|
||||
private String userAgent;
|
||||
|
||||
@JsonProperty("registration_date")
|
||||
private Timestamp registrationDate;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.soune.nocopy.entity.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserAdditionalInfoListAnswer {
|
||||
|
||||
@JsonProperty("items")
|
||||
private List<UserAdditionalInfoAnswer> items;
|
||||
|
||||
@JsonProperty("count")
|
||||
private int count;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package ru.soune.nocopy.entity.user.moderation;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import ru.soune.nocopy.entity.user.ModerationStatus;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user_verification")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserVerification {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id", unique = true, nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", updatable = false, nullable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Column(name = "admin_id")
|
||||
private Long adminId;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "status")
|
||||
private ModerationStatus moderationStatus;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,12 @@ public class ViolationNotion {
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class ComplaintNotFoundException extends RuntimeException {
|
||||
public ComplaintNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class DuplicateComplaintException extends RuntimeException {
|
||||
public DuplicateComplaintException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class InsufficientTokensException extends RuntimeException {
|
||||
public InsufficientTokensException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class InvalidAppealException extends RuntimeException {
|
||||
public InvalidAppealException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class RegistrationAdditionalInfoNullException extends RuntimeException {
|
||||
public RegistrationAdditionalInfoNullException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class SearchFailedException extends RuntimeException {
|
||||
public SearchFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.soune.nocopy.exception;
|
||||
|
||||
public class UserAdditionalInfoNotFound extends RuntimeException {
|
||||
public UserAdditionalInfoNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
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.complaint.ComplaintRequest;
|
||||
import ru.soune.nocopy.dto.complaint.ComplaintResponse;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||
import ru.soune.nocopy.service.complaint.ComplaintEntityService;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ComplaintEntityHandler implements RequestHandler {
|
||||
private final ComplaintEntityService complaintService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
Integer msgId = request.getMsgId();
|
||||
ComplaintRequest complaintRequest = objectMapper.convertValue(request.getMessageBody(), ComplaintRequest.class);
|
||||
String action = complaintRequest.getAction();
|
||||
|
||||
try {
|
||||
switch (action.toLowerCase()) {
|
||||
case "create":
|
||||
return handleCreate(msgId, complaintRequest);
|
||||
case "get":
|
||||
return handleGet(msgId, complaintRequest);
|
||||
case "get_all":
|
||||
return handleGetAll(msgId, complaintRequest);
|
||||
case "get_by_violation":
|
||||
return handleGetByViolation(msgId, complaintRequest);
|
||||
case "update_status":
|
||||
return handleUpdateStatus(msgId, complaintRequest);
|
||||
case "update":
|
||||
return handleUpdate(msgId, complaintRequest);
|
||||
case "delete":
|
||||
return handleDelete(msgId, complaintRequest);
|
||||
default:
|
||||
return errorResponse(msgId, MessageCode.MSG_ID_NOT_FOUND.getCode(), "Unknown action: " + action);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error handling complaint request", e);
|
||||
return errorResponse(msgId, MessageCode.INVALID_JSON_BODY.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleCreate(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getViolationId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(),
|
||||
"violation_id is required");
|
||||
if (req.getComplaintText() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(),
|
||||
"text is required");
|
||||
|
||||
ComplaintResponse response = complaintService.createComplaint(req);
|
||||
|
||||
return successResponse(msgId, "Complaint created successfully", response);
|
||||
}
|
||||
|
||||
private BaseResponse handleGet(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
||||
|
||||
ComplaintResponse response = complaintService.getComplaintById(req.getId());
|
||||
return successResponse(msgId, "Complaint retrieved successfully", response);
|
||||
}
|
||||
|
||||
private BaseResponse handleGetAll(Integer msgId, ComplaintRequest req) {
|
||||
Pageable pageable = PageRequest.of(
|
||||
req.getPage() != null ? req.getPage() : 0,
|
||||
req.getSize() != null ? req.getSize() : 20,
|
||||
Sort.by(Sort.Direction.fromString(req.getSortDirection() != null ? req.getSortDirection() : "desc"),
|
||||
req.getSortBy() != null ? req.getSortBy() : "createdAt")
|
||||
);
|
||||
|
||||
var page = complaintService.getAllComplaints(pageable);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("content", page.getContent());
|
||||
data.put("page", page.getNumber());
|
||||
data.put("size", page.getSize());
|
||||
data.put("totalElements", page.getTotalElements());
|
||||
data.put("totalPages", page.getTotalPages());
|
||||
|
||||
return successResponse(msgId, "Complaints retrieved successfully", data);
|
||||
}
|
||||
|
||||
private BaseResponse handleGetByViolation(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getViolationId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(),
|
||||
"violation_id is required");
|
||||
|
||||
var complaints = complaintService.getComplaintsByViolationId(req.getViolationId());
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("content", complaints);
|
||||
data.put("totalElements", complaints.size());
|
||||
|
||||
return successResponse(msgId, "Complaints retrieved successfully", data);
|
||||
}
|
||||
|
||||
private BaseResponse handleUpdateStatus(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
||||
if (req.getStatus() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "status is required");
|
||||
|
||||
ComplaintStatus status = ComplaintStatus.valueOf(req.getStatus().toUpperCase());
|
||||
ComplaintResponse response = complaintService.updateComplaintStatus(req.getId(), status);
|
||||
return successResponse(msgId, "Status updated successfully", response);
|
||||
}
|
||||
|
||||
private BaseResponse handleUpdate(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
||||
|
||||
ComplaintResponse response = complaintService.updateComplaint(req.getId(), req);
|
||||
|
||||
return successResponse(msgId, "Complaint updated successfully", response);
|
||||
}
|
||||
|
||||
private BaseResponse handleDelete(Integer msgId, ComplaintRequest req) {
|
||||
if (req.getId() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), "id is required");
|
||||
|
||||
ComplaintResponse response = complaintService.deleteComplaint(req.getId());
|
||||
return successResponse(msgId, "Complaint deleted successfully", response);
|
||||
}
|
||||
|
||||
private BaseResponse successResponse(Integer msgId, String message, Object data) {
|
||||
return new BaseResponse(msgId, MessageCode.SUCCESS.getCode(), message, data);
|
||||
}
|
||||
|
||||
private BaseResponse errorResponse(Integer msgId, Integer code, String message) {
|
||||
return new BaseResponse(msgId, code, message, new HashMap<>());
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,20 @@ 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.*;
|
||||
import ru.soune.nocopy.dto.file.*;
|
||||
import ru.soune.nocopy.entity.file.FileAppeal;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
import ru.soune.nocopy.exception.FileEntityNotFoundException;
|
||||
import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.entity.file.moderation.ModerationLog;
|
||||
import ru.soune.nocopy.exception.*;
|
||||
import ru.soune.nocopy.repository.FileAppealRepository;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.ModerationLogRepository;
|
||||
import ru.soune.nocopy.service.file.moderation.ModerationService;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
import ru.soune.nocopy.service.file.FileStatsService;
|
||||
@@ -35,6 +40,12 @@ public class FileEntityHandler implements RequestHandler {
|
||||
|
||||
private final FileEntityRepository fileEntityRepository;
|
||||
|
||||
private final ModerationService moderationService;
|
||||
|
||||
private final FileAppealRepository fileAppealRepository;
|
||||
|
||||
private final ModerationLogRepository moderationLogRepository;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) {
|
||||
try {
|
||||
@@ -60,6 +71,18 @@ public class FileEntityHandler implements RequestHandler {
|
||||
return handleProtectFile(request, fileRequest);
|
||||
case "delete_file":
|
||||
return handleDeleteFile(request, fileRequest);
|
||||
case "change_file_status":
|
||||
return handleChangeStatus(request, fileRequest);
|
||||
case "moderate_file":
|
||||
return handleModerateFile(request, fileRequest);
|
||||
case "submit_appeal":
|
||||
return handleSubmitAppeal(request, fileRequest);
|
||||
case "review_appeal":
|
||||
return handleReviewAppeal(request, fileRequest);
|
||||
case "user_appeals":
|
||||
return handleGetUserAppeals(request, fileRequest);
|
||||
case "files_for_moderation":
|
||||
return handleGetFilesForModeration(request, fileRequest);
|
||||
default:
|
||||
ActionResponse response = ActionResponse.builder()
|
||||
.action(action)
|
||||
@@ -183,6 +206,25 @@ public class FileEntityHandler implements RequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleChangeStatus(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
FileStatus newStatus = fileRequest.getFileStatus();
|
||||
String fileId = fileRequest.getFileId();
|
||||
|
||||
try {
|
||||
fileEntityService.changeFileStatus(newStatus ,fileRequest.getFileId());
|
||||
} catch (FileEntityNotFoundException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||
FileEntityResponse.builder().id(fileId).build());
|
||||
}
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
Map.of("file_status", newStatus, "file_id", fileId));
|
||||
}
|
||||
|
||||
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
try {
|
||||
Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
||||
@@ -568,6 +610,326 @@ public class FileEntityHandler implements RequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleModerateFile(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
try {
|
||||
//TODO добавить проверку на админа
|
||||
// Long moderatorId = authService.useAdminAuthToken(fileRequest.getToken());
|
||||
|
||||
ModerationActionRequest moderationRequest = ModerationActionRequest.builder()
|
||||
.fileId(fileRequest.getFileId())
|
||||
.newStatus(fileRequest.getFileStatus())
|
||||
.comment(fileRequest.getComment())
|
||||
.build();
|
||||
|
||||
//TODO set moderator ID
|
||||
moderationService.moderateFile(moderationRequest, 0L);
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS_MODERATION.getCode(),
|
||||
MessageCode.SUCCESS_MODERATION.getDescription(),
|
||||
FileEntityResponse.builder().id(fileRequest.getFileId()).build());
|
||||
|
||||
} catch (SecurityException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.ACCESS_DENIED.getCode(),
|
||||
MessageCode.ACCESS_DENIED.getDescription(),
|
||||
FileEntityResponse.builder().id(fileRequest.getFileId()).build());
|
||||
} catch (FileEntityNotFoundException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||
FileEntityResponse.builder()
|
||||
.id(fileRequest.getFileId()).build());
|
||||
} catch (IllegalStateException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.ILLEGAL_STATE.getCode(),
|
||||
MessageCode.ILLEGAL_STATE.getDescription(),
|
||||
FileEntityResponse.builder()
|
||||
.status(fileRequest.getFileStatus()).build());
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleSubmitAppeal(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
try {
|
||||
Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
||||
|
||||
AppealRequest appealRequest = AppealRequest.builder()
|
||||
.fileId(fileRequest.getFileId())
|
||||
.appealReason(fileRequest.getAppealReason())
|
||||
.additionalInfo(fileRequest.getAdditionalInfo())
|
||||
.build();
|
||||
|
||||
AppealResponse response = moderationService.submitAppeal(appealRequest, userId);
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
"Appeal submitted successfully",
|
||||
response);
|
||||
} catch (InvalidAppealException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"Failed to submit appeal: " + e.getMessage(),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleReviewAppeal(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
try {
|
||||
// TODO
|
||||
// Long moderatorId = authService.useAdminAuthToken(fileRequest.getToken());
|
||||
|
||||
String appealId = fileRequest.getAppealId();
|
||||
Boolean approve = fileRequest.getApprove();
|
||||
String comment = fileRequest.getComment();
|
||||
|
||||
if (appealId == null || approve == null) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"appealId and approve are required",
|
||||
null);
|
||||
}
|
||||
//TODO
|
||||
moderationService.reviewAppeal(appealId, approve, comment, 0L);
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
"Appeal reviewed successfully",
|
||||
Map.of(
|
||||
"appealId", appealId,
|
||||
"approved", approve,
|
||||
"comment", comment
|
||||
));
|
||||
|
||||
} catch (SecurityException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.ACCESS_DENIED.getCode(),
|
||||
"Admin access required",
|
||||
null);
|
||||
} catch (IllegalStateException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
log.error("Error reviewing appeal", e);
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"Failed to review appeal: " + e.getMessage(),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleGetUserAppeals(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;
|
||||
|
||||
Page<AppealResponse> appeals = moderationService.getUserAppeals(userId, page - 1, pageSize);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
// TODO
|
||||
// authService.useAdminAuthToken(fileRequest.getToken());
|
||||
|
||||
String fileId = fileRequest.getFileId();
|
||||
if (fileId == null) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"fileId is required",
|
||||
null);
|
||||
}
|
||||
|
||||
FileModerationInfo moderationInfo = moderationService.getFileModerationInfo(fileId);
|
||||
|
||||
FileEntity file = fileEntityRepository.findById(fileId)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException(fileId));
|
||||
|
||||
Map<String, Object> fileInfoMap = new HashMap<>();
|
||||
fileInfoMap.put("id", file.getId());
|
||||
fileInfoMap.put("fileName", file.getOriginalFileName());
|
||||
fileInfoMap.put("storedFileName", file.getStoredFileName());
|
||||
fileInfoMap.put("fileSize", file.getFileSize());
|
||||
fileInfoMap.put("formattedSize", fileEntityService.formatFileSize(file.getFileSize()));
|
||||
fileInfoMap.put("mimeType", file.getMimeType());
|
||||
fileInfoMap.put("fileExtension", file.getFileExtension());
|
||||
fileInfoMap.put("checksum", file.getChecksum());
|
||||
fileInfoMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
|
||||
fileInfoMap.put("createdAt", file.getCreatedAt());
|
||||
fileInfoMap.put("updatedAt", file.getUpdatedAt());
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("fileInfo", fileInfoMap);
|
||||
response.put("moderationInfo", moderationInfo != null ? moderationInfo : new HashMap<>());
|
||||
response.put("moderationHistory", getModerationHistory(fileId));
|
||||
response.put("appeals", getFileAppeals(fileId));
|
||||
|
||||
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 (FileEntityNotFoundException e) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting file moderation info", e);
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"Failed to get file info: " + e.getMessage(),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getModerationHistory(String fileId) {
|
||||
List<ModerationLog> logs = moderationLogRepository.findByFileIdOrderByCreatedAtDesc(fileId);
|
||||
if (logs == null || logs.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return logs.stream()
|
||||
.map(log -> {
|
||||
Map<String, Object> logMap = new HashMap<>();
|
||||
logMap.put("id", log.getId());
|
||||
logMap.put("moderatorId", log.getModeratorId());
|
||||
logMap.put("oldStatus", log.getOldStatus() != null ? log.getOldStatus().name() : null);
|
||||
logMap.put("newStatus", log.getNewStatus() != null ? log.getNewStatus().name() : null);
|
||||
logMap.put("reason", log.getReason());
|
||||
logMap.put("comment", log.getComment());
|
||||
logMap.put("createdAt", log.getCreatedAt());
|
||||
return logMap;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getFileAppeals(String fileId) {
|
||||
List<FileAppeal> appeals = fileAppealRepository.findByFileId(fileId);
|
||||
if (appeals == null || appeals.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return appeals.stream()
|
||||
.map(appeal -> {
|
||||
Map<String, Object> appealMap = new HashMap<>();
|
||||
appealMap.put("id", appeal.getId());
|
||||
appealMap.put("userId", appeal.getUserId());
|
||||
appealMap.put("appealReason", appeal.getAppealReason());
|
||||
appealMap.put("additionalInfo", appeal.getAdditionalInfo());
|
||||
appealMap.put("status", appeal.getStatus() != null ? appeal.getStatus().name() : null);
|
||||
appealMap.put("adminComment", appeal.getAdminComment());
|
||||
appealMap.put("moderatorId", appeal.getModeratorId());
|
||||
appealMap.put("createdAt", appeal.getCreatedAt());
|
||||
appealMap.put("resolvedAt", appeal.getResolvedAt());
|
||||
return appealMap;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String formatFileSize(long size) {
|
||||
if (size < 1024) return size + " B";
|
||||
int exp = (int) (Math.log(size) / Math.log(1024));
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.mail.MessagingException;
|
||||
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.complaint.LawCaseRequest;
|
||||
import ru.soune.nocopy.dto.complaint.LawCaseResponse;
|
||||
import ru.soune.nocopy.dto.complaint.PaginatedResponse;
|
||||
import ru.soune.nocopy.entity.complaint.LawCase;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.NotValidFieldException;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.exception.UserNotFoundException;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.complaint.LawCaseService;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.tariff.TariffConstants;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class LawCaseHandler implements RequestHandler {
|
||||
|
||||
private final LawCaseService lawCaseService;
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
private final TariffInfoService tariffInfoService;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
|
||||
LawCaseRequest lawCaseRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
LawCaseRequest.class);
|
||||
Long userId = authService.useUserAuthToken(lawCaseRequest.getToken());
|
||||
String action = lawCaseRequest.getAction();
|
||||
|
||||
return switch (action) {
|
||||
case "get_all" -> getAllUserLawCases(userId, lawCaseRequest, request);
|
||||
case "get_byId" -> getLawCaseById(lawCaseRequest.getId(), request);
|
||||
case "create" -> createLawCase(userId, lawCaseRequest, request);
|
||||
case "update_priority" -> updatePriority(lawCaseRequest, request);
|
||||
case "update_type" -> updateType(lawCaseRequest, request);
|
||||
case "update_amount" -> updateAmount(lawCaseRequest, request);
|
||||
case "delete" -> deleteLawCase(lawCaseRequest.getId(), request);
|
||||
default -> new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.INVALID_ACTION.getCode(),
|
||||
MessageCode.INVALID_ACTION.getDescription(),
|
||||
Map.of("actions", "get_all, get_byId, create, update_priority, update_type, " +
|
||||
"update_amount, delete")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private BaseResponse getAllUserLawCases(Long userId, LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
Page<LawCase> lawCases = lawCaseService.getAllUserLawCases(
|
||||
userId,
|
||||
lawCaseRequest.getPageSize(),
|
||||
lawCaseRequest.getPageNumber(),
|
||||
lawCaseRequest.getFilterType(),
|
||||
lawCaseRequest.getFilterLawyer(),
|
||||
lawCaseRequest.getFilterPriority(),
|
||||
lawCaseRequest.getSortBy(),
|
||||
lawCaseRequest.getSortDir());
|
||||
|
||||
List<LawCaseResponse> responses = lawCases.getContent().stream()
|
||||
.map(LawCaseResponse::fromEntity)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PaginatedResponse<LawCaseResponse> paginatedResponse = new PaginatedResponse<>(
|
||||
responses,
|
||||
lawCases.getTotalElements(),
|
||||
lawCases.getTotalPages(),
|
||||
lawCases.getNumber(),
|
||||
lawCases.getSize(),
|
||||
lawCases.isFirst(),
|
||||
lawCases.isLast()
|
||||
);
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), paginatedResponse);
|
||||
}
|
||||
|
||||
private BaseResponse getLawCaseById(Long id, BaseRequest request) {
|
||||
LawCase lawCase = lawCaseService.getById(id);
|
||||
|
||||
if (lawCase == null) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_NOT_FOUND.getCode(),
|
||||
MessageCode.LAW_CASE_NOT_FOUND.getDescription(), Map.of("id", id));
|
||||
}
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), LawCaseResponse.fromEntity(lawCase));
|
||||
}
|
||||
|
||||
private BaseResponse createLawCase(Long userId, LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
try {
|
||||
tariffInfoService.writeOffTokens(userId, TariffConstants.LEGAL_COST);
|
||||
} catch (TariffNotFoundException e) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.USER_NOT_HAVE_TOKEN.getCode(),
|
||||
MessageCode.USER_NOT_HAVE_TOKEN.getDescription(),
|
||||
Map.of("error", "Tariff not found", "message", e.getMessage()));
|
||||
} catch (MessagingException | IOException e) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.INVALID_FIELD.getCode(),
|
||||
MessageCode.INVALID_FIELD.getDescription(), Map.of("id", lawCaseRequest.getId()));
|
||||
}
|
||||
|
||||
validateRequiredParameters(lawCaseRequest, request);
|
||||
|
||||
User user = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("User not found"));
|
||||
|
||||
LawCase lawCase = lawCaseService.addLawCase(
|
||||
lawCaseRequest.getAmount(),
|
||||
lawCaseRequest.getDescription(),
|
||||
lawCaseRequest.getName(),
|
||||
LawCasePriority.valueOf(lawCaseRequest.getPriority()));
|
||||
lawCase.setUser(user);
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), LawCaseResponse.fromEntity(lawCase));
|
||||
}
|
||||
|
||||
private BaseResponse updatePriority(LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
LawCase lawCase = lawCaseService.changePriority(
|
||||
lawCaseRequest.getId(),
|
||||
LawCasePriority.valueOf(lawCaseRequest.getPriority()));
|
||||
|
||||
if (lawCase == null) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_NOT_FOUND.getCode(),
|
||||
MessageCode.LAW_CASE_NOT_FOUND.getDescription(), Map.of("id", lawCaseRequest.getId()));
|
||||
}
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), LawCaseResponse.fromEntity(lawCase));
|
||||
}
|
||||
|
||||
private BaseResponse updateType(LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
LawCase lawCase = lawCaseService.changeStatus(
|
||||
lawCaseRequest.getId(),
|
||||
LawCaseType.valueOf(lawCaseRequest.getType()));
|
||||
|
||||
if (lawCase == null) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_NOT_FOUND.getCode(),
|
||||
MessageCode.LAW_CASE_NOT_FOUND.getDescription(), Map.of("id", lawCaseRequest.getId()));
|
||||
}
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), LawCaseResponse.fromEntity(lawCase));
|
||||
}
|
||||
|
||||
private BaseResponse updateAmount(LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
LawCase lawCase = lawCaseService.changeDamage(
|
||||
lawCaseRequest.getId(),
|
||||
lawCaseRequest.getAmount());
|
||||
|
||||
if (lawCase == null) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_NOT_FOUND.getCode(),
|
||||
MessageCode.LAW_CASE_NOT_FOUND.getDescription(), Map.of("id", lawCaseRequest.getId()));
|
||||
}
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), LawCaseResponse.fromEntity(lawCase));
|
||||
}
|
||||
|
||||
private BaseResponse deleteLawCase(Long id, BaseRequest request) {
|
||||
lawCaseService.deleteById(id);
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), Map.of("id", id));
|
||||
}
|
||||
|
||||
private void validateRequiredParameters(LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
if (lawCaseRequest.getName() == null) throw new NotValidFieldException("Name is required",
|
||||
new BaseResponse(request.getMsgId(), MessageCode.NOT_VALID_FIELD.getCode(),
|
||||
MessageCode.NOTION_NOT_FOUND.getDescription(), Map.of("fields", "name")));
|
||||
|
||||
if (lawCaseRequest.getDescription() == null) throw new NotValidFieldException("Description is required",
|
||||
new BaseResponse(request.getMsgId(), MessageCode.NOT_VALID_FIELD.getCode(),
|
||||
MessageCode.NOTION_NOT_FOUND.getDescription(), Map.of("fields", "description")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
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.service.notification.NotificationService;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import ru.soune.nocopy.dto.notification.*;
|
||||
import ru.soune.nocopy.entity.notification.Notification;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationHandler implements RequestHandler {
|
||||
|
||||
private final NotificationService notificationService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
Map<String, Object> bodyMap = objectMapper.convertValue(request.getMessageBody(),
|
||||
TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class));
|
||||
|
||||
String action = (String) bodyMap.get("action");
|
||||
|
||||
if (action == null) {
|
||||
ActionResponse response = ActionResponse.builder()
|
||||
.action(action)
|
||||
.availableActions(Arrays.asList("list", "active", "markRead"))
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_FIELD.getCode(),
|
||||
"Action is required",
|
||||
response);
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "list": {
|
||||
NotificationListRequest listRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
NotificationListRequest.class);
|
||||
User user = authService.getUser(listRequest.getAuthToken());
|
||||
|
||||
Page<Notification> page = notificationService.getAllNotifications(
|
||||
user,
|
||||
listRequest.getPage(),
|
||||
listRequest.getSize(),
|
||||
listRequest.getSortBy(),
|
||||
listRequest.getSortDirection(),
|
||||
listRequest.getTypes(),
|
||||
listRequest.getStatuses());
|
||||
|
||||
List<NotificationDto> dtos = page.getContent().stream()
|
||||
.map(this::toDto)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
NotificationListResponse response = NotificationListResponse.builder()
|
||||
.notifications(dtos)
|
||||
.currentPage(page.getNumber())
|
||||
.totalPages(page.getTotalPages())
|
||||
.totalElements(page.getTotalElements())
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
response);
|
||||
}
|
||||
|
||||
case "active": {
|
||||
ActivateNotificationRequest activateRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
ActivateNotificationRequest.class);
|
||||
User user = authService.getUser(activateRequest.getAuthToken());
|
||||
|
||||
List<Notification> recent = notificationService.getActiveNotifications(user);
|
||||
|
||||
long unreadCount = notificationService.getUnreadCount(user);
|
||||
|
||||
ActiveNotificationsResponse response = ActiveNotificationsResponse.builder()
|
||||
.notifications(recent.stream().map(this::toDto).collect(Collectors.toList()))
|
||||
.unreadCount(unreadCount)
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
response);
|
||||
}
|
||||
|
||||
case "markRead": {
|
||||
MarkAsReadRequest markRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
MarkAsReadRequest.class);
|
||||
User user = authService.getUser(markRequest.getAuthToken());
|
||||
|
||||
int updated = notificationService.markAsRead(user, markRequest.getNotificationIds());
|
||||
|
||||
MarkAsReadResponse response = MarkAsReadResponse.builder()
|
||||
.success(true)
|
||||
.updatedCount(updated)
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
response);
|
||||
}
|
||||
|
||||
case "delete": {
|
||||
MarkAsReadRequest markRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
MarkAsReadRequest.class);
|
||||
|
||||
int delete = notificationService.delete(markRequest.getNotificationIds());
|
||||
|
||||
MarkAsReadResponse response = MarkAsReadResponse.builder()
|
||||
.success(true)
|
||||
.updatedCount(delete)
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
response);
|
||||
}
|
||||
|
||||
default:
|
||||
ActionResponse response = ActionResponse.builder()
|
||||
.action(action)
|
||||
.availableActions(Arrays.asList("list", "active", "markRead", "delete"))
|
||||
.build();
|
||||
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_ACTION.getCode(),
|
||||
"Invalid action: " + action,
|
||||
response);
|
||||
}
|
||||
}
|
||||
|
||||
private NotificationDto toDto(Notification notification) {
|
||||
return NotificationDto.builder()
|
||||
.id(notification.getId())
|
||||
.message(notification.getMessage())
|
||||
.type(notification.getNotificationType())
|
||||
.status(notification.getStatus())
|
||||
.createdAt(notification.getCreatedAt())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import ru.soune.nocopy.repository.ReferralJpaRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.mail.EmailService;
|
||||
import ru.soune.nocopy.service.user.AdditionalInfoService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
@@ -43,6 +44,8 @@ public class RegRequestHandler implements RequestHandler {
|
||||
|
||||
private final ReferralJpaRepository referralJpaRepository;
|
||||
|
||||
private final AdditionalInfoService additionalInfoService;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws ValidationException {
|
||||
RegRequest regRequest = objectMapper.convertValue(request.getMessageBody(), RegRequest.class);
|
||||
@@ -124,9 +127,10 @@ public class RegRequestHandler implements RequestHandler {
|
||||
referralService.onRegister(authToken.getUser().getId(), regRequest.getReferralLink());
|
||||
}
|
||||
|
||||
additionalInfoService.additionalInfo(regRequest.getIp(), regRequest.getUserAgent(), authToken.getUser());
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), regAnswer);
|
||||
|
||||
} catch (CompanyAlreadyExist e) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.COMPANY_ALREADY_EXISTS.getCode(),
|
||||
MessageCode.COMPANY_ALREADY_EXISTS.getDescription(), Map.of(
|
||||
|
||||
@@ -10,6 +10,7 @@ import ru.soune.nocopy.dto.MessageCode;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffDTO;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffRequest;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffResponse;
|
||||
import ru.soune.nocopy.entity.tarif.TariffTimeTerm;
|
||||
import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
@@ -64,7 +65,7 @@ public class TariffHandler implements RequestHandler {
|
||||
private BaseResponse handleAddTariff(BaseRequest request, TariffRequest tariffRequest) {
|
||||
tariffService.addTariff(tariffRequest.getName(), tariffRequest.getPrice(), tariffRequest.getType(),
|
||||
tariffRequest.getTokens(), tariffRequest.getDiskSize(), tariffRequest.getMaxUsers(),
|
||||
tariffRequest.getMaxFilesCount());
|
||||
tariffRequest.getMaxFilesCount(), tariffRequest.getTariffTerm());
|
||||
|
||||
TariffResponse tariffResponse = TariffResponse.builder()
|
||||
.tariffName(tariffRequest.getName())
|
||||
@@ -122,7 +123,18 @@ public class TariffHandler implements RequestHandler {
|
||||
private BaseResponse handleGetTariffs(BaseRequest request, TariffRequest tariffRequest) {
|
||||
AuthToken authToken = authTokenRepository.findByToken(tariffRequest.getUserToken()).orElseThrow();
|
||||
User user = authToken.getUser();
|
||||
List<TariffDTO> allTariffs = tariffService.getTariffByAccountType(user);
|
||||
|
||||
if (tariffRequest.getTariffTerm() == null || !TariffTimeTerm.validTerms().contains(
|
||||
tariffRequest.getTariffTerm())) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
"Not valid tariff_term",
|
||||
Map.of("Valid term", TariffTimeTerm.validTerms()));
|
||||
}
|
||||
|
||||
List<TariffDTO> allTariffs = tariffService.getTariffByAccountTypeAndTariffTerm(user,
|
||||
TariffTimeTerm.valueOf(tariffRequest.getTariffTerm().toUpperCase()));
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
|
||||
@@ -12,6 +12,7 @@ import ru.soune.nocopy.dto.tarriff.TariffInfoRequest;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffInfoResponse;
|
||||
import ru.soune.nocopy.entity.tarif.Tariff;
|
||||
import ru.soune.nocopy.entity.tarif.TariffStatus;
|
||||
import ru.soune.nocopy.entity.tarif.TariffTimeTerm;
|
||||
import ru.soune.nocopy.entity.tarif.TariffType;
|
||||
import ru.soune.nocopy.repository.TariffRepository;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
@@ -75,13 +76,14 @@ public class TariffInfoHandler implements RequestHandler {
|
||||
try {
|
||||
Long tariffId = tariffInfoRequest.getTariffId();
|
||||
Tariff tariff= tariffRepository.findById(tariffId).orElseThrow();
|
||||
TariffTimeTerm tariffTerm = tariff.getTariffTerm();
|
||||
LocalDateTime endDateTime = LocalDateTime.now().plusDays(tariffTerm.getDays());
|
||||
|
||||
TariffInfoDTO tariffInfoDTO = new TariffInfoDTO(null,
|
||||
tariffInfoRequest.getStatus() != null ? tariffInfoRequest.getStatus() : TariffStatus.ACTIVE.name(),
|
||||
tariffInfoRequest.getStartTariff() != null ? tariffInfoRequest.getStartTariff() : LocalDateTime.now(),
|
||||
tariffInfoRequest.getEndTariff() != null ? tariffInfoRequest.getEndTariff() : LocalDateTime.now().plusDays(30),
|
||||
tariffInfoRequest.getTariffId(), tariff.getName(), tariff.getTokens(), tariff.getDiskSize(), 0L,
|
||||
0, tariff.getMaxFilesCount());
|
||||
endDateTime, tariffInfoRequest.getTariffId(), tariff.getName(), tariff.getTokens(),
|
||||
tariff.getDiskSize(), 0L, 0, tariff.getMaxFilesCount());
|
||||
|
||||
TariffInfoDTO createdTariffInfo = tariffInfoService.createTariffInfo(tariffInfoDTO);
|
||||
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.user.UserAdditionalInfoBody;
|
||||
|
||||
import ru.soune.nocopy.entity.user.UserAdditionalInfo;
|
||||
import ru.soune.nocopy.entity.user.UserAdditionalInfoAnswer;
|
||||
import ru.soune.nocopy.entity.user.UserAdditionalInfoListAnswer;
|
||||
import ru.soune.nocopy.exception.UserAdditionalInfoNotFound;
|
||||
import ru.soune.nocopy.service.user.AdditionalInfoService;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UserInfoHandler implements RequestHandler {
|
||||
|
||||
private final AdditionalInfoService additionalInfoService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
try {
|
||||
UserAdditionalInfoBody body = objectMapper.convertValue(request.getMessageBody(),
|
||||
UserAdditionalInfoBody.class);
|
||||
|
||||
log.info("Processing UserInfoHandler with action: {}", body.getAction());
|
||||
|
||||
return switch (body.getAction()) {
|
||||
case "getAll" -> getAllAdditionalInfos(request);
|
||||
case "getById" -> getAdditionalInfoById(request, body.getUserId());
|
||||
case "update" -> updateAdditionalInfo(request, body);
|
||||
case "delete" -> deleteAdditionalInfo(request, body.getUserId());
|
||||
default -> new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.INVALID_ACTION.getCode(),
|
||||
"Invalid action: " + body.getAction(),
|
||||
null
|
||||
);
|
||||
};
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Validation error in UserInfoHandler", e);
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.VALIDATION_ERROR.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (UserAdditionalInfoNotFound e) {
|
||||
log.error("User additional info not found", e);
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.NOT_FOUND.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
log.error("Unexpected error in UserInfoHandler", e);
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.INTERNAL_ERROR.getCode(),
|
||||
"Internal server error: " + e.getMessage(),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse getAllAdditionalInfos(BaseRequest request) {
|
||||
log.info("Getting all additional infos");
|
||||
|
||||
List<UserAdditionalInfo> infos = additionalInfoService.getAllAdditionalInfos();
|
||||
|
||||
List<UserAdditionalInfoAnswer> answerItems = infos.stream()
|
||||
.map(this::convertToAnswer)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
UserAdditionalInfoListAnswer listAnswer = UserAdditionalInfoListAnswer.builder()
|
||||
.items(answerItems)
|
||||
.count(answerItems.size())
|
||||
.build();
|
||||
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
listAnswer
|
||||
);
|
||||
}
|
||||
|
||||
private BaseResponse getAdditionalInfoById(BaseRequest request, Long userId) {
|
||||
log.info("Getting additional info for user: {}", userId);
|
||||
|
||||
if (userId == null) {
|
||||
throw new IllegalArgumentException("User ID is required for getById action");
|
||||
}
|
||||
|
||||
UserAdditionalInfo info = additionalInfoService.getAdditionalInfoByUser(userId);
|
||||
|
||||
if (info == null) {
|
||||
throw new UserAdditionalInfoNotFound(
|
||||
String.format("User additional info not found for userId: %d", userId)
|
||||
);
|
||||
}
|
||||
|
||||
UserAdditionalInfoAnswer answer = convertToAnswer(info);
|
||||
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
answer
|
||||
);
|
||||
}
|
||||
|
||||
private BaseResponse updateAdditionalInfo(BaseRequest request, UserAdditionalInfoBody body) {
|
||||
log.info("Updating additional info for user: {}", body.getUserId());
|
||||
|
||||
if (body.getUserId() == null) {
|
||||
throw new IllegalArgumentException("User ID is required for update action");
|
||||
}
|
||||
|
||||
validateIpAddress(body.getIpAddress());
|
||||
validateUserAgent(body.getUserAgent());
|
||||
|
||||
Optional<UserAdditionalInfo> updatedInfo = additionalInfoService.updateAdditionalInfo(
|
||||
body.getUserId(),
|
||||
body.getIpAddress(),
|
||||
body.getUserAgent()
|
||||
);
|
||||
|
||||
if (updatedInfo.isEmpty()) {
|
||||
throw new UserAdditionalInfoNotFound(
|
||||
String.format("User additional info not found for userId: %d", body.getUserId())
|
||||
);
|
||||
}
|
||||
|
||||
UserAdditionalInfoAnswer answer = convertToAnswer(updatedInfo.get());
|
||||
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
answer
|
||||
);
|
||||
}
|
||||
|
||||
private BaseResponse deleteAdditionalInfo(BaseRequest request, Long userId) {
|
||||
log.info("Deleting additional info for user: {}", userId);
|
||||
|
||||
if (userId == null) {
|
||||
throw new IllegalArgumentException("User ID is required for delete action");
|
||||
}
|
||||
|
||||
UserAdditionalInfo existingInfo = additionalInfoService.getAdditionalInfoByUser(userId);
|
||||
|
||||
if (existingInfo == null) {
|
||||
throw new UserAdditionalInfoNotFound(
|
||||
String.format("User additional info not found for userId: %d", userId)
|
||||
);
|
||||
}
|
||||
|
||||
additionalInfoService.deleteAdditionalInfo(userId);
|
||||
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
Map.of("deleted", true, "user_id", userId)
|
||||
);
|
||||
}
|
||||
|
||||
private UserAdditionalInfoAnswer convertToAnswer(UserAdditionalInfo info) {
|
||||
return UserAdditionalInfoAnswer.builder()
|
||||
.id(info.getId())
|
||||
.userId(info.getUser() != null ? info.getUser().getId() : null)
|
||||
.ipAddress(info.getIpAddress())
|
||||
.userAgent(info.getUserAgent())
|
||||
.registrationDate(info.getRegistrationDate())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void validateIpAddress(String ip) {
|
||||
if (ip == null || ip.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("IP address is required for update action");
|
||||
}
|
||||
|
||||
String ipv4Pattern =
|
||||
"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
|
||||
|
||||
if (!ip.trim().matches(ipv4Pattern)) {
|
||||
log.warn("Invalid IP address format: {}", ip);
|
||||
throw new IllegalArgumentException("Invalid IP address format");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUserAgent(String userAgent) {
|
||||
if (userAgent == null || userAgent.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("User agent is required for update action");
|
||||
}
|
||||
|
||||
if (userAgent.length() > 500) {
|
||||
throw new IllegalArgumentException("User agent must not exceed 500 characters");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.user.moderation.UserVerificationRequest;
|
||||
import ru.soune.nocopy.dto.user.moderation.UserVerificationResponse;
|
||||
import ru.soune.nocopy.entity.user.moderation.UserVerification;
|
||||
import ru.soune.nocopy.service.user.moderation.UserVerificationService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class UserVerificationHandler implements RequestHandler {
|
||||
|
||||
private final UserVerificationService userVerificationService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
UserVerificationRequest userVerificationRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
UserVerificationRequest.class);
|
||||
String action = userVerificationRequest.getAction();
|
||||
|
||||
switch (action) {
|
||||
case "get_all_verifications":
|
||||
return handleVerifications(request, userVerificationRequest);
|
||||
case "verified":
|
||||
return handleVerified(request, userVerificationRequest);
|
||||
default:
|
||||
ActionResponse response = ActionResponse.builder()
|
||||
.action(action)
|
||||
.availableActions(Arrays.asList(
|
||||
"get_all_verifications", "verified"))
|
||||
.build();
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.INVALID_ACTION.getCode(),
|
||||
"Invalid action: " + action,
|
||||
response);
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleVerifications(BaseRequest request, UserVerificationRequest userVerificationRequest) throws Exception {
|
||||
List<UserVerification> verifications = userVerificationService.verifications();
|
||||
|
||||
if (verifications.isEmpty()) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.USER_VERIFICATIONS_NOT_FOUND.getCode(),
|
||||
MessageCode.USER_VERIFICATIONS_NOT_FOUND.getDescription(), null);
|
||||
}
|
||||
|
||||
List<UserVerificationResponse> verificationResponses = verifications.stream().map(this::convertDto).toList();
|
||||
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageBody(verificationResponses)
|
||||
.build();
|
||||
}
|
||||
|
||||
private BaseResponse handleVerified(BaseRequest request, UserVerificationRequest userVerificationRequest) throws Exception {
|
||||
UserVerification userVerification = userVerificationService.verifyUser(userVerificationRequest.getUserId(), userVerificationRequest.getMessage(),
|
||||
userVerificationRequest.getAdminId(), userVerificationRequest.getVerified());
|
||||
|
||||
if (userVerification == null) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.ADMIN_USER_NOT_FOUND.getCode(),
|
||||
MessageCode.ADMIN_USER_NOT_FOUND.getDescription(),
|
||||
null);
|
||||
}
|
||||
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageBody(UserVerificationResponse.builder()
|
||||
.userVerificationId(userVerification.getId())
|
||||
.moderationStatus(userVerification.getModerationStatus().toString())
|
||||
.userId(userVerification.getUserId()))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private UserVerificationResponse convertDto(UserVerification userVerification) {
|
||||
return UserVerificationResponse.builder()
|
||||
.userVerificationId(userVerification.getId())
|
||||
.userId(userVerification.getUserId())
|
||||
.moderationStatus(userVerification.getModerationStatus().name())
|
||||
.updateTime(userVerification.getUpdatedAt())
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.violation.ViolationService;
|
||||
import ru.soune.nocopy.service.violation.ViolationStatus;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -66,6 +67,18 @@ public class ViolationHandler implements RequestHandler {
|
||||
endDate = parseDate(violationRequest.getEndDate());
|
||||
}
|
||||
|
||||
if ("updateStatus".equals(violationRequest.getAction())) {
|
||||
String status = violationRequest.getStatus();
|
||||
Long violationId = violationRequest.getViolationId();
|
||||
|
||||
violationService.changeStatus(ViolationStatus.valueOf(status), violationId);
|
||||
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageBody(Map.of("status", status))
|
||||
.build();
|
||||
}
|
||||
|
||||
if ("group".equalsIgnoreCase(violationRequest.getAction())) {
|
||||
Map<String, Long> groupedData = violationService.getGroupedViolations(
|
||||
targetFiles,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.soune.nocopy.handler.validator;
|
||||
|
||||
import org.apache.commons.validator.routines.EmailValidator;
|
||||
import org.apache.commons.validator.routines.InetAddressValidator;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
@@ -28,6 +29,7 @@ public class RegRequestValidator implements Validator {
|
||||
validateEmail(request.getEmail(), errors);
|
||||
validateCompanyName(request.getCompanyName(), errors);
|
||||
validateFullName(request.getFullName(), errors);
|
||||
validateAdditionalInfo(request.getIp(), request.getUserAgent(), errors);
|
||||
}
|
||||
|
||||
private void validateFullName(String fullName, Errors errors) {
|
||||
@@ -73,6 +75,21 @@ public class RegRequestValidator implements Validator {
|
||||
}
|
||||
}
|
||||
|
||||
public void validateAdditionalInfo(String ip, String userAgent, Errors errors) {
|
||||
if (ip == null || ip.trim().isEmpty()) {
|
||||
errors.rejectValue("ip", "ip.required", "IP address is required");
|
||||
} else if (!InetAddressValidator.getInstance().isValid(ip.trim())) {
|
||||
errors.rejectValue("ip", "ip.invalid", "Invalid IP address format");
|
||||
}
|
||||
|
||||
if (userAgent == null || userAgent.trim().isEmpty()) {
|
||||
errors.rejectValue("userAgent", "userAgent.required", "User agent is required");
|
||||
} else if (userAgent.length() > 500) {
|
||||
errors.rejectValue("userAgent", "userAgent.tooLong", "User agent must not exceed " +
|
||||
"500 characters");
|
||||
}
|
||||
}
|
||||
|
||||
public void validateEmail(String email, Errors errors) {
|
||||
if (email == null || email.trim().isEmpty()) {
|
||||
errors.rejectValue("email", "email.is.empty", "Email must not be empty");
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintEntity;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ComplaintEntityRepository extends JpaRepository<ComplaintEntity, String> {
|
||||
Optional<ComplaintEntity> findById(Long id);
|
||||
Page<ComplaintEntity> findAll(Pageable pageable);
|
||||
Page<ComplaintEntity> findByStatus(ComplaintStatus status, Pageable pageable);
|
||||
List<ComplaintEntity> findByViolationId(Long violationId);
|
||||
boolean existsByViolationId(Long violationId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("UPDATE ComplaintEntity c SET c.status = :status WHERE c.id = :id")
|
||||
int updateStatus(Long id, ComplaintStatus status);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.soune.nocopy.entity.file.FileAppeal;
|
||||
import ru.soune.nocopy.entity.file.AppealStatus;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface FileAppealRepository extends JpaRepository<FileAppeal, String> {
|
||||
|
||||
Optional<FileAppeal> findByFileIdAndStatus(String fileId, AppealStatus status);
|
||||
|
||||
List<FileAppeal> findByFileId(String fileId);
|
||||
|
||||
Page<FileAppeal> findByStatus(AppealStatus status, Pageable pageable);
|
||||
|
||||
Page<FileAppeal> findByUserId(Long userId, Pageable pageable);
|
||||
|
||||
@Query("SELECT fa FROM FileAppeal fa WHERE fa.status = :status ORDER BY fa.createdAt ASC")
|
||||
Page<FileAppeal> findPendingAppeals(@Param("status") AppealStatus status, Pageable pageable);
|
||||
|
||||
boolean existsByFileIdAndStatusIn(String fileId, List<AppealStatus> statuses);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -8,6 +10,7 @@ import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -21,6 +24,8 @@ public interface FileEntityRepository extends JpaRepository<FileEntity, String>
|
||||
|
||||
List<FileEntity> findByUserIdAndStatus(Long userId, FileStatus status);
|
||||
|
||||
List<FileEntity> findByUserIdAndStatusIn(Long userId, Collection<FileStatus> statuses);
|
||||
|
||||
Optional<FileEntity> findByFilePath(String filePath);
|
||||
|
||||
Optional<FileEntity> findByUploadSessionId(String uploadSessionId);
|
||||
@@ -66,4 +71,11 @@ public interface FileEntityRepository extends JpaRepository<FileEntity, String>
|
||||
Integer findMaxSupportId();
|
||||
|
||||
List<FileEntity> findByThumbnailPathIsNull();
|
||||
|
||||
Page<FileEntity> findByStatusIn(List<FileStatus> statuses, Pageable pageable);
|
||||
|
||||
List<FileEntity> findByUserIdAndStatusIn(Long userId, List<FileStatus> statuses);
|
||||
|
||||
@Query("SELECT f FROM FileEntity f WHERE f.userId = :userId AND f.status IN :statuses")
|
||||
List<FileEntity> findByStatuses(Long userId, @Param("statuses") List<String> statuses);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public interface ImageSimilarityRepository
|
||||
f.created_at AS uploadDate,
|
||||
f.protection_status AS protectionStatus,
|
||||
f.file_extension AS extension,
|
||||
f.status AS fileStatus,
|
||||
h.hash64_hi AS hash64Hi,
|
||||
h.hash64_lo AS hash64Lo
|
||||
FROM image_hashes ref
|
||||
@@ -30,7 +31,7 @@ public interface ImageSimilarityRepository
|
||||
JOIN file_entities f
|
||||
ON f.id = h.file_id
|
||||
WHERE ref.file_id = :fileId
|
||||
AND f.status = 'ACTIVE'
|
||||
AND f.status IN ('ACTIVE', 'MODERATION')
|
||||
""",
|
||||
nativeQuery = true)
|
||||
List<SimilarImageProjection> findCandidates(
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.complaint.LawCase;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface LawCaseRepository extends JpaRepository<LawCase, Long> {
|
||||
|
||||
@Query("SELECT l FROM LawCase l WHERE l.user.Id = :userId")
|
||||
List<LawCase> getUserLawCases(@Param("userId") Long userId, Pageable pageable);
|
||||
|
||||
// @Query("SELECT l FROM LawCase l WHERE l.user.Id = :userId " +
|
||||
// "AND (:type IS NULL OR l.type = :type) " +
|
||||
// "AND (:lawyer IS NULL OR l.lawyer = :lawyer) " +
|
||||
// "AND (:priority IS NULL OR l.priority = :priority)")
|
||||
// List<LawCase> getUserLawCases(@Param("userId") Long userId,
|
||||
// @Param("type") LawCaseType type,
|
||||
// @Param("lawyer") String lawyer,
|
||||
// @Param("priority") LawCasePriority priority,
|
||||
// Pageable pageable);
|
||||
|
||||
@Query("SELECT l FROM LawCase l WHERE l.user.Id = :userId " +
|
||||
"AND (:type IS NULL OR l.type = :type) " +
|
||||
"AND (:lawyer IS NULL OR l.lawyer = :lawyer) " +
|
||||
"AND (:priority IS NULL OR l.priority = :priority)")
|
||||
Page<LawCase> getUserLawCases(@Param("userId") Long userId,
|
||||
@Param("type") LawCaseType type,
|
||||
@Param("lawyer") String lawyer,
|
||||
@Param("priority") LawCasePriority priority,
|
||||
Pageable pageable);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.file.moderation.ModerationPassportFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ModerationFileRepository extends CrudRepository<ModerationPassportFile, Long> {
|
||||
|
||||
public List<ModerationPassportFile> findByStatus(String status);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.soune.nocopy.entity.file.moderation.ModerationLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModerationLogRepository extends JpaRepository<ModerationLog, String> {
|
||||
|
||||
List<ModerationLog> findByFileIdOrderByCreatedAtDesc(String fileId);
|
||||
|
||||
List<ModerationLog> findByModeratorId(Long moderatorId);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.soune.nocopy.entity.notification.Notification;
|
||||
import ru.soune.nocopy.entity.notification.NotificationStatus;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface NotificationRepository extends JpaRepository<Notification, Long> {
|
||||
Page<Notification> findByUser(User user, Pageable pageable);
|
||||
|
||||
Page<Notification> findByUserAndNotificationTypeIn(User user, List<NotificationType> types, Pageable pageable);
|
||||
|
||||
Page<Notification> findByUserAndStatusIn(User user, List<NotificationStatus> statuses, Pageable pageable);
|
||||
|
||||
Page<Notification> findByUserAndNotificationTypeInAndStatusIn(User user, List<NotificationType> types,
|
||||
List<NotificationStatus> statuses,
|
||||
Pageable pageable);
|
||||
|
||||
List<Notification> findTop5ByUserAndStatusOrderByCreatedAtDesc(User user, NotificationStatus status);
|
||||
|
||||
long countByUserAndStatus(User user, NotificationStatus status);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Notification n SET n.status = :newStatus , n.updatedAt = :updateTime WHERE n.id IN :ids AND n.user = :user AND " +
|
||||
"n.status = :oldStatus")
|
||||
int updateStatus(@Param("ids") List<Long> ids,
|
||||
@Param("user") User user,
|
||||
@Param("oldStatus") NotificationStatus oldStatus,
|
||||
@Param("newStatus") NotificationStatus newStatus,
|
||||
@Param("updateTime") LocalDateTime updateTime);
|
||||
|
||||
Page<Notification> getNotificationsByUser(User user, Pageable pageable);
|
||||
}
|
||||
@@ -15,4 +15,5 @@ public interface SimilarImageProjection {
|
||||
LocalDateTime getUploadDate();
|
||||
ProtectionStatus getProtectionStatus();
|
||||
String getExtension();
|
||||
String getFileStatus();
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package ru.soune.nocopy.repository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.tarif.Tariff;
|
||||
import ru.soune.nocopy.entity.tarif.TariffTimeTerm;
|
||||
import ru.soune.nocopy.entity.tarif.TariffType;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,5 +14,6 @@ public interface TariffRepository extends JpaRepository<Tariff, Long> {
|
||||
Optional<Tariff> findByType(String type);
|
||||
List<Tariff> findAllByOrderByPriceAsc();
|
||||
List<Tariff> findByTariffAccountType(String typeAccount);
|
||||
List<Tariff> findByTariffAccountTypeAndTariffTerm(String typeAccount, TariffTimeTerm tariffTerm);
|
||||
Tariff findByName(String name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.user.UserAdditionalInfo;
|
||||
|
||||
@Repository
|
||||
public interface UserAdditionalInfoRepository extends JpaRepository<UserAdditionalInfo, Long> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.soune.nocopy.entity.user.ModerationStatus;
|
||||
import ru.soune.nocopy.entity.user.moderation.UserVerification;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserVerificationRepository extends JpaRepository<UserVerification, Long> {
|
||||
List<UserVerification> findByUserId(Long userId);
|
||||
List<UserVerification>findByUserIdAndModerationStatus(Long userId, ModerationStatus moderationStatus);
|
||||
}
|
||||
@@ -7,12 +7,16 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||
import ru.soune.nocopy.service.monitoring.MonitoringSearchService;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
import ru.soune.nocopy.service.notification.NotificationService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -23,6 +27,8 @@ public class MonitoringScheduler {
|
||||
|
||||
private final MonitoringSearchService monitoringSearchService;
|
||||
|
||||
private final NotificationService notificationService;
|
||||
|
||||
@Scheduled(cron = "0 1 2 * * *", zone = "Europe/Moscow")
|
||||
@Transactional
|
||||
public void processScheduledMonitoring() {
|
||||
@@ -30,6 +36,8 @@ public class MonitoringScheduler {
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<FileMonitoringEntity> readyForRun = monitoringRepository.findReadyForRun(now);
|
||||
Map<Long, List<FileMonitoringEntity>> groupingFilesMonitoring = readyForRun.stream()
|
||||
.collect(Collectors.groupingBy(FileMonitoringEntity::getUserId));
|
||||
|
||||
log.info("Found {} files ready for monitoring", readyForRun.size());
|
||||
|
||||
@@ -44,5 +52,10 @@ public class MonitoringScheduler {
|
||||
monitoringRepository.save(monitoring);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Long> usersForNotifications = groupingFilesMonitoring.keySet();
|
||||
for (Long userId : usersForNotifications) {
|
||||
notificationService.addNotification(NotificationType.MONITORING_RESULT, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.dto.file.SimilarFileDTO;
|
||||
import ru.soune.nocopy.entity.company.Company;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.DuplicateImageException;
|
||||
@@ -154,22 +155,19 @@ public class FileSimilarityService {
|
||||
var imageHashEntity = hashRepository.findById(fileId)
|
||||
.orElseThrow(() -> new RuntimeException("Hash not found for file: " + fileId));
|
||||
|
||||
List<SimilarImageProjection> candidates;
|
||||
|
||||
List<Long> userIds;
|
||||
// if (authToken == null || "all".equals(authToken)) {
|
||||
candidates = repository.findCandidates(fileId);
|
||||
// } else {
|
||||
Long userId = authTokenRepository.findUserIdByToken(authToken);
|
||||
User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
|
||||
Company company = user.getCompany();
|
||||
if (company != null) {
|
||||
userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toList());
|
||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userIds);
|
||||
} else {
|
||||
userIds = List.of(userId);
|
||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userId);
|
||||
}
|
||||
// }
|
||||
List<SimilarImageProjection> candidates = repository.findCandidates(fileId);
|
||||
|
||||
Long userId = authTokenRepository.findUserIdByToken(authToken);
|
||||
User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
|
||||
Company company = user.getCompany();
|
||||
|
||||
if (company != null) {
|
||||
userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toList());
|
||||
} else {
|
||||
userIds = List.of(userId);
|
||||
}
|
||||
|
||||
List<String> levels = (similarityLevels != null && !similarityLevels.isEmpty())
|
||||
? similarityLevels
|
||||
@@ -180,6 +178,7 @@ public class FileSimilarityService {
|
||||
imageHashEntity.getHash64Hi(),
|
||||
imageHashEntity.getHash64Lo(), userIds))
|
||||
.filter(dto -> levels.contains(dto.getSimilarityLevel()))
|
||||
.filter(dto -> !(dto.getFileStatus().equals(FileStatus.MODERATION.name()) && !dto.getOwner()))
|
||||
.sorted(Comparator.comparingInt(SimilarFileDTO::getHammingDistance))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -228,6 +227,9 @@ public class FileSimilarityService {
|
||||
level = "DIFFERENT";
|
||||
}
|
||||
|
||||
boolean owner = userIds.contains(similarImageProjection.getUserId());
|
||||
|
||||
|
||||
return SimilarFileDTO.builder()
|
||||
.fileId(similarImageProjection.getId())
|
||||
.ownerId(similarImageProjection.getUserId())
|
||||
@@ -240,9 +242,10 @@ public class FileSimilarityService {
|
||||
.supportId(similarImageProjection.getSupportId())
|
||||
.uploadDate(similarImageProjection.getUploadDate())
|
||||
.status(similarImageProjection.getProtectionStatus())
|
||||
.owner(userIds.contains(similarImageProjection.getUserId()))
|
||||
.owner(owner)
|
||||
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
||||
.url(baseUrl + "/api/files/protected/" + similarImageProjection.getId() + "/thumbnail")
|
||||
.fileStatus(similarImageProjection.getFileStatus())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -255,6 +258,7 @@ public class FileSimilarityService {
|
||||
"." + fileEntity.getFileExtension())
|
||||
.fileSize(fileEntity.getFileSize())
|
||||
.uploadDate(fileEntity.getCreatedAt())
|
||||
.fileStatus(fileEntity.getStatus().name())
|
||||
.status(fileEntity.getProtectionStatus())
|
||||
.supportId(Long.valueOf(fileEntity.getSupportId()))
|
||||
.build();
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package ru.soune.nocopy.service.complaint;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.complaint.ComplaintRequest;
|
||||
import ru.soune.nocopy.dto.complaint.ComplaintResponse;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintEntity;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
import ru.soune.nocopy.entity.violation.Violation;
|
||||
import ru.soune.nocopy.exception.ComplaintNotFoundException;
|
||||
import ru.soune.nocopy.exception.DuplicateComplaintException;
|
||||
import ru.soune.nocopy.exception.ViolationNotFoundException;
|
||||
import ru.soune.nocopy.repository.ComplaintEntityRepository;
|
||||
import ru.soune.nocopy.repository.ViolationRepository;
|
||||
import ru.soune.nocopy.service.notification.NotificationService;
|
||||
import ru.soune.nocopy.service.violation.ViolationService;
|
||||
import ru.soune.nocopy.service.violation.ViolationStatus;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional
|
||||
public class ComplaintEntityService {
|
||||
private final ComplaintEntityRepository complaintRepository;
|
||||
|
||||
private final ViolationRepository violationRepository;
|
||||
|
||||
private final ViolationService violationService;
|
||||
|
||||
private final NotificationService notificationService;
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public ComplaintResponse createComplaint(ComplaintRequest request) {
|
||||
Violation violation = violationRepository.findById(request.getViolationId())
|
||||
.orElseThrow(() -> new ViolationNotFoundException("Violation not found: " + request.getViolationId()));
|
||||
|
||||
if (complaintRepository.existsByViolationId(request.getViolationId())) {
|
||||
throw new DuplicateComplaintException("Complaint already exists for violation: " + request.getViolationId());
|
||||
}
|
||||
|
||||
ComplaintEntity complaint = ComplaintEntity.builder()
|
||||
.status(ComplaintStatus.CREATED)
|
||||
.complaintText(request.getComplaintText())
|
||||
.email(request.getEmail())
|
||||
.violation(violation)
|
||||
.not_moderated_file(violation.getFileEntity().getStatus().equals(FileStatus.MODERATION))
|
||||
.build();
|
||||
|
||||
violationService.changeStatus(ViolationStatus.COMPLAINT_IN_WORK, request.getViolationId());
|
||||
|
||||
return mapToResponse(complaintRepository.save(complaint));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public ComplaintResponse getComplaintById(Long id) {
|
||||
return complaintRepository.findById(id)
|
||||
.map(this::mapToResponse)
|
||||
.orElseThrow(() -> new ComplaintNotFoundException("Complaint not found: " + id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<ComplaintResponse> getAllComplaints(Pageable pageable) {
|
||||
return complaintRepository.findAll(pageable).map(this::mapToResponse);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<ComplaintResponse> getComplaintsByViolationId(Long violationId) {
|
||||
if (!violationRepository.existsById(violationId)) {
|
||||
throw new ViolationNotFoundException("Violation not found: " + violationId);
|
||||
}
|
||||
return complaintRepository.findByViolationId(violationId)
|
||||
.stream()
|
||||
.map(this::mapToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ComplaintResponse updateComplaintStatus(Long id, ComplaintStatus status) {
|
||||
ComplaintEntity complaint = complaintRepository.findById(id)
|
||||
.orElseThrow(() -> new ComplaintNotFoundException("Complaint not found: " + id));
|
||||
complaint.setStatus(status);
|
||||
return mapToResponse(complaintRepository.save(complaint));
|
||||
}
|
||||
|
||||
public ComplaintResponse updateComplaint(Long id, ComplaintRequest request) {
|
||||
ComplaintEntity complaint = complaintRepository.findById(id)
|
||||
.orElseThrow(() -> new ComplaintNotFoundException("Complaint not found: " + id));
|
||||
|
||||
if (request.getViolationId() != null) {
|
||||
Violation violation = violationRepository.findById(request.getViolationId())
|
||||
.orElseThrow(() -> new ViolationNotFoundException("Violation not found: " + request.getViolationId()));
|
||||
complaint.setViolation(violation);
|
||||
}
|
||||
if (request.getComplaintText() != null) complaint.setComplaintText(request.getComplaintText());
|
||||
if (request.getEmail() != null) complaint.setEmail(request.getEmail());
|
||||
if (request.getStatus() != null) {
|
||||
complaint.setStatus(ComplaintStatus.valueOf(request.getStatus()));
|
||||
|
||||
notificationService.addNotification(NotificationType.COMPLAINT_STATUS_CHANGED, complaint.getViolation()
|
||||
.getFileEntity().getUserId(), request.getStatus());
|
||||
}
|
||||
|
||||
return mapToResponse(complaintRepository.save(complaint));
|
||||
}
|
||||
|
||||
public ComplaintResponse deleteComplaint(Long id) {
|
||||
ComplaintEntity complaint = complaintRepository.findById(id)
|
||||
.orElseThrow(() -> new ComplaintNotFoundException("Complaint not found: " + id));
|
||||
complaint.setStatus(ComplaintStatus.CANCELLED);
|
||||
return mapToResponse(complaintRepository.save(complaint));
|
||||
}
|
||||
|
||||
private ComplaintResponse mapToResponse(ComplaintEntity entity) {
|
||||
|
||||
return ComplaintResponse.builder()
|
||||
.id(entity.getId())
|
||||
.status(entity.getStatus() != null ? entity.getStatus().name() : null)
|
||||
.complaintText(entity.getComplaintText())
|
||||
.email(entity.getEmail())
|
||||
.violationId(entity.getViolation() != null ? entity.getViolation().getId() : null)
|
||||
.createdAt(entity.getCreatedAt() != null ? entity.getCreatedAt().format(DATE_FORMATTER) : null)
|
||||
.updatedAt(entity.getUpdatedAt() != null ? entity.getUpdatedAt().format(DATE_FORMATTER) : null)
|
||||
.notModerated(entity.getNot_moderated_file() != null ? entity.getNot_moderated_file() : null)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package ru.soune.nocopy.service.complaint;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.entity.complaint.LawCase;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
import ru.soune.nocopy.repository.LawCaseRepository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LawCaseService {
|
||||
|
||||
private final LawCaseRepository lawCaseRepository;
|
||||
|
||||
public LawCase addLawCase(BigDecimal amount, String description, String name,
|
||||
LawCasePriority priority) {
|
||||
LawCase lawCase = new LawCase();
|
||||
|
||||
BigDecimal damage = amount == null ? BigDecimal.ZERO : amount;
|
||||
|
||||
lawCase.setAmount(damage);
|
||||
lawCase.setName(name);
|
||||
lawCase.setDescription(description);
|
||||
lawCase.setPriority(priority);
|
||||
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase getById(Long id) {
|
||||
return lawCaseRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public LawCase changeStatus(Long id, LawCaseType type) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lawCase.setType(type);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase changePriority(Long id, LawCasePriority priority) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lawCase.setPriority(priority);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase changeDamage(Long id, BigDecimal damage) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
lawCase.setAmount(damage);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public List<LawCase> getAllUserLawCases(Long userId, int pageSize, int pageNumber, String propertySort,
|
||||
String ascDesc) {
|
||||
Sort.Direction direction = ascDesc.equalsIgnoreCase("desc") ? Sort.Direction.DESC:
|
||||
Sort.Direction.ASC;
|
||||
Sort sort = Sort.by(direction, propertySort);
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
|
||||
return lawCaseRepository.getUserLawCases(userId, pageable);
|
||||
}
|
||||
|
||||
public Page<LawCase> getAllUserLawCases(Long userId, int pageSize, int pageNumber,
|
||||
LawCaseType lawCaseType, String lawyer,
|
||||
LawCasePriority lawCasePriority,
|
||||
String propertySort, String ascDesc) {
|
||||
Sort.Direction direction = ascDesc.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC;
|
||||
Sort sort = Sort.by(direction, propertySort);
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
|
||||
return lawCaseRepository.getUserLawCases(userId, lawCaseType, lawyer, lawCasePriority, pageable);
|
||||
}
|
||||
|
||||
public void deleteById(Long id) {
|
||||
lawCaseRepository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,20 +9,14 @@ import ru.soune.nocopy.dto.file.FileEntityResponse;
|
||||
import ru.soune.nocopy.dto.file.FileResponse;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.FileUploadSession;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
|
||||
import ru.soune.nocopy.entity.monitoring.MonitoringType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.DuplicateImageException;
|
||||
import ru.soune.nocopy.exception.FileEntityNotFoundException;
|
||||
import ru.soune.nocopy.handler.MonitoringHandler;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||
import ru.soune.nocopy.repository.SimilarImageProjection;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.FileSimilarityService;
|
||||
import ru.soune.nocopy.service.ImageHashService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,7 +26,6 @@ import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -43,10 +36,6 @@ public class FileEntityService {
|
||||
|
||||
private final FileEntityRepository fileEntityRepository;
|
||||
|
||||
private final ImageHashService imageHashService;
|
||||
|
||||
private final FileSimilarityService fileSimilarityService;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
private final ImageResizeService imageResizeService;
|
||||
@@ -54,63 +43,6 @@ public class FileEntityService {
|
||||
@Value("${server.baseurl}")
|
||||
private String baseUrl;
|
||||
|
||||
@Transactional(noRollbackFor = DuplicateImageException.class)
|
||||
public FileEntity createFromUploadSession(FileUploadSession session, String checksum) {
|
||||
log.info("Creating FileEntity for upload session: {}", session.getUploadId());
|
||||
|
||||
try {
|
||||
Path filePath = Paths.get(session.getFilePath());
|
||||
|
||||
if (!Files.exists(filePath)) {
|
||||
throw new IOException("File not found on disk: " + filePath);
|
||||
}
|
||||
|
||||
Map<String, Long> imageHash = Map.of();
|
||||
|
||||
if (session.getFileType().startsWith("image")) {
|
||||
imageHash = imageHashService.calculateHash(filePath);
|
||||
List<SimilarImageProjection> duplicatedByHash = fileSimilarityService.findDuplicatedByHash(
|
||||
imageHash.get("hi"), imageHash.get("low"));
|
||||
|
||||
if (!duplicatedByHash.isEmpty()) {
|
||||
SimilarImageProjection similarImageProjection = duplicatedByHash.get(0);
|
||||
|
||||
throw new DuplicateImageException("Duplicate", similarImageProjection.getId(),
|
||||
similarImageProjection.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
long fileSize = Files.size(filePath);
|
||||
String originalName = session.getFileName();
|
||||
String storedName = filePath.getFileName().toString();
|
||||
|
||||
FileEntity fileEntity = FileEntity.builder()
|
||||
.userId(session.getUserId())
|
||||
.originalFileName(originalName)
|
||||
.storedFileName(storedName)
|
||||
.filePath(session.getFilePath())
|
||||
.fileSize(fileSize)
|
||||
.mimeType(session.getFileType())
|
||||
.fileExtension(session.getExtension())
|
||||
.checksum(checksum)
|
||||
.uploadSessionId(session.getUploadId())
|
||||
.status(FileStatus.ACTIVE)
|
||||
.build();
|
||||
|
||||
FileEntity saved = fileEntityRepository.save(fileEntity);
|
||||
|
||||
if (!imageHash.isEmpty()) {
|
||||
imageHashService.create(saved, imageHash);
|
||||
}
|
||||
|
||||
return saved;
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to create FileEntity for session {}: {}",
|
||||
session.getUploadId(), e.getMessage(), e);
|
||||
throw new RuntimeException("Failed to create file entity: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileEntityResponse getById(String fileId, int version) {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(fileId)
|
||||
@@ -145,10 +77,28 @@ public class FileEntityService {
|
||||
for (Long uId : userRepository.findByCompanyId(user.getCompany().getId()).stream()
|
||||
.map(User::getId)
|
||||
.toList()) {
|
||||
allFiles.addAll(fileEntityRepository.findByUserIdAndStatus(uId, FileStatus.ACTIVE));
|
||||
allFiles.addAll(getAllUserFiles(uId, List.of(FileStatus.ACTIVE, FileStatus.BLOCKED,
|
||||
FileStatus.MODERATION)));
|
||||
}
|
||||
} else {
|
||||
allFiles = fileEntityRepository.findByUserIdAndStatus(userId, FileStatus.ACTIVE);
|
||||
allFiles = getAllUserFiles(userId, List.of(FileStatus.ACTIVE, FileStatus.BLOCKED, FileStatus.MODERATION));
|
||||
}
|
||||
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
public List<FileEntity> getAllUserFiles(Long userId, List<FileStatus> statuses) {
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
List<FileEntity> allFiles = new ArrayList<>();
|
||||
|
||||
if (user.getCompany() != null) {
|
||||
for (Long uId : userRepository.findByCompanyId(user.getCompany().getId()).stream()
|
||||
.map(User::getId)
|
||||
.toList()) {
|
||||
allFiles.addAll(fileEntityRepository.findByUserIdAndStatusIn(uId, statuses));
|
||||
}
|
||||
} else {
|
||||
allFiles = fileEntityRepository.findByUserIdAndStatusIn(userId, statuses);
|
||||
}
|
||||
|
||||
return allFiles;
|
||||
@@ -163,12 +113,13 @@ public class FileEntityService {
|
||||
for (Long uId : userRepository.findByCompanyId(user.getCompany().getId()).stream()
|
||||
.map(User::getId)
|
||||
.toList()) {
|
||||
allFiles.addAll(fileEntityRepository.findByUserIdAndStatus(uId, FileStatus.ACTIVE));
|
||||
allFiles.addAll(fileEntityRepository.findByUserIdAndStatusIn(uId,
|
||||
List.of(FileStatus.ACTIVE, FileStatus.BLOCKED, FileStatus.MODERATION)));
|
||||
}
|
||||
|
||||
} else {
|
||||
allFiles = fileEntityRepository.findByUserIdAndStatus(
|
||||
userId, FileStatus.ACTIVE);
|
||||
allFiles = fileEntityRepository.findByUserIdAndStatusIn(userId,
|
||||
List.of(FileStatus.ACTIVE, FileStatus.BLOCKED, FileStatus.MODERATION));
|
||||
}
|
||||
|
||||
int start = (page - 1) * pageSize;
|
||||
@@ -205,31 +156,18 @@ public class FileEntityService {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public FileEntity markAsDeleted(FileEntity fileEntity) throws IOException {
|
||||
fileEntity.setStatus(FileStatus.DELETED);
|
||||
fileEntity.setUpdatedAt(LocalDateTime.now());
|
||||
fileEntity.setProtectionStatus(ProtectionStatus.NOT_PROTECTED);
|
||||
|
||||
Path path = Paths.get(fileEntity.getProtectedFilePath());
|
||||
Files.deleteIfExists(path);
|
||||
fileEntity.setProtectedFilePath("");
|
||||
|
||||
return fileEntityRepository.save(fileEntity);
|
||||
}
|
||||
|
||||
public void softDeleteFileWithHash(FileEntity fileEntity) throws IOException {
|
||||
if (fileEntity.getImageHash() != null) {
|
||||
fileEntity.setImageHash(null);
|
||||
}
|
||||
|
||||
fileEntity.setStatus(FileStatus.DELETED);
|
||||
fileEntity.setStatus(FileStatus.REMOVED);
|
||||
fileEntity.setUpdatedAt(LocalDateTime.now());
|
||||
fileEntity.setProtectionStatus(ProtectionStatus.NOT_PROTECTED);
|
||||
// fileEntity.setProtectionStatus(ProtectionStatus.NOT_PROTECTED);
|
||||
|
||||
Path path = Paths.get(fileEntity.getProtectedFilePath());
|
||||
Files.deleteIfExists(path);
|
||||
fileEntity.setProtectedFilePath("");
|
||||
// Path path = Paths.get(fileEntity.getProtectedFilePath());
|
||||
// Files.deleteIfExists(path);
|
||||
// fileEntity.setProtectedFilePath("");
|
||||
|
||||
fileEntityRepository.save(fileEntity);
|
||||
}
|
||||
@@ -252,7 +190,7 @@ public class FileEntityService {
|
||||
return totalSize != null ? totalSize : 0L;
|
||||
}
|
||||
|
||||
public void changeStatus(ProtectionStatus newStatus, String fileId) {
|
||||
public void changeProtectionStatus(ProtectionStatus newStatus, String fileId) {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(fileId)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException(fileId));
|
||||
fileEntity.setProtectionStatus(newStatus);
|
||||
@@ -260,6 +198,14 @@ public class FileEntityService {
|
||||
fileEntityRepository.save(fileEntity);
|
||||
}
|
||||
|
||||
public void changeFileStatus(FileStatus newStatus, String fileId) {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(fileId)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException(fileId));
|
||||
fileEntity.setStatus(newStatus);
|
||||
|
||||
fileEntityRepository.save(fileEntity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void writeProtectedFile(String id, byte[] data, String fileExt) throws IOException {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(id)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user