@@ -14,6 +14,7 @@ import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.repository.GlobalSearchTaskRepository;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.search.GlobalSearchService;
|
||||
import ru.soune.nocopy.service.violation.ViolationService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -31,6 +32,8 @@ public class GlobalSearchController {
|
||||
|
||||
private final GlobalSearchTaskRepository searchTaskRepository;
|
||||
|
||||
private final ViolationService violationService;
|
||||
|
||||
@PostMapping("/start")
|
||||
public ResponseEntity<?> startSearch(
|
||||
@RequestBody GlobalSearchStartRequest request,
|
||||
@@ -101,6 +104,35 @@ public class GlobalSearchController {
|
||||
return ResponseEntity.ok(taskOptional.get());
|
||||
}
|
||||
|
||||
@GetMapping("/violation-summary")
|
||||
public ResponseEntity<?> getSummary(@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
||||
|
||||
if (tokenHeader == null || tokenHeader.isBlank()) {
|
||||
Map<String, Object> errorData = new HashMap<>();
|
||||
errorData.put("token", tokenHeader);
|
||||
|
||||
return ResponseEntity.ok().body(Map.of("error", errorData));
|
||||
}
|
||||
|
||||
Map<String, Map<String, Object>> fileViolationsSummary;
|
||||
|
||||
try {
|
||||
Long userId = authService.useUserAuthToken(tokenHeader);
|
||||
|
||||
fileViolationsSummary =
|
||||
violationService.getFileViolationsSummary(userId);
|
||||
|
||||
if (fileViolationsSummary.isEmpty()) return ResponseEntity.ok().body("Violations summary not found");
|
||||
} catch (NotFoundAuthToken e) {
|
||||
Map<String, Object> errorData = new HashMap<>();
|
||||
errorData.put("token", tokenHeader);
|
||||
|
||||
return ResponseEntity.ok().body(Map.of("error", errorData));
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(fileViolationsSummary);
|
||||
}
|
||||
|
||||
@GetMapping("/status/{taskId}")
|
||||
public ResponseEntity<?> getStatus(@PathVariable String taskId,
|
||||
@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
||||
|
||||
Reference in New Issue
Block a user