Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/main/java/com/progbe/domain/category/entity/CategoryEntity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.progbe.domain.category.entity;

import com.progbe.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Table(
Expand All @@ -23,49 +19,41 @@
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class CategoryEntity {
public class CategoryEntity extends BaseEntity {

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private CategoryEntity parent;

@Column(nullable = false, unique = true)
private String name;

@Column(columnDefinition = "TEXT")
private String description;

@CreatedDate
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Builder
public CategoryEntity(String name, String description) {
public CategoryEntity(CategoryEntity parent, String name, String description) {
this.parent = parent;
this.name = name;
this.description = description;
}

// 어드민에서 카테고리 관리 고려
public void update(String name, String description) {
public void update(CategoryEntity parent, String name, String description) {
if (parent != null) {
this.parent = parent;
}
if (name != null) {
this.name = name;
}
if (description != null) {
this.description = description;
}
}

public void delete() {
this.deletedAt = LocalDateTime.now();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import com.progbe.domain.category.entity.CategoryEntity;
import com.progbe.domain.user.entity.UserEntity;
import com.progbe.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Table(name = "prompt_drafts")
@Table(
name = "prompt_drafts",
indexes = {
@Index(name = "idx_prompt_drafts_user_id", columnList = "user_id"),
@Index(name = "idx_prompt_drafts_category_id", columnList = "category_id"),
@Index(name = "idx_prompt_drafts_updated_at", columnList = "updated_at")
}
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class PromptDraftEntity {
public class PromptDraftEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -46,10 +49,6 @@ public class PromptDraftEntity {
@Column(name = "tag_ids_json")
private String tagIdsJson;

@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Builder
public PromptDraftEntity(
UserEntity user,
Expand Down
26 changes: 7 additions & 19 deletions src/main/java/com/progbe/domain/prompt/entity/PromptEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import com.progbe.domain.category.entity.CategoryEntity;
import com.progbe.domain.user.entity.UserEntity;
import com.progbe.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Table(
Expand All @@ -24,8 +20,7 @@
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class PromptEntity {
public class PromptEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -46,16 +41,8 @@ public class PromptEntity {
@Column(nullable = false, columnDefinition = "TEXT")
private String content;

@CreatedDate
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;
@OneToOne(mappedBy = "prompt", cascade = CascadeType.ALL, orphanRemoval = true)
private PromptStatusEntity statusEntity;

@Builder
public PromptEntity(UserEntity user, CategoryEntity category, String title, String content) {
Expand All @@ -77,8 +64,9 @@ public void update(CategoryEntity category, String title, String content) {
}
}

public void delete() {
this.deletedAt = LocalDateTime.now();
//프롬프트 생성 시 또는 status 테이블과 연결 시
public void attachStatus(PromptStatusEntity statusEntity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭘 연결한다는거죠...?

this.statusEntity = statusEntity;
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.progbe.domain.prompt.entity;

import com.progbe.domain.user.entity.UserEntity;
import com.progbe.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Table(
Expand All @@ -26,8 +23,7 @@
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class PromptLikeEntity {
public class PromptLikeEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -42,10 +38,6 @@ public class PromptLikeEntity {
@JoinColumn(name = "prompt_id", nullable = false)
private PromptEntity prompt;

@CreatedDate
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;

@Builder
public PromptLikeEntity(UserEntity user, PromptEntity prompt) {
this.user = user;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.progbe.domain.prompt.entity;

import com.progbe.domain.prompt.type.PromptStatus;
import com.progbe.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(
name = "prompt_statuses",
uniqueConstraints = {
@UniqueConstraint(name = "uk_prompt_statuses_prompt_id", columnNames = {"prompt_id"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 의도가 OneToOne 매핑도 걸려있는데 prompt_id가 중복이 안 시켤려고 한건가요?

}
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PromptStatusEntity extends BaseEntity {

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

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "prompt_id", nullable = false, unique = true)
private PromptEntity prompt;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private PromptStatus status;

@Builder
public PromptStatusEntity(PromptEntity prompt, PromptStatus status) {
this.prompt = prompt;
this.status = status;
}

public void changeStatus(PromptStatus status) {
this.status = status;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/progbe/domain/prompt/type/PromptStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.progbe.domain.prompt.type;

// 프롬프트 게시물 공개 상태
public enum PromptStatus {
PUBLIC, // 공개
PRIVATE, // 비공개
DELETED, // 삭제됨
}