From 8bab330101bd2958ca47d227bc94b7feeef724b8 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 18:49:39 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EA=B4=80=EB=A0=A8=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/db/BreadDiaryEventCheckEntity.java | 26 ++++++++++++++ .../domain/event/db/TimestampEntity.java | 31 ++++++++++++++++ .../domain/event/db/UserPointEntity.java | 35 +++++++++++++++++++ .../event/db/UserPointHistoryEntity.java | 35 +++++++++++++++++++ .../domain/event/domain/Timestamp.java | 11 ++++++ .../breaddiaryevent/BreadDiaryEventCheck.java | 12 +++++++ .../BreadDiaryEventCheckContent.java | 14 ++++++++ .../BreadDiaryEventCheckPK.java | 11 ++++++ .../BreadDiaryEventCheckState.java | 25 +++++++++++++ .../BreadDiaryEventCheckTarget.java | 7 ++++ .../event/domain/point/PointHistoryType.java | 5 +++ .../domain/event/domain/point/UserPoint.java | 18 ++++++++++ .../event/domain/point/UserPointHistory.java | 8 +++++ .../domain/point/UserPointHistoryContent.java | 20 +++++++++++ .../domain/point/UserPointHistoryPK.java | 4 +++ .../event/domain/point/UserPointPK.java | 6 ++++ 16 files changed, 268 insertions(+) create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/Timestamp.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/PointHistoryType.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPoint.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryPK.java create mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java new file mode 100644 index 00000000..db6ab298 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java @@ -0,0 +1,26 @@ +package com.depromeet.breadmapbackend.domain.event.db; + +import com.depromeet.breadmapbackend.domain.breaddiary.BreadDiary; +import com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent.BreadDiaryEventCheckState; +import lombok.Getter; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; + +@Entity +@Getter +@Table(name = "bread_diary_event_check") +class BreadDiaryEventCheckEntity extends TimestampEntity { + @Id + @GeneratedValue + private long id; + @OneToOne + @JoinColumn(name = "diary_id") + @NotNull + private BreadDiary diary; + @NotNull + private String description = ""; + @Enumerated(EnumType.STRING) + @NotNull + private BreadDiaryEventCheckState state = BreadDiaryEventCheckState.PENDING; +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java new file mode 100644 index 00000000..60351bd6 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java @@ -0,0 +1,31 @@ +package com.depromeet.breadmapbackend.domain.event.db; + +import lombok.Getter; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.validation.constraints.NotNull; +import java.time.ZonedDateTime; + +@MappedSuperclass +@Getter +public abstract class TimestampEntity { + @Column(updatable = false) + @NotNull + private ZonedDateTime createdAt; + @NotNull + private ZonedDateTime updatedAt; + + @PrePersist + public void prePersist() { + createdAt = ZonedDateTime.now(); + updatedAt = ZonedDateTime.now(); + } + + @PreUpdate + public void preUpdate() { + updatedAt = ZonedDateTime.now(); + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java new file mode 100644 index 00000000..47cc5da1 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java @@ -0,0 +1,35 @@ +package com.depromeet.breadmapbackend.domain.event.db; + +import com.depromeet.breadmapbackend.domain.user.User; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; + +@Entity +@Getter +@Table(name = "user_point") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +class UserPointEntity extends TimestampEntity { + @Id + @GeneratedValue + private long userId; + + @OneToOne + @PrimaryKeyJoinColumn(name = "user_id") + private User user; + + @NotNull + private int totalPoint = 0; + + UserPointEntity(long userId, User user) { + this.userId = userId; + this.user = user; + } + + void addPoint(int point) { + totalPoint += point; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java new file mode 100644 index 00000000..1f0e3c87 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java @@ -0,0 +1,35 @@ +package com.depromeet.breadmapbackend.domain.event.db; + +import com.depromeet.breadmapbackend.domain.event.domain.point.PointHistoryType; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; + +@Entity +@Table(name = "user_point_history") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +class UserPointHistoryEntity extends TimestampEntity { + @Id @GeneratedValue + private long id; + @NotNull + private long userId; + @NotNull + private int point; + @NotNull + private int grandTotalPoint; + @Enumerated(EnumType.STRING) + @NotNull + private PointHistoryType type = PointHistoryType.ETC; + @NotNull + private String description = ""; + + UserPointHistoryEntity(long id, long userId, int point, int grandTotalPoint, String description) { + this.id = id; + this.userId = userId; + this.point = point; + this.grandTotalPoint = grandTotalPoint; + this.description = description; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/Timestamp.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/Timestamp.java new file mode 100644 index 00000000..292bc6fb --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/Timestamp.java @@ -0,0 +1,11 @@ +package com.depromeet.breadmapbackend.domain.event.domain; + +import lombok.Getter; + +import java.time.ZonedDateTime; + +@Getter +public class Timestamp { + private ZonedDateTime createdAt; + private ZonedDateTime updatedAt; +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java new file mode 100644 index 00000000..13dbbd83 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java @@ -0,0 +1,12 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; +import lombok.Getter; + +@Getter +public record BreadDiaryEventCheck(BreadDiaryEventCheckPK pk, BreadDiaryEventCheckTarget diary, + BreadDiaryEventCheckContent content, Timestamp timestamps) { + public String getHistoryDescription() { + return "빵일기 "+ content.getState() +" 상태 진입으로 "+ content.getPoint()+"포인트 " + content.getIncreaseKeyword()+"되었습니다"; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java new file mode 100644 index 00000000..4bbea2f6 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java @@ -0,0 +1,14 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import lombok.Getter; + +@Getter +public class BreadDiaryEventCheckContent { + private BreadDiaryEventCheckState state = BreadDiaryEventCheckState.PENDING; + private String description = ""; + private int point = 500; + + public String getIncreaseKeyword() { + return point < 0 ? "차감" : "지급"; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java new file mode 100644 index 00000000..ab933735 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java @@ -0,0 +1,11 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import lombok.Getter; + +@Getter +public record BreadDiaryEventCheckPK(long id) { + + public enum State { + PENDING, ACCEPTED, REJECTED + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java new file mode 100644 index 00000000..343c7489 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java @@ -0,0 +1,25 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import lombok.AllArgsConstructor; +import org.codehaus.jackson.annotate.JsonCreator; +import org.codehaus.jackson.annotate.JsonValue; + +@AllArgsConstructor +public enum BreadDiaryEventCheckState { + PENDING("대기"), ACCEPTED("수락"), REJECTED("거부"); + public final String value; + + @JsonCreator + static public BreadDiaryEventCheckState jsonCreator(String state) { + try { + return BreadDiaryEventCheckState.valueOf(state); + } catch (Exception e) { + return null; + } + } + + @JsonValue + public String value() { + return value; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java new file mode 100644 index 00000000..4f513c01 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java @@ -0,0 +1,7 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import lombok.Getter; + +@Getter +public record BreadDiaryEventCheckTarget(long breadDiaryId) { +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/PointHistoryType.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/PointHistoryType.java new file mode 100644 index 00000000..27f2a5b0 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/PointHistoryType.java @@ -0,0 +1,5 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +public enum PointHistoryType { + BREAD_DIARY, ETC +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPoint.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPoint.java new file mode 100644 index 00000000..3c10c7fc --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPoint.java @@ -0,0 +1,18 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import lombok.Getter; + +@Getter +public class UserPoint { + private final UserPointPK pk; + private int totalPoint; + + public void addPoint(int point) { + totalPoint += point; + } + + public UserPoint(UserPointPK pk, int totalPoint) { + this.pk = pk; + this.totalPoint = totalPoint; + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java new file mode 100644 index 00000000..71271db6 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java @@ -0,0 +1,8 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; +import lombok.Getter; + +@Getter +public record UserPointHistory(UserPointHistoryPK pk, UserPointHistoryContent content, Timestamp timestamp) { +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java new file mode 100644 index 00000000..cee5bd07 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java @@ -0,0 +1,20 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import lombok.Getter; + +@Getter +public class UserPointHistoryContent { + private final int point; + private final int grandTotalPoint; + private final PointHistoryType type; + private final String description; + + public UserPointHistoryContent(int point, int grandTotalPoint, PointHistoryType type, String description) { + this.point = point; + this.grandTotalPoint = grandTotalPoint; + this.type = type; + this.description = description; + } + + +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryPK.java new file mode 100644 index 00000000..3bfc3c62 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryPK.java @@ -0,0 +1,4 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +public record UserPointHistoryPK(long id, long userId) { +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java new file mode 100644 index 00000000..62ba5528 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java @@ -0,0 +1,6 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import lombok.Getter; + +public record UserPointPK(long userId) { +} From 0be40c447398a0d1aab1ce756a434e9d7a712f31 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 19:04:40 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20SQL=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V3__event_point_related_table.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/resources/db/migration/V3__event_point_related_table.sql diff --git a/src/main/resources/db/migration/V3__event_point_related_table.sql b/src/main/resources/db/migration/V3__event_point_related_table.sql new file mode 100644 index 00000000..e2822f07 --- /dev/null +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -0,0 +1,33 @@ +CREATE TABLE `bread_diary_event_check` ( + `id` bigint PRIMARY KEY, + `bread_diary_id` bigint NOT NULL, + `state` ENUM ('PENDING', 'ACCEPTED', 'REJECTED') NOT NULL DEFAULT 'PENDING', + `point` int NOT NULL DEFAULT 0, + `description` string NOT NULL DEFAULT '', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE `point_history` ( + `id` bigint PRIMARY KEY, + `user_id` bigint NOT NULL, + `point` int NOT NULL DEFAULT 0, + `grand_total_point` int NOT NULL DEFAULT 0, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `type` ENUM ('BREAD_DIARY', 'ETC') NOT NULL DEFAULT 'ETC', + `description` string NOT NULL DEFAULT '' +); + +CREATE TABLE `user_point` ( + `user_id` bigint PRIMARY KEY, + `total_point` int NOT NULL DEFAULT 0, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE `bread_diary_event_check` ADD FOREIGN KEY (`bread_diary_id`) REFERENCES `bread_diary` (`id`); + +ALTER TABLE `point_history` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); + +ALTER TABLE `user_point` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); From c9c3f5880c6c09d512b8127861e861080299edc6 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 19:15:07 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20=EB=A0=88=EC=BD=94=EB=93=9C=20Getter?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/domain/breaddiaryevent/BreadDiaryEventCheck.java | 2 -- .../event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java | 3 --- .../domain/breaddiaryevent/BreadDiaryEventCheckTarget.java | 3 --- .../domain/event/domain/point/UserPointHistory.java | 2 -- .../breadmapbackend/domain/event/domain/point/UserPointPK.java | 2 -- 5 files changed, 12 deletions(-) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java index 13dbbd83..9a15a704 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java @@ -1,9 +1,7 @@ package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; -import lombok.Getter; -@Getter public record BreadDiaryEventCheck(BreadDiaryEventCheckPK pk, BreadDiaryEventCheckTarget diary, BreadDiaryEventCheckContent content, Timestamp timestamps) { public String getHistoryDescription() { diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java index ab933735..332026ad 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java @@ -1,8 +1,5 @@ package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; -import lombok.Getter; - -@Getter public record BreadDiaryEventCheckPK(long id) { public enum State { diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java index 4f513c01..aa48d4c0 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java @@ -1,7 +1,4 @@ package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; -import lombok.Getter; - -@Getter public record BreadDiaryEventCheckTarget(long breadDiaryId) { } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java index 71271db6..c73cace1 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java @@ -1,8 +1,6 @@ package com.depromeet.breadmapbackend.domain.event.domain.point; import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; -import lombok.Getter; -@Getter public record UserPointHistory(UserPointHistoryPK pk, UserPointHistoryContent content, Timestamp timestamp) { } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java index 62ba5528..47bb2622 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java @@ -1,6 +1,4 @@ package com.depromeet.breadmapbackend.domain.event.domain.point; -import lombok.Getter; - public record UserPointPK(long userId) { } From d4c8d33c65fbb5afbda774ce032c354dbafa6643 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 19:27:01 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=EC=9D=BC=EB=8C=80=EC=9D=BC=20?= =?UTF-8?q?=EC=99=B8=EB=9E=98=ED=82=A4=20=EC=A0=9C=EC=95=BD=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/db/BreadDiaryEventCheckEntity.java | 5 ++--- .../breadmapbackend/domain/event/db/UserPointEntity.java | 2 +- .../db/migration/V3__event_point_related_table.sql | 7 +++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java index db6ab298..bdc0eb38 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java @@ -12,10 +12,9 @@ @Table(name = "bread_diary_event_check") class BreadDiaryEventCheckEntity extends TimestampEntity { @Id - @GeneratedValue - private long id; + private long diaryId; @OneToOne - @JoinColumn(name = "diary_id") + @PrimaryKeyJoinColumn(name = "diary_id") @NotNull private BreadDiary diary; @NotNull diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java index 47cc5da1..55921150 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java @@ -14,11 +14,11 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) class UserPointEntity extends TimestampEntity { @Id - @GeneratedValue private long userId; @OneToOne @PrimaryKeyJoinColumn(name = "user_id") + @NotNull private User user; @NotNull diff --git a/src/main/resources/db/migration/V3__event_point_related_table.sql b/src/main/resources/db/migration/V3__event_point_related_table.sql index e2822f07..e599a7d6 100644 --- a/src/main/resources/db/migration/V3__event_point_related_table.sql +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -1,6 +1,5 @@ CREATE TABLE `bread_diary_event_check` ( - `id` bigint PRIMARY KEY, - `bread_diary_id` bigint NOT NULL, + `diary_id` bigint PRIMARY KEY , `state` ENUM ('PENDING', 'ACCEPTED', 'REJECTED') NOT NULL DEFAULT 'PENDING', `point` int NOT NULL DEFAULT 0, `description` string NOT NULL DEFAULT '', @@ -9,7 +8,7 @@ CREATE TABLE `bread_diary_event_check` ( ); CREATE TABLE `point_history` ( - `id` bigint PRIMARY KEY, + `id` bigint auto_increment PRIMARY KEY, `user_id` bigint NOT NULL, `point` int NOT NULL DEFAULT 0, `grand_total_point` int NOT NULL DEFAULT 0, @@ -26,7 +25,7 @@ CREATE TABLE `user_point` ( `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ); -ALTER TABLE `bread_diary_event_check` ADD FOREIGN KEY (`bread_diary_id`) REFERENCES `bread_diary` (`id`); +ALTER TABLE `bread_diary_event_check` ADD FOREIGN KEY (`diary_id`) REFERENCES `bread_diary` (`id`); ALTER TABLE `point_history` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); From 84eb7be280a77e284ca0390bf3d1e7d5de46d081 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 19:38:29 +0900 Subject: [PATCH 5/7] =?UTF-8?q?typo:=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...iaryEventCheckEntity.java => BreadDiaryEventEntity.java} | 6 +++--- .../{BreadDiaryEventCheck.java => BreadDiaryEvent.java} | 4 ++-- ...ryEventCheckContent.java => BreadDiaryEventContent.java} | 4 ++-- .../{BreadDiaryEventCheckPK.java => BreadDiaryEventPK.java} | 2 +- ...dDiaryEventCheckState.java => BreadDiaryEventState.java} | 6 +++--- ...iaryEventCheckTarget.java => BreadDiaryEventTarget.java} | 2 +- .../db/migration/V3__event_point_related_table.sql | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/com/depromeet/breadmapbackend/domain/event/db/{BreadDiaryEventCheckEntity.java => BreadDiaryEventEntity.java} (76%) rename src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/{BreadDiaryEventCheck.java => BreadDiaryEvent.java} (64%) rename src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/{BreadDiaryEventCheckContent.java => BreadDiaryEventContent.java} (68%) rename src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/{BreadDiaryEventCheckPK.java => BreadDiaryEventPK.java} (75%) rename src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/{BreadDiaryEventCheckState.java => BreadDiaryEventState.java} (74%) rename src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/{BreadDiaryEventCheckTarget.java => BreadDiaryEventTarget.java} (55%) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java similarity index 76% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java index bdc0eb38..e4ebacc4 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventCheckEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java @@ -1,7 +1,7 @@ package com.depromeet.breadmapbackend.domain.event.db; import com.depromeet.breadmapbackend.domain.breaddiary.BreadDiary; -import com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent.BreadDiaryEventCheckState; +import com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent.BreadDiaryEventState; import lombok.Getter; import javax.persistence.*; @@ -10,7 +10,7 @@ @Entity @Getter @Table(name = "bread_diary_event_check") -class BreadDiaryEventCheckEntity extends TimestampEntity { +class BreadDiaryEventEntity extends TimestampEntity { @Id private long diaryId; @OneToOne @@ -21,5 +21,5 @@ class BreadDiaryEventCheckEntity extends TimestampEntity { private String description = ""; @Enumerated(EnumType.STRING) @NotNull - private BreadDiaryEventCheckState state = BreadDiaryEventCheckState.PENDING; + private BreadDiaryEventState state = BreadDiaryEventState.PENDING; } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEvent.java similarity index 64% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEvent.java index 9a15a704..a850085b 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheck.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEvent.java @@ -2,8 +2,8 @@ import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; -public record BreadDiaryEventCheck(BreadDiaryEventCheckPK pk, BreadDiaryEventCheckTarget diary, - BreadDiaryEventCheckContent content, Timestamp timestamps) { +public record BreadDiaryEvent(BreadDiaryEventPK pk, BreadDiaryEventTarget diary, + BreadDiaryEventContent content, Timestamp timestamps) { public String getHistoryDescription() { return "빵일기 "+ content.getState() +" 상태 진입으로 "+ content.getPoint()+"포인트 " + content.getIncreaseKeyword()+"되었습니다"; } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventContent.java similarity index 68% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventContent.java index 4bbea2f6..0597a087 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckContent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventContent.java @@ -3,8 +3,8 @@ import lombok.Getter; @Getter -public class BreadDiaryEventCheckContent { - private BreadDiaryEventCheckState state = BreadDiaryEventCheckState.PENDING; +public class BreadDiaryEventContent { + private BreadDiaryEventState state = BreadDiaryEventState.PENDING; private String description = ""; private int point = 500; diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventPK.java similarity index 75% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventPK.java index 332026ad..78982655 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckPK.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventPK.java @@ -1,6 +1,6 @@ package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; -public record BreadDiaryEventCheckPK(long id) { +public record BreadDiaryEventPK(long id) { public enum State { PENDING, ACCEPTED, REJECTED diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.java similarity index 74% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.java index 343c7489..aca8fa7a 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckState.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.java @@ -5,14 +5,14 @@ import org.codehaus.jackson.annotate.JsonValue; @AllArgsConstructor -public enum BreadDiaryEventCheckState { +public enum BreadDiaryEventState { PENDING("대기"), ACCEPTED("수락"), REJECTED("거부"); public final String value; @JsonCreator - static public BreadDiaryEventCheckState jsonCreator(String state) { + static public BreadDiaryEventState jsonCreator(String state) { try { - return BreadDiaryEventCheckState.valueOf(state); + return BreadDiaryEventState.valueOf(state); } catch (Exception e) { return null; } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventTarget.java similarity index 55% rename from src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java rename to src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventTarget.java index aa48d4c0..fcc9011c 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventCheckTarget.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventTarget.java @@ -1,4 +1,4 @@ package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; -public record BreadDiaryEventCheckTarget(long breadDiaryId) { +public record BreadDiaryEventTarget(long breadDiaryId) { } diff --git a/src/main/resources/db/migration/V3__event_point_related_table.sql b/src/main/resources/db/migration/V3__event_point_related_table.sql index e599a7d6..e05cf14c 100644 --- a/src/main/resources/db/migration/V3__event_point_related_table.sql +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -1,4 +1,4 @@ -CREATE TABLE `bread_diary_event_check` ( +CREATE TABLE `bread_diary_event` ( `diary_id` bigint PRIMARY KEY , `state` ENUM ('PENDING', 'ACCEPTED', 'REJECTED') NOT NULL DEFAULT 'PENDING', `point` int NOT NULL DEFAULT 0, @@ -25,7 +25,7 @@ CREATE TABLE `user_point` ( `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ); -ALTER TABLE `bread_diary_event_check` ADD FOREIGN KEY (`diary_id`) REFERENCES `bread_diary` (`id`); +ALTER TABLE `bread_diary_event` ADD FOREIGN KEY (`diary_id`) REFERENCES `bread_diary` (`id`); ALTER TABLE `point_history` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); From ca5f8ef5871f4086c84f113255a6d173e47e7d93 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Thu, 18 Apr 2024 19:43:13 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=97=90=20targe?= =?UTF-8?q?t=20id=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/db/UserPointHistoryEntity.java | 11 ++++++++++- .../db/migration/V3__event_point_related_table.sql | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java index 1f0e3c87..357bf9ef 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java @@ -14,22 +14,31 @@ class UserPointHistoryEntity extends TimestampEntity { @Id @GeneratedValue private long id; @NotNull + @Column(updatable = false) private long userId; @NotNull + @Column(updatable = false) private int point; @NotNull + @Column(updatable = false) private int grandTotalPoint; @Enumerated(EnumType.STRING) @NotNull + @Column(updatable = false) private PointHistoryType type = PointHistoryType.ETC; @NotNull + @Column(updatable = false) private String description = ""; + @Column(updatable = false) + private Long targetId; - UserPointHistoryEntity(long id, long userId, int point, int grandTotalPoint, String description) { + UserPointHistoryEntity(long id, long userId, int point, int grandTotalPoint, PointHistoryType type, String description, Long targetId) { this.id = id; this.userId = userId; this.point = point; this.grandTotalPoint = grandTotalPoint; + this.type = type; this.description = description; + this.targetId = targetId; } } diff --git a/src/main/resources/db/migration/V3__event_point_related_table.sql b/src/main/resources/db/migration/V3__event_point_related_table.sql index e05cf14c..da5a9789 100644 --- a/src/main/resources/db/migration/V3__event_point_related_table.sql +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -10,6 +10,7 @@ CREATE TABLE `bread_diary_event` ( CREATE TABLE `point_history` ( `id` bigint auto_increment PRIMARY KEY, `user_id` bigint NOT NULL, + `target_id` bigint, `point` int NOT NULL DEFAULT 0, `grand_total_point` int NOT NULL DEFAULT 0, `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, From c64258e1dab97b7edbde4e2ee964574b0159921b Mon Sep 17 00:00:00 2001 From: facewise Date: Tue, 7 May 2024 21:02:16 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/db/BreadDiaryEventEntity.java | 6 +++- .../domain/event/db/TimestampEntity.java | 31 ------------------- .../domain/event/db/UserPointEntity.java | 4 ++- .../event/db/UserPointHistoryEntity.java | 12 ++++++- .../domain/point/UserPointHistoryContent.java | 15 +-------- .../V3__event_point_related_table.sql | 4 +-- 6 files changed, 22 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java index e4ebacc4..aa990f65 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java @@ -2,6 +2,7 @@ import com.depromeet.breadmapbackend.domain.breaddiary.BreadDiary; import com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent.BreadDiaryEventState; +import com.depromeet.breadmapbackend.global.BaseEntity; import lombok.Getter; import javax.persistence.*; @@ -10,15 +11,18 @@ @Entity @Getter @Table(name = "bread_diary_event_check") -class BreadDiaryEventEntity extends TimestampEntity { +public class BreadDiaryEventEntity extends BaseEntity { @Id private long diaryId; + @OneToOne @PrimaryKeyJoinColumn(name = "diary_id") @NotNull private BreadDiary diary; + @NotNull private String description = ""; + @Enumerated(EnumType.STRING) @NotNull private BreadDiaryEventState state = BreadDiaryEventState.PENDING; diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java deleted file mode 100644 index 60351bd6..00000000 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/TimestampEntity.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.depromeet.breadmapbackend.domain.event.db; - -import lombok.Getter; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; -import javax.persistence.PrePersist; -import javax.persistence.PreUpdate; -import javax.validation.constraints.NotNull; -import java.time.ZonedDateTime; - -@MappedSuperclass -@Getter -public abstract class TimestampEntity { - @Column(updatable = false) - @NotNull - private ZonedDateTime createdAt; - @NotNull - private ZonedDateTime updatedAt; - - @PrePersist - public void prePersist() { - createdAt = ZonedDateTime.now(); - updatedAt = ZonedDateTime.now(); - } - - @PreUpdate - public void preUpdate() { - updatedAt = ZonedDateTime.now(); - } -} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java index 55921150..bbb19c3b 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java @@ -1,6 +1,7 @@ package com.depromeet.breadmapbackend.domain.event.db; import com.depromeet.breadmapbackend.domain.user.User; +import com.depromeet.breadmapbackend.global.BaseEntity; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,7 +13,8 @@ @Getter @Table(name = "user_point") @NoArgsConstructor(access = AccessLevel.PROTECTED) -class UserPointEntity extends TimestampEntity { +public class UserPointEntity extends BaseEntity { + @Id private long userId; diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java index 357bf9ef..025b8596 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java @@ -1,7 +1,9 @@ package com.depromeet.breadmapbackend.domain.event.db; import com.depromeet.breadmapbackend.domain.event.domain.point.PointHistoryType; +import com.depromeet.breadmapbackend.global.BaseEntity; import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; @@ -10,25 +12,33 @@ @Entity @Table(name = "user_point_history") @NoArgsConstructor(access = AccessLevel.PROTECTED) -class UserPointHistoryEntity extends TimestampEntity { +@Getter +public class UserPointHistoryEntity extends BaseEntity { + @Id @GeneratedValue private long id; + @NotNull @Column(updatable = false) private long userId; + @NotNull @Column(updatable = false) private int point; + @NotNull @Column(updatable = false) private int grandTotalPoint; + @Enumerated(EnumType.STRING) @NotNull @Column(updatable = false) private PointHistoryType type = PointHistoryType.ETC; + @NotNull @Column(updatable = false) private String description = ""; + @Column(updatable = false) private Long targetId; diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java index cee5bd07..ffce4b54 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java @@ -3,18 +3,5 @@ import lombok.Getter; @Getter -public class UserPointHistoryContent { - private final int point; - private final int grandTotalPoint; - private final PointHistoryType type; - private final String description; - - public UserPointHistoryContent(int point, int grandTotalPoint, PointHistoryType type, String description) { - this.point = point; - this.grandTotalPoint = grandTotalPoint; - this.type = type; - this.description = description; - } - - +public record UserPointHistoryContent(int point, int grandTotalPoint, PointHistoryType type, String description) { } diff --git a/src/main/resources/db/migration/V3__event_point_related_table.sql b/src/main/resources/db/migration/V3__event_point_related_table.sql index da5a9789..efc34809 100644 --- a/src/main/resources/db/migration/V3__event_point_related_table.sql +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -3,8 +3,8 @@ CREATE TABLE `bread_diary_event` ( `state` ENUM ('PENDING', 'ACCEPTED', 'REJECTED') NOT NULL DEFAULT 'PENDING', `point` int NOT NULL DEFAULT 0, `description` string NOT NULL DEFAULT '', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE `point_history` (