Skip to content

Commit

Permalink
chore: 데이터 모델 구현 초기(#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed Apr 2, 2024
1 parent 25b2aa9 commit f947a38
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.skhu.tastyinventory_be.domain.inventory;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventoryVolume.InventoryVolume;

import java.util.HashSet;
import java.util.Set;

@Getter
@NoArgsConstructor
@Entity
public class Inventory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
private String unit;

@OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<InventoryVolume> inventoryVolumes = new HashSet<>();


@Builder
public Inventory(Long id, String name, String unit, Set<InventoryVolume> inventoryVolumes) {
this.id = id;
this.name = name;
this.unit = unit;
this.inventoryVolumes = inventoryVolumes != null ? inventoryVolumes : new HashSet<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.skhu.tastyinventory_be.domain.inventory;

import org.springframework.data.jpa.repository.JpaRepository;

public interface InventoryRepository extends JpaRepository<Inventory, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.skhu.tastyinventory_be.domain.inventoryVolume;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventory.Inventory;

import java.util.Date;


@Getter
@NoArgsConstructor
@Entity
public class InventoryVolume {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Temporal(TemporalType.DATE)
private Date weekStart;

private Integer friInventory;
private Integer sunInventory;
private Integer monOrder;
private Integer tueOrder;
private Integer wedOrder;
private Integer thuOrder;
private Integer friOrder;
private Integer satOrder;
private Integer sunOrder;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inventory_id")
private Inventory inventory;

@Builder
public InventoryVolume(Long id, Date weekStart, Integer friInventory, Integer sumInventory, Integer monOrder, Integer tueOrder, Integer wedOrder, Integer thuOrder, Integer friOrder, Integer satOrder, Integer sunOrder, Inventory inventory) {
this.id = id;
this.weekStart = weekStart;
this.friInventory = friInventory;
this.sunInventory = sumInventory;
this.monOrder = monOrder;
this.tueOrder = tueOrder;
this.wedOrder = wedOrder;
this.thuOrder = thuOrder;
this.friOrder = friOrder;
this.satOrder = satOrder;
this.sunOrder = sunOrder;
this.inventory = inventory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.tastyinventory_be.domain.inventoryVolume;

import org.springframework.data.jpa.repository.JpaRepository;

public interface InventoryVolumeRepository extends JpaRepository<InventoryVolume, Long> {
}
32 changes: 32 additions & 0 deletions src/main/java/net/skhu/tastyinventory_be/domain/menu/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.skhu.tastyinventory_be.domain.menu;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.recipe.Recipe;

import java.util.HashSet;
import java.util.Set;

@Getter
@NoArgsConstructor
@Entity
public class Menu {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

@OneToMany(mappedBy = "menu", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Recipe> recipes = new HashSet<>();

@Builder
public Menu(Long id, String name) {
this.id = id;
this.name = name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.tastyinventory_be.domain.menu;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MenuRepository extends JpaRepository<Menu, Long> {
}
36 changes: 36 additions & 0 deletions src/main/java/net/skhu/tastyinventory_be/domain/recipe/Recipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.skhu.tastyinventory_be.domain.recipe;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventory.Inventory;
import net.skhu.tastyinventory_be.domain.menu.Menu;

@Getter
@NoArgsConstructor
@Entity
public class Recipe {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "menu_id")
private Menu menu;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inventory_id")
private Inventory inventory;

private Integer usage; //재료 사용량

@Builder
public Recipe(Long id, Menu menu, Inventory inventory, Integer usage) {
this.id = id;
this.menu = menu;
this.inventory = inventory;
this.usage = usage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.skhu.tastyinventory_be.domain.recipe;

import org.springframework.data.jpa.repository.JpaRepository;

public interface RecipeRepository extends JpaRepository<Recipe, Long> {

}

0 comments on commit f947a38

Please sign in to comment.