backend stuff for ingredients and nutritions AND FIXED MAGIC NUMBERS and fixed stevens and oskars problems

This commit is contained in:
Aysegul Aydinlik 2025-12-05 00:12:53 +01:00
commit f9262d4046
2 changed files with 12 additions and 3 deletions

View file

@ -1,12 +1,12 @@
package commons; package commons;
import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Ingredient { public class Ingredient {
@ -20,10 +20,17 @@ public class Ingredient {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
public long id; public long id;
@Column(name = "name", nullable = false, unique = true)
public String name; public String name;
@Column(name = "protein", nullable = false)
public double proteinPer100g; public double proteinPer100g;
@Column(name = "fat", nullable = false)
public double fatPer100g; public double fatPer100g;
@Column(name = "carbs", nullable = false)
public double carbsPer100g; public double carbsPer100g;
@SuppressWarnings("unused") @SuppressWarnings("unused")

View file

@ -14,10 +14,12 @@ public class RecipeIngredient {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id; public Long id;
// which recipe is used
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "recipe_id") @JoinColumn(name = "recipe_id")
public Recipe recipe; public Recipe recipe;
//which ingredient is used
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "ingredient_id") @JoinColumn(name = "ingredient_id")
public Ingredient ingredient; public Ingredient ingredient;
@ -35,12 +37,12 @@ public class RecipeIngredient {
public RecipeIngredient(Recipe recipe, //which recipe public RecipeIngredient(Recipe recipe, //which recipe
Ingredient ingredient, // which ingredient Ingredient ingredient, // which ingredient
double amount, // the amount double amount, // the amount
String unitName) { //gram liter etc String unit) { //gram liter etc
//store it im tha field //store it im tha field
this.recipe = recipe; this.recipe = recipe;
this.ingredient = ingredient; this.ingredient = ingredient;
this.amount = amount; this.amount = amount;
this.unitName = unitName; this.unitName = unit;
} }
// Convert unitName to Unit object so java can read it // Convert unitName to Unit object so java can read it