Код: Выделить всё
@RestController
@RequestMapping("v1/games")
public class GameController {
@PostMapping
public GameCreateOutWeb create(@RequestBody @Valid GameWeb dto) {
//some request handling
}
}
Код: Выделить всё
public record GameWeb(@NotBlank String localId, @NotBlank String name,
List slots) {
}
Код: Выделить всё
public record SlotWeb(@NotNull SlotColor color, @NotNull SlotStatus status, PlayerWeb player) {
public record PlayerWeb(Long id, String name) {
}
}
public enum SlotStatus {
OPEN((short) 0), CLOSED((short) 1), OCCUPIED((short) 2);
private final short statusCode;
//constructor and getter
}
public enum SlotColor {
RED((short) 0), BLUE((short) 1), TEAL((short) 2), PURPLE((short) 3), YELLOW((short) 4), ORANGE((short) 5);
private final short colorCode;
//constructor and getter
}
Код: Выделить всё
@SlotВ аннотации
Код: Выделить всё
@Target(TYPE_USE)
@Retention(RUNTIME)
@Constraint(validatedBy = {SlotValidator.class})
public @interface Slot {
String message() default "If slotStatus == OCCUPIED(2) then player field must not be null.";
Class[] groups() default {};
Class
Подробнее здесь: [url]https://stackoverflow.com/questions/79086580/skip-invalid-array-collection-elements-annotated-with-valid[/url]