@@ -8,11 +8,14 @@ import ru.soune.nocopy.dto.BaseRequest;
|
||||
import ru.soune.nocopy.dto.BaseResponse;
|
||||
import ru.soune.nocopy.dto.violation.ViolationStatisticsRequest;
|
||||
import ru.soune.nocopy.dto.violation.ViolationStatisticsResponse;
|
||||
import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.service.violation.ViolationService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -22,6 +25,8 @@ public class ViolationStatisticsHandler implements RequestHandler {
|
||||
|
||||
private final ViolationService violationService;
|
||||
|
||||
private final AuthTokenRepository authTokenRepository;
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
@@ -43,8 +48,17 @@ public class ViolationStatisticsHandler implements RequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Optional<AuthToken> tokenOptional =
|
||||
authTokenRepository.findByToken(statRequest.getToken());
|
||||
|
||||
if (tokenOptional.isPresent()) {
|
||||
throw new IllegalArgumentException("User token is required");
|
||||
}
|
||||
|
||||
Long userId = tokenOptional.orElseThrow().getUser().getId();
|
||||
|
||||
ViolationStatisticsResponse statistics = violationService.getViolationStatistics(
|
||||
statRequest.getUserId(),
|
||||
userId,
|
||||
statRequest.getFileId(),
|
||||
startDate,
|
||||
endDate
|
||||
@@ -57,8 +71,8 @@ public class ViolationStatisticsHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
private void validateRequest(ViolationStatisticsRequest request) {
|
||||
if (request.getUserId() == null) {
|
||||
throw new IllegalArgumentException("User ID is required");
|
||||
if (request.getToken() == null) {
|
||||
throw new IllegalArgumentException("Token is required");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user