From f893c66b617b649513d63db3e0b8df9253803de4 Mon Sep 17 00:00:00 2001 From: zzimnii Date: Tue, 2 Jan 2024 18:32:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20entity=20=EC=83=9D=EC=84=B1=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hackerton/demo/domain/Input.java | 22 ++++++++++++++++ .../com/hackerton/demo/domain/Result.java | 25 +++++++++++++++++++ .../demo/domain/common/BaseEntity.java | 22 ++++++++++++++++ .../demo/domain/mapping/Keyword.java | 24 ++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/com/hackerton/demo/domain/Input.java create mode 100644 src/main/java/com/hackerton/demo/domain/Result.java create mode 100644 src/main/java/com/hackerton/demo/domain/common/BaseEntity.java create mode 100644 src/main/java/com/hackerton/demo/domain/mapping/Keyword.java diff --git a/src/main/java/com/hackerton/demo/domain/Input.java b/src/main/java/com/hackerton/demo/domain/Input.java new file mode 100644 index 0000000..a53c672 --- /dev/null +++ b/src/main/java/com/hackerton/demo/domain/Input.java @@ -0,0 +1,22 @@ +package com.hackerton.demo.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import lombok.*; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +@Entity +@Getter +@DynamicUpdate +@DynamicInsert +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Input { + + @Id + private Long id; + + private String content; +} diff --git a/src/main/java/com/hackerton/demo/domain/Result.java b/src/main/java/com/hackerton/demo/domain/Result.java new file mode 100644 index 0000000..cf27282 --- /dev/null +++ b/src/main/java/com/hackerton/demo/domain/Result.java @@ -0,0 +1,25 @@ +package com.hackerton.demo.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import lombok.*; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + + +@Entity +@Getter +@DynamicUpdate +@DynamicInsert +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Result { + + @Id + private Long id; + + private String content; + + private String keyword; +} diff --git a/src/main/java/com/hackerton/demo/domain/common/BaseEntity.java b/src/main/java/com/hackerton/demo/domain/common/BaseEntity.java new file mode 100644 index 0000000..75a090e --- /dev/null +++ b/src/main/java/com/hackerton/demo/domain/common/BaseEntity.java @@ -0,0 +1,22 @@ +package com.hackerton.demo.domain.common; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +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) +@Getter +public abstract class BaseEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/src/main/java/com/hackerton/demo/domain/mapping/Keyword.java b/src/main/java/com/hackerton/demo/domain/mapping/Keyword.java new file mode 100644 index 0000000..1679de7 --- /dev/null +++ b/src/main/java/com/hackerton/demo/domain/mapping/Keyword.java @@ -0,0 +1,24 @@ +package com.hackerton.demo.domain.mapping; + +import com.hackerton.demo.domain.Result; +import com.hackerton.demo.domain.common.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Keyword extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "result_id") + private Result result; +}