Skip to content

Commit

Permalink
Merge pull request #22 from mjuCapstone/feat/21-Entity-개발
Browse files Browse the repository at this point in the history
feat : 추가 구현 ERD 개발합니다.
  • Loading branch information
hyunw9 authored May 4, 2024
2 parents affa8b7 + b15684c commit fbc0a05
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mju/capstone/CapstoneApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class CapstoneApplication {

public static void main(String[] args) {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/mju/capstone/food/history/entity/History.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mju.capstone.food.history.entity;

import com.mju.capstone.global.baseEntity.BaseTimeEntity;
import com.mju.capstone.member.entity.Member;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@Entity
public class History extends BaseTimeEntity {

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

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

private int tot_kcal;

private int tot_carbohydrate;

private int tot_protein;

private int tot_fat;

public History(Member member, int tot_kcal, int tot_carbohydrate, int tot_protein, int tot_fat) {
this.member = member;
this.tot_kcal = tot_kcal;
this.tot_carbohydrate = tot_carbohydrate;
this.tot_protein = tot_protein;
this.tot_fat = tot_fat;
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/mju/capstone/food/item/entity/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mju.capstone.food.item.entity;

import com.mju.capstone.food.history.entity.History;
import com.mju.capstone.global.baseEntity.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@Getter
public class Item extends BaseTimeEntity {

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

@ManyToOne
@JoinColumn(name = "history_id")
private History history;

private String name;

private int kcal;

private int carbohydrate;

private int protein;

private int fat;

public Item(History history, String name, int kcal, int carbohydrate, int protein, int fat) {
this.history = history;
this.name = name;
this.kcal = kcal;
this.carbohydrate = carbohydrate;
this.protein = protein;
this.fat = fat;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mju.capstone.global.baseEntity;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseTimeEntity {

@CreatedDate
private LocalDateTime localDateTime;

@LastModifiedDate
private LocalDateTime modifiedDate;
}
38 changes: 38 additions & 0 deletions src/main/java/com/mju/capstone/menu/entity/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mju.capstone.menu.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
public class Menu {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String food_id;

private String name;

private int kcal;

private int carbohydrate;

private int protein;

private int fat;

@Builder
public Menu(String name, int kcal, int carbohydrate, int protein, int fat) {
this.name = name;
this.kcal = kcal;
this.carbohydrate = carbohydrate;
this.protein = protein;
this.fat = fat;
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/mju/capstone/preference/entity/Preference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mju.capstone.preference.entity;

import com.mju.capstone.global.baseEntity.BaseTimeEntity;
import com.mju.capstone.member.entity.Member;
import com.mju.capstone.menu.entity.Menu;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
public class Preference extends BaseTimeEntity {

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

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne
@JoinColumn(name = "menu_id")
private Menu menu;

@Builder
public Preference(Member member, Menu menu) {
this.member = member;
this.menu = menu;
}
}

0 comments on commit fbc0a05

Please sign in to comment.