-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Entity 구성 #2 #17
The head ref may contain hidden characters: "feature/#2-Entity\uAD6C\uC131"
Changes from 9 commits
6f79022
c5b9f5c
4665ea4
bfd1f65
3e6ea6e
899754d
3b64557
6a10939
30fb168
8254200
9257741
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.staccato.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,31 @@ | ||
package com.staccato.config.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
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 lombok.Getter; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
public abstract class BaseEntity { | ||
@CreatedDate | ||
private LocalDateTime createdDateTIme; | ||
@LastModifiedDate | ||
private LocalDateTime modifiedDateTime; | ||
private Boolean isDeleted = false; | ||
|
||
public void delete() { | ||
isDeleted = true; | ||
} | ||
|
||
public void restore() { | ||
isDeleted = false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.staccato.member.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "member") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테이블명은 default로 entity의 이름을 사용함에도 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 명시적으로 해당 테이블의 이름을 확인하기 위해 붙였놓았었는데 현재는 논리적 이름과 물리적 이름이 같기에 삭제하였습니다. |
||
public class Member extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(nullable = false, unique = true) | ||
private String nickname; | ||
@Column(columnDefinition = "TEXT") | ||
private String imageUrl; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.staccato.pin.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "pin") | ||
public class Pin extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(nullable = false) | ||
private String place; | ||
@Column(nullable = false) | ||
private String address; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.staccato.travel.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
import com.staccato.member.domain.Member; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "mate") | ||
public class Mate extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "travel_id", nullable = false) | ||
private Travel travel; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.staccato.travel.domain; | ||
|
||
import java.time.LocalDate; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "travel") | ||
public class Travel extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(columnDefinition = "TEXT") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안써봐서 잘 모르긴 하는데, 찾아보니까 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
private String thumbnailUrl; | ||
@Column(nullable = false, length = 50) | ||
private String title; | ||
@Column(columnDefinition = "TEXT") | ||
private String description; | ||
@Column(nullable = false) | ||
private LocalDate startAt; | ||
@Column(nullable = false) | ||
private LocalDate endAt; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.staccato.visit.domain; | ||
|
||
import java.time.LocalDate; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
import com.staccato.pin.domain.Pin; | ||
import com.staccato.travel.domain.Travel; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "visit") | ||
public class Visit extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(nullable = false) | ||
private LocalDate visitedAt; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "pin_id", nullable = false) | ||
private Pin pin; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "travel_id", nullable = false) | ||
private Travel travel; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.staccato.visit.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "visit_image") | ||
public class VisitImage extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(columnDefinition = "TEXT") | ||
private String imageUrl; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "visit_id", nullable = false) | ||
private Visit visit; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.staccato.visit.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import com.staccato.config.domain.BaseEntity; | ||
import com.staccato.member.domain.Member; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "visit_log") | ||
public class VisitLog extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "visit_id", nullable = false) | ||
private Visit visit; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
spring: | ||
application: | ||
name: staccato | ||
sql: | ||
init: | ||
mode: always | ||
h2: | ||
console: | ||
enabled: true | ||
datasource: | ||
url: jdbc:h2:mem:staccato | ||
jpa: | ||
show-sql: true | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
hibernate: | ||
ddl-auto: create | ||
defer-datasource-initialization: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setter를 사용한 삭제가 아닌
@SQLDelete
를 사용하는 방법도 있을 것 같네요!참고: https://velog.io/@jsb100800/Spring-boot-JPA-Soft-Delete-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0