Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/de/schulung/quarkus/recipes/Ingredient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.schulung.quarkus.recipes;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

import lombok.Getter;
import lombok.Setter;

Expand All @@ -10,14 +14,18 @@ public class Ingredient {
/**
* The ingredient name.
*/
@NotNull
@Size(min = 1, max = 100)
private String name;
/**
* The quantity of the ingredient.
*/
@Positive
private double quantity;
/**
* The unit of the ingredient.
*/
@NotNull
private IngredientUnit unit;

}
18 changes: 16 additions & 2 deletions src/main/java/de/schulung/quarkus/recipes/Recipe.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package de.schulung.quarkus.recipes;

import com.fasterxml.jackson.annotation.JsonProperty;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -20,14 +24,19 @@ public class Recipe {
/**
* The recipe name.
*/
@NotNull
@Size(min = 1, max = 100)
private String name;
/**
* URL of the recipe image, absolute or relative.
*/
@Size(max = 255)
@Pattern(regexp = "^(/|https?://).+")
private String img;
/**
* The number of servings.
*/
@Min(1)
private int servings;
/**
* The last edited timestamp (read-only, assigned by the server).
Expand All @@ -37,6 +46,7 @@ public class Recipe {
/**
* Preparation time in minutes.
*/
@Min(1)
private int duration;
/**
* Difficulty level of the recipe.
Expand All @@ -45,10 +55,14 @@ public class Recipe {
/**
* List of ingredients.
*/
private List<Ingredient> ingredients;
@NotNull
@Size(max = 100)
private List<@Valid @NotNull Ingredient> ingredients;
/**
* Preparation instructions.
*/
@NotNull
@Size(max = 2000)
private String preparation;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.schulung.quarkus.recipes;

import jakarta.validation.Valid;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -26,6 +27,7 @@ public Collection<Recipe> getAllRecipes() {

@POST
public Response createRecipe(
@Valid
Recipe recipe,
@Context
UriInfo uriInfo
Expand Down
Loading