106 lines
2.4 KiB
Java
106 lines
2.4 KiB
Java
package com.example.hangry;
|
|
|
|
import jakarta.persistence.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Entity
|
|
public class User {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String username;
|
|
|
|
@Column(nullable = false)
|
|
private String password; // Hier solltest du sicherstellen, dass das Passwort verschlüsselt wird
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String email;
|
|
|
|
private String role; // Für Rollen wie "ADMIN", "USER", etc.
|
|
|
|
// Many-to-Many Beziehung zu Ingredients
|
|
@ManyToMany
|
|
@JoinTable(
|
|
name = "user_ingredients",
|
|
joinColumns = @JoinColumn(name = "user_id"),
|
|
inverseJoinColumns = @JoinColumn(name = "ingredient_id")
|
|
)
|
|
private List<Ingredient> ingredients = new ArrayList<>();
|
|
|
|
// No-Args-Konstruktor (wichtig für JPA)
|
|
public User() {
|
|
}
|
|
|
|
// All-Args-Konstruktor
|
|
public User(Long id, String username, String password, String email, String role) {
|
|
this.id = id;
|
|
this.username = username;
|
|
this.password = password;
|
|
this.email = email;
|
|
this.role = role;
|
|
}
|
|
|
|
// Getter und Setter
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public String getEmail() {
|
|
return email;
|
|
}
|
|
|
|
public void setEmail(String email) {
|
|
this.email = email;
|
|
}
|
|
|
|
public String getRole() {
|
|
return role;
|
|
}
|
|
|
|
public void setRole(String role) {
|
|
this.role = role;
|
|
}
|
|
|
|
public List<Ingredient> getIngredients() {
|
|
return ingredients;
|
|
}
|
|
|
|
public void setIngredients(List<Ingredient> ingredients) {
|
|
this.ingredients = ingredients;
|
|
}
|
|
|
|
// Methode, um eine Zutat zu einem User hinzuzufügen
|
|
public void addIngredient(Ingredient ingredient) {
|
|
this.ingredients.add(ingredient);
|
|
}
|
|
|
|
// Methode, um eine Zutat aus der Liste zu entfernen
|
|
public void removeIngredient(Ingredient ingredient) {
|
|
this.ingredients.remove(ingredient);
|
|
}
|
|
}
|