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 new file mode 100644 index 00000000..aa990f65 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/BreadDiaryEventEntity.java @@ -0,0 +1,29 @@ +package com.depromeet.breadmapbackend.domain.event.db; + +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.*; +import javax.validation.constraints.NotNull; + +@Entity +@Getter +@Table(name = "bread_diary_event_check") +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/UserPointEntity.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java new file mode 100644 index 00000000..bbb19c3b --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointEntity.java @@ -0,0 +1,37 @@ +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; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; + +@Entity +@Getter +@Table(name = "user_point") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class UserPointEntity extends BaseEntity { + + @Id + private long userId; + + @OneToOne + @PrimaryKeyJoinColumn(name = "user_id") + @NotNull + 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..025b8596 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/db/UserPointHistoryEntity.java @@ -0,0 +1,54 @@ +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.*; +import javax.validation.constraints.NotNull; + +@Entity +@Table(name = "user_point_history") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@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; + + 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/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/BreadDiaryEvent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEvent.java new file mode 100644 index 00000000..a850085b --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEvent.java @@ -0,0 +1,10 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; + +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/BreadDiaryEventContent.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventContent.java new file mode 100644 index 00000000..0597a087 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventContent.java @@ -0,0 +1,14 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +import lombok.Getter; + +@Getter +public class BreadDiaryEventContent { + private BreadDiaryEventState state = BreadDiaryEventState.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/BreadDiaryEventPK.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventPK.java new file mode 100644 index 00000000..78982655 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventPK.java @@ -0,0 +1,8 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +public record BreadDiaryEventPK(long id) { + + public enum State { + PENDING, ACCEPTED, REJECTED + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.java new file mode 100644 index 00000000..aca8fa7a --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventState.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 BreadDiaryEventState { + PENDING("대기"), ACCEPTED("수락"), REJECTED("거부"); + public final String value; + + @JsonCreator + static public BreadDiaryEventState jsonCreator(String state) { + try { + return BreadDiaryEventState.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/BreadDiaryEventTarget.java b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventTarget.java new file mode 100644 index 00000000..fcc9011c --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/breaddiaryevent/BreadDiaryEventTarget.java @@ -0,0 +1,4 @@ +package com.depromeet.breadmapbackend.domain.event.domain.breaddiaryevent; + +public record BreadDiaryEventTarget(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..c73cace1 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistory.java @@ -0,0 +1,6 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import com.depromeet.breadmapbackend.domain.event.domain.Timestamp; + +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..ffce4b54 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointHistoryContent.java @@ -0,0 +1,7 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +import lombok.Getter; + +@Getter +public record UserPointHistoryContent(int point, int grandTotalPoint, PointHistoryType type, String 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..47bb2622 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/event/domain/point/UserPointPK.java @@ -0,0 +1,4 @@ +package com.depromeet.breadmapbackend.domain.event.domain.point; + +public record UserPointPK(long userId) { +} 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..efc34809 --- /dev/null +++ b/src/main/resources/db/migration/V3__event_point_related_table.sql @@ -0,0 +1,33 @@ +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, + `description` string NOT NULL DEFAULT '', + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +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, + `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` ADD FOREIGN KEY (`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`);