diff --git a/src/main/java/ru/soune/nocopy/dto/violation/ViolationRequest.java b/src/main/java/ru/soune/nocopy/dto/violation/ViolationRequest.java index 84f4141..4dd51db 100644 --- a/src/main/java/ru/soune/nocopy/dto/violation/ViolationRequest.java +++ b/src/main/java/ru/soune/nocopy/dto/violation/ViolationRequest.java @@ -13,15 +13,6 @@ public class ViolationRequest { @JsonProperty("violation_id") private Long violationId; - @JsonProperty("page") - private Integer page = 0; - - @JsonProperty("size") - private Integer size = 10; - - @JsonProperty("sort_direction") - private String sortDirection = "desc"; - @JsonProperty("status") private String status; @@ -31,9 +22,6 @@ public class ViolationRequest { @JsonProperty("end_date") private String endDate; - @JsonProperty("group_by") - private String groupBy; - @JsonProperty("action") private String action; @@ -42,4 +30,17 @@ public class ViolationRequest { @JsonProperty("file_name") private String fileName = null; + + @JsonProperty("page") + private Integer page = 0; + + @JsonProperty("size") + private Integer size = 10; + + @JsonProperty("sort_direction") + private String sortDirection = "desc"; + + @JsonProperty("group_by") + private String groupBy; + } \ No newline at end of file diff --git a/src/main/java/ru/soune/nocopy/dto/violation/ViolationResponse.java b/src/main/java/ru/soune/nocopy/dto/violation/ViolationResponse.java index 8a588c6..cc462fa 100644 --- a/src/main/java/ru/soune/nocopy/dto/violation/ViolationResponse.java +++ b/src/main/java/ru/soune/nocopy/dto/violation/ViolationResponse.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; import ru.soune.nocopy.entity.violation.Violation; -import ru.soune.nocopy.service.geo.GeoCountryService; import java.time.LocalDateTime; import java.util.List; @@ -13,8 +12,6 @@ import java.util.List; @Builder public class ViolationResponse { - private final GeoCountryService geoCountryService; - @JsonProperty("violations") private List violations; diff --git a/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java b/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java index 3426e6d..7958b69 100644 --- a/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java +++ b/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java @@ -66,6 +66,16 @@ public class ViolationHandler implements RequestHandler { if (violationRequest.getFileId() != null && !violationRequest.getFileId().isEmpty()) { FileEntity file = fileRepository.findById(violationRequest.getFileId()) .orElseThrow(() -> new FileNotFoundException("File not found with id: " + violationRequest.getFileId())); + + if (!Objects.equals(file.getUserId(), userId)) { + return BaseResponse.builder() + .messageCode(MessageCode.USER_NOT_HAD_PERMISSION.getCode()) + .messageCode(MessageCode.USER_NOT_HAD_PERMISSION.getCode()) + .msgId(request.getMsgId()) + .messageBody(Map.of("user_id", userId)) + .build(); + } + targetFiles = List.of(file); } else { targetFiles = fileEntityService.getAllUserFiles(userId); @@ -170,6 +180,8 @@ public class ViolationHandler implements RequestHandler { return BaseResponse.builder() .msgId(request.getMsgId()) .messageBody(response) + .messageCode(MessageCode.SUCCESS.getCode()) + .messageDesc(MessageCode.SUCCESS.getDescription()) .build(); } } diff --git a/src/main/java/ru/soune/nocopy/service/geo/GeoCountryService.java b/src/main/java/ru/soune/nocopy/service/geo/GeoCountryService.java index 597975c..a888029 100644 --- a/src/main/java/ru/soune/nocopy/service/geo/GeoCountryService.java +++ b/src/main/java/ru/soune/nocopy/service/geo/GeoCountryService.java @@ -37,7 +37,8 @@ public class GeoCountryService { try { CountryResponse response = extractCountry(input); - return response.getCountry().getName(); + return response.getCountry().getName() == null ? "Not defined": + response.getCountry().getName(); } catch (Exception e) { log.error("Failed for input: {}", input, e); return "UNKNOWN"; @@ -83,7 +84,8 @@ public class GeoCountryService { try { CountryResponse response = extractCountry(input); - return response.getCountry().getIsoCode(); + return response.getCountry().getIsoCode() == null ? "Not defined": + response.getCountry().getIsoCode(); } catch (Exception e) { log.error("Failed for input: {}", input, e); return "UNKNOWN";