diff --git a/backend/src/main/java/com/staccato/config/JpaAuditingConfig.java b/backend/src/main/java/com/staccato/config/JpaAuditingConfig.java new file mode 100644 index 000000000..0c609456f --- /dev/null +++ b/backend/src/main/java/com/staccato/config/JpaAuditingConfig.java @@ -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 { +} diff --git a/backend/src/main/java/com/staccato/config/domain/BaseEntity.java b/backend/src/main/java/com/staccato/config/domain/BaseEntity.java new file mode 100644 index 000000000..c5fce38fb --- /dev/null +++ b/backend/src/main/java/com/staccato/config/domain/BaseEntity.java @@ -0,0 +1,23 @@ +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; +} diff --git a/backend/src/main/java/com/staccato/member/domain/Member.java b/backend/src/main/java/com/staccato/member/domain/Member.java new file mode 100644 index 000000000..8aba694e9 --- /dev/null +++ b/backend/src/main/java/com/staccato/member/domain/Member.java @@ -0,0 +1,27 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE member SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/java/com/staccato/pin/domain/Pin.java b/backend/src/main/java/com/staccato/pin/domain/Pin.java new file mode 100644 index 000000000..c5a9d8e3d --- /dev/null +++ b/backend/src/main/java/com/staccato/pin/domain/Pin.java @@ -0,0 +1,27 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE pin SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/java/com/staccato/travel/domain/Mate.java b/backend/src/main/java/com/staccato/travel/domain/Mate.java new file mode 100644 index 000000000..d69c62b57 --- /dev/null +++ b/backend/src/main/java/com/staccato/travel/domain/Mate.java @@ -0,0 +1,32 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; +import com.staccato.member.domain.Member; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE mate SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/java/com/staccato/travel/domain/Travel.java b/backend/src/main/java/com/staccato/travel/domain/Travel.java new file mode 100644 index 000000000..53f9837c0 --- /dev/null +++ b/backend/src/main/java/com/staccato/travel/domain/Travel.java @@ -0,0 +1,35 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE travel SET is_deleted = true WHERE id = ?") +public class Travel extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(columnDefinition = "TEXT") + 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; +} diff --git a/backend/src/main/java/com/staccato/visit/domain/Visit.java b/backend/src/main/java/com/staccato/visit/domain/Visit.java new file mode 100644 index 000000000..9fb0109a0 --- /dev/null +++ b/backend/src/main/java/com/staccato/visit/domain/Visit.java @@ -0,0 +1,38 @@ +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 org.hibernate.annotations.SQLDelete; + +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) +@SQLDelete(sql = "UPDATE visit SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/java/com/staccato/visit/domain/VisitImage.java b/backend/src/main/java/com/staccato/visit/domain/VisitImage.java new file mode 100644 index 000000000..32d3cf1a4 --- /dev/null +++ b/backend/src/main/java/com/staccato/visit/domain/VisitImage.java @@ -0,0 +1,31 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE visit_image SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/java/com/staccato/visit/domain/VisitLog.java b/backend/src/main/java/com/staccato/visit/domain/VisitLog.java new file mode 100644 index 000000000..e41b1848d --- /dev/null +++ b/backend/src/main/java/com/staccato/visit/domain/VisitLog.java @@ -0,0 +1,35 @@ +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 org.hibernate.annotations.SQLDelete; + +import com.staccato.config.domain.BaseEntity; +import com.staccato.member.domain.Member; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE visit_log SET is_deleted = true WHERE id = ?") +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; +} diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 72c3a73e3..fd1e6425d 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -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