init commit

This commit is contained in:
2026-10-22 20:59:59 +03:00
parent ec540a1a72
commit 1fddc0e76c
95 changed files with 5668 additions and 27 deletions
@@ -0,0 +1,39 @@
package ru.mtusi.messenger.validation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import ru.mtusi.messenger.config.properties.IdempotencyProperties;
import ru.mtusi.messenger.exception.InvalidRequestException;
import java.util.regex.Pattern;
@Component
@RequiredArgsConstructor
public class IdempotencyValidator {
private final IdempotencyProperties properties;
public void validateKey(String key) {
requireNotBlank(key);
requireMaxLength(key);
requirePattern(key);
}
private void requireNotBlank(String key) {
if (key == null || key.isEmpty()) {
throw new InvalidRequestException("Idempotency-Key header is required");
}
}
private void requireMaxLength(String key) {
if (key.length() > properties.keyMaxLength()) {
throw new InvalidRequestException("Idempotency-Key is too long");
}
}
private void requirePattern(String key) {
if (!Pattern.matches(properties.keyPattern(), key)) {
throw new InvalidRequestException("Idempotency-Key contains invalid characters");
}
}
}