Skip to content

Commit

Permalink
[feat] database 초기 엔티티 구성 및 개발 (#7)
Browse files Browse the repository at this point in the history
* [feat] create enum types for domain

* [feat] create basetimeentity for domain

* [feat] create Store jpa entity and repository

* [feat] create User jpa entity and repository

* [feat] create University jpa entity and repository

* [feat] create Menu jpa entity and repository

* [feat] create Report jpa entity and repository

* [feat] create Heart jpa entity and repository

* [feat] create Favorite jpa entity and repository
  • Loading branch information
Parkjyun authored Jul 4, 2024
1 parent c809173 commit e57fcb1
Show file tree
Hide file tree
Showing 30 changed files with 551 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.hankki.hankkiserver.domain.common;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseCreatedAtEntity {

@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.hankki.hankkiserver.domain.common;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

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

@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;

}
15 changes: 15 additions & 0 deletions src/main/java/org/hankki/hankkiserver/domain/common/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.hankki.hankkiserver.domain.common;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

@Embeddable
public class Point {

@Column(nullable = false)
private double latitude;

@Column(nullable = false)
private double longitude;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hankki.hankkiserver.domain.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaAuditingConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.hankki.hankkiserver.domain.favorite.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.BaseTimeEntity;
import org.hankki.hankkiserver.domain.user.model.User;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Favorite extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "favorite_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Column(nullable = false)
private String name;

private String detail;

@Column(nullable = false)
private String favorite_image_url;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.favorite.repository;

import org.hankki.hankkiserver.domain.favorite.model.Favorite;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FavoriteRepository extends JpaRepository<Favorite, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.hankki.hankkiserver.domain.favoritestore.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.favorite.model.Favorite;
import org.hankki.hankkiserver.domain.store.model.Store;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FavoriteStore {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "favorite_store_id")
private Long id;

@ManyToOne
@JoinColumn(name = "store_id")
private Store store;

@ManyToOne
@JoinColumn(name = "favorite_id")
private Favorite favorite;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.favoritestore.repository;

import org.hankki.hankkiserver.domain.favoritestore.model.FavoriteStore;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FavoriteStoreRepository extends JpaRepository<FavoriteStore, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.hankki.hankkiserver.domain.heart.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.store.model.Store;
import org.hankki.hankkiserver.domain.user.model.User;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Heart {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "heart_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
private Store store;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.heart.repository;

import org.hankki.hankkiserver.domain.heart.model.Heart;
import org.springframework.data.jpa.repository.JpaRepository;

public interface HeartRepository extends JpaRepository<Heart, Long> {
}
30 changes: 30 additions & 0 deletions src/main/java/org/hankki/hankkiserver/domain/menu/model/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.hankki.hankkiserver.domain.menu.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.BaseTimeEntity;
import org.hankki.hankkiserver.domain.store.model.Store;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Menu extends BaseTimeEntity {

@Id
@GeneratedValue
@Column(name = "menu_id")
private Long id;

@ManyToOne
@JoinColumn(name = "store_id")
private Store store;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private int price;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.menu.repository;

import org.hankki.hankkiserver.domain.menu.model.Menu;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MenuRepository extends JpaRepository<Menu, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.hankki.hankkiserver.domain.report.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.BaseCreatedAtEntity;
import org.hankki.hankkiserver.domain.store.model.Store;
import org.hankki.hankkiserver.domain.university.model.University;
import org.hankki.hankkiserver.domain.user.model.User;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Report extends BaseCreatedAtEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "report_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
private Store store;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "university_id")
private University university;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.report.repository;

import org.hankki.hankkiserver.domain.report.model.Report;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ReportRepository extends JpaRepository<Report, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.hankki.hankkiserver.domain.store.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.BaseTimeEntity;
import org.hankki.hankkiserver.domain.common.Point;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Store extends BaseTimeEntity {

@Id
@Column(name = "store_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Embedded
private Point point;

@Column(nullable = false)
private String name;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private StoreCategory category;

@Column(nullable = false)
private int heartCount;

@Column(nullable = false)
private int lowestPrice;

@Column(nullable = false)
private boolean isDeleted;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hankki.hankkiserver.domain.store.model;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum StoreCategory {

KOREAN("한식"),
CHINESE("중식"),
JAPANESE("일식"),
WESTERN("양식"),
CONVENIENCEFOOD("간편식"),
BUNSIK("분식"),
SALAD("샐러드"),
FASTFOOD("패스트푸드"),
ETC("기타");

private final String name;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hankki.hankkiserver.domain.store.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.BaseCreatedAtEntity;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class StoreImage extends BaseCreatedAtEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "store_image_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
private Store store;

@Column(nullable = false)
private String image_url;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.store.repository;

import org.hankki.hankkiserver.domain.store.model.StoreImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StoreImageRepository extends JpaRepository<StoreImage, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.domain.store.repository;

import org.hankki.hankkiserver.domain.store.model.Store;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StoreRepository extends JpaRepository<Store, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.hankki.hankkiserver.domain.university.model;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hankki.hankkiserver.domain.common.Point;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class University {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "university_id")
private Long id;

@Embedded
private Point point;

@Column(nullable = false)
private String name;

}
Loading

0 comments on commit e57fcb1

Please sign in to comment.