Update 4 files

- /demo/src/main/java/com/example/demo/dto/RecipeUpdateRequest.java
- /demo/src/main/java/com/example/demo/dto/IngredientDto.java
- /demo/src/main/java/com/example/demo/dto/RecipeCreateRequest.java
- /demo/src/main/java/com/example/demo/dto/RecipeResponse.java
This commit is contained in:
Madeleine Stamp
2026-03-04 13:59:31 -07:00
parent 9335314e1f
commit fe2cd38277
4 changed files with 184 additions and 2 deletions
@@ -1,5 +1,26 @@
package com.example.demo.dto; package com.example.demo.dto;
import java.math.BigDecimal;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
public class IngredientDto { public class IngredientDto {
@NotBlank(message = "ingredientName is required")
private String ingredientName;
@PositiveOrZero(message = "quantity must be 0 or greater")
private BigDecimal quantity;
private String unit;
public String getIngredientName() { return ingredientName; }
public void setIngredientName(String ingredientName) { this.ingredientName = ingredientName; }
public @PositiveOrZero(message = "quantity must be 0 or greater") BigDecimal getQuantity() { return quantity; }
public void setQuantity(BigDecimal bigDecimal) { this.quantity = bigDecimal; }
public String getUnit() { return unit; }
public void setUnit(String unit) { this.unit = unit; }
} }
@@ -1,5 +1,59 @@
package com.example.demo.dto; package com.example.demo.dto;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import jakarta.validation.constraints.Size;
import java.util.List;
import com.example.demo.dto.StepDto;
public class RecipeCreateRequest { public class RecipeCreateRequest {
@NotBlank(message = "title is required")
@Size(max = 100, message = "title must be 100 characters or less")
private String title;
@Size(max = 1000, message = "description must be 1000 characters or less")
private String description;
@PositiveOrZero(message = "prepTimeMinutes must be 0 or greater")
private int prepTimeMinutes;
@PositiveOrZero(message = "cookTimeMinutes must be 0 or greater")
private int cookTimeMinutes;
@PositiveOrZero(message = "servings must be 0 or greater")
private int servings;
@NotNull(message = "ingredients list is required")
@Valid
private java.util.List<IngredientDto> ingredients;
@NotNull(message = "steps list is required")
@Valid
private java.util.List<StepDto> steps;
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public int getPrepTimeMinutes() { return prepTimeMinutes; }
public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; }
public int getCookTimeMinutes() { return cookTimeMinutes; }
public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; }
public int getServings() { return servings; }
public void setServings(int servings) { this.servings = servings; }
public java.util.List<IngredientDto> getIngredients() { return ingredients; }
public void setIngredients(java.util.List<IngredientDto> ingredients) { this.ingredients = ingredients; }
public java.util.List<StepDto> getSteps() { return steps; }
public void setSteps(java.util.List<StepDto> steps) { this.steps = steps; }
} }
@@ -1,5 +1,53 @@
package com.example.demo.dto; package com.example.demo.dto;
import java.time.LocalDateTime;
import java.util.List;
import com.example.demo.dto.StepDto;
public class RecipeResponse { public class RecipeResponse {
private Long id;
private String title;
private String description;
private int prepTimeMinutes;
private int cookTimeMinutes;
private int servings;
private List<IngredientDto> ingredients;
private List<StepDto> steps;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public int getPrepTimeMinutes() { return prepTimeMinutes; }
public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; }
public int getCookTimeMinutes() { return cookTimeMinutes; }
public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; }
public int getServings() { return servings; }
public void setServings(int servings) { this.servings = servings; }
public List<IngredientDto> getIngredients() { return ingredients; }
public void setIngredients(List<IngredientDto> ingredients) { this.ingredients = ingredients; }
public List<StepDto> getSteps() { return steps; }
public void setSteps(List<StepDto> steps) { this.steps = steps; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
} }
@@ -0,0 +1,59 @@
package com.example.demo.dto;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import jakarta.validation.constraints.Size;
import java.util.List;
import com.example.demo.dto.StepDto;
public class RecipeUpdateRequest {
@NotBlank(message = "title is required")
@Size(max = 100, message = "title must be 100 characters or less")
private String title;
@Size(max = 1000, message = "description must be 1000 characters or less")
private String description;
@PositiveOrZero(message = "prepTimeMinutes must be 0 or greater")
private int prepTimeMinutes;
@PositiveOrZero(message = "cookTimeMinutes must be 0 or greater")
private int cookTimeMinutes;
@PositiveOrZero(message = "servings must be 0 or greater")
private int servings;
@NotNull(message = "ingredients list is required")
@Valid
private List<IngredientDto> ingredients;
@NotNull(message = "steps list is required")
@Valid
private List<StepDto> steps;
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public int getPrepTimeMinutes() { return prepTimeMinutes; }
public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; }
public int getCookTimeMinutes() { return cookTimeMinutes; }
public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; }
public int getServings() { return servings; }
public void setServings(int servings) { this.servings = servings; }
public List<IngredientDto> getIngredients() { return ingredients; }
public void setIngredients(List<IngredientDto> ingredients) { this.ingredients = ingredients; }
public List<StepDto> getSteps() { return steps; }
public void setSteps(List<StepDto> steps) { this.steps = steps; }
}