SaveTastingRequest.java
1,435 bytes
| 1 | package com.tasteprint.tasting; |
|---|---|
| 2 | |
| 3 | import java.time.LocalDate; |
| 4 | |
| 5 | import jakarta.validation.constraints.DecimalMax; |
| 6 | import jakarta.validation.constraints.DecimalMin; |
| 7 | import jakarta.validation.constraints.Max; |
| 8 | import jakarta.validation.constraints.Min; |
| 9 | import jakarta.validation.constraints.NotBlank; |
| 10 | import jakarta.validation.constraints.NotNull; |
| 11 | import jakarta.validation.constraints.PastOrPresent; |
| 12 | import jakarta.validation.constraints.Pattern; |
| 13 | import jakarta.validation.constraints.Size; |
| 14 | |
| 15 | public record SaveTastingRequest( |
| 16 | @NotBlank @Size(max = 120) String dishSlug, |
| 17 | @Size(max = 160) String restaurantName, |
| 18 | @NotBlank @Size(max = 100) String city, |
| 19 | @NotBlank @Pattern(regexp = "^[A-Za-z]{2}$", message = "must be a two-letter country code") String countryCode, |
| 20 | @NotNull @PastOrPresent LocalDate tastedOn, |
| 21 | @NotNull @Min(1) @Max(5) Integer rating, |
| 22 | @Size(max = 500) String note, |
| 23 | @Size(max = 500) @Pattern(regexp = "^$|^https://.+|^/uploads/[A-Za-z0-9._-]+$", message = "must be an HTTPS URL or an uploaded photo") String photoUrl, |
| 24 | @DecimalMin("-90.0") @DecimalMax("90.0") Double latitude, |
| 25 | @DecimalMin("-180.0") @DecimalMax("180.0") Double longitude |
| 26 | ) { |
| 27 | public SaveTastingRequest { |
| 28 | if ((latitude == null) != (longitude == null)) { |
| 29 | throw new IllegalArgumentException("Latitude and longitude must be provided together."); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |