From 71c445ca2e5791593326f42b0fec1e7c143c8693 Mon Sep 17 00:00:00 2001 From: jiyeon Date: Thu, 6 Jul 2023 03:24:09 +0900 Subject: [PATCH] feat: Add Entity --- build.gradle | 2 +- .../com/universe/uni/domain/MatchResult.java | 5 ++ .../com/universe/uni/domain/MatchType.java | 5 ++ .../java/com/universe/uni/domain/SnsType.java | 7 +++ .../universe/uni/domain/entity/Couple.java | 40 ++++++++++++++ .../universe/uni/domain/entity/LongMatch.java | 29 ++++++++++ .../com/universe/uni/domain/entity/Match.java | 42 +++++++++++++++ .../uni/domain/entity/MissionCategory.java | 47 ++++++++++++++++ .../uni/domain/entity/MissionContent.java | 35 ++++++++++++ .../uni/domain/entity/RoundHistory.java | 51 ++++++++++++++++++ .../uni/domain/entity/RoundMatch.java | 39 ++++++++++++++ .../uni/domain/entity/RoundMission.java | 49 +++++++++++++++++ .../uni/domain/entity/ShortMatch.java | 20 +++++++ .../com/universe/uni/domain/entity/User.java | 46 ++++++++++++++++ .../uni/domain/entity/UserMatchHistory.java | 53 +++++++++++++++++++ .../uni/domain/entity/WishCoupon.java | 53 +++++++++++++++++++ .../com/universe/uni/UniApplicationTests.java | 6 +-- 17 files changed, 525 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/universe/uni/domain/MatchResult.java create mode 100644 src/main/java/com/universe/uni/domain/MatchType.java create mode 100644 src/main/java/com/universe/uni/domain/SnsType.java create mode 100644 src/main/java/com/universe/uni/domain/entity/Couple.java create mode 100644 src/main/java/com/universe/uni/domain/entity/LongMatch.java create mode 100644 src/main/java/com/universe/uni/domain/entity/Match.java create mode 100644 src/main/java/com/universe/uni/domain/entity/MissionCategory.java create mode 100644 src/main/java/com/universe/uni/domain/entity/MissionContent.java create mode 100644 src/main/java/com/universe/uni/domain/entity/RoundHistory.java create mode 100644 src/main/java/com/universe/uni/domain/entity/RoundMatch.java create mode 100644 src/main/java/com/universe/uni/domain/entity/RoundMission.java create mode 100644 src/main/java/com/universe/uni/domain/entity/ShortMatch.java create mode 100644 src/main/java/com/universe/uni/domain/entity/User.java create mode 100644 src/main/java/com/universe/uni/domain/entity/UserMatchHistory.java create mode 100644 src/main/java/com/universe/uni/domain/entity/WishCoupon.java diff --git a/build.gradle b/build.gradle index 9740469..13278b9 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' - //implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // sentry dependency implementation 'io.sentry:sentry-spring-boot-starter:6.23.0' diff --git a/src/main/java/com/universe/uni/domain/MatchResult.java b/src/main/java/com/universe/uni/domain/MatchResult.java new file mode 100644 index 0000000..4290402 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/MatchResult.java @@ -0,0 +1,5 @@ +package com.universe.uni.domain; + +public enum MatchResult { + WIN, LOSE, DRAW +} diff --git a/src/main/java/com/universe/uni/domain/MatchType.java b/src/main/java/com/universe/uni/domain/MatchType.java new file mode 100644 index 0000000..077fcc2 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/MatchType.java @@ -0,0 +1,5 @@ +package com.universe.uni.domain; + +public enum MatchType { + SHORT, LONG +} diff --git a/src/main/java/com/universe/uni/domain/SnsType.java b/src/main/java/com/universe/uni/domain/SnsType.java new file mode 100644 index 0000000..af94ab6 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/SnsType.java @@ -0,0 +1,7 @@ +package com.universe.uni.domain; + +public enum SnsType { + KAKAO, + GOOGLE, + APPLE; +} diff --git a/src/main/java/com/universe/uni/domain/entity/Couple.java b/src/main/java/com/universe/uni/domain/entity/Couple.java new file mode 100644 index 0000000..e184821 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/Couple.java @@ -0,0 +1,40 @@ +package com.universe.uni.domain.entity; + +import java.time.LocalDate; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.ColumnDefault; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "couple") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class Couple { + + @Id + @Column(name = "couple_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "start_date", nullable = false) + private LocalDate startDate; + + @Column(name = "invite_code", nullable = false) + private String inviteCode; + + @Column(name = "heart_token", nullable = false) + @ColumnDefault("5") + private int heartToken; +} diff --git a/src/main/java/com/universe/uni/domain/entity/LongMatch.java b/src/main/java/com/universe/uni/domain/entity/LongMatch.java new file mode 100644 index 0000000..d8914e4 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/LongMatch.java @@ -0,0 +1,29 @@ +package com.universe.uni.domain.entity; + +import javax.persistence.Column; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.PrimaryKeyJoinColumn; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@DiscriminatorValue("LongMatch") +@PrimaryKeyJoinColumn(name = "match_id") +public class LongMatch extends Match { + + @Column(name = "duration", nullable = false) + private int duration; + + @Column(name = "round", nullable = false) + private int round; + + @Column(name = "rest_of_game", nullable = false) + private int restOfGame; +} diff --git a/src/main/java/com/universe/uni/domain/entity/Match.java b/src/main/java/com/universe/uni/domain/entity/Match.java new file mode 100644 index 0000000..5764f1e --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/Match.java @@ -0,0 +1,42 @@ +package com.universe.uni.domain.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Table(name = "match") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Inheritance(strategy = InheritanceType.JOINED) +@DiscriminatorColumn +public class Match { + + @Id + @Column(name = "match_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "couple_id") + private Long coupleId; + + @Column(name = "enable", nullable = false) + private Boolean enable; + + @Column(name = "finish_at") + private LocalDateTime finishAt; +} diff --git a/src/main/java/com/universe/uni/domain/entity/MissionCategory.java b/src/main/java/com/universe/uni/domain/entity/MissionCategory.java new file mode 100644 index 0000000..48673a8 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/MissionCategory.java @@ -0,0 +1,47 @@ +package com.universe.uni.domain.entity; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "mission_category") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class MissionCategory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_category_id", nullable = false) + private Long id; + + @Column(name = "title", nullable = false) + private String title; + + @Column(name = "description", nullable = false) + private String description; + + @Column(name = "tip", nullable = false) + private String tip; + + @Column(name = "image", nullable = false) + private String image; + + @Column(name = "lever", nullable = false) + private int level; + + @OneToMany(mappedBy = "mission_category_id") + private List missionContentList = new ArrayList<>(); + +} diff --git a/src/main/java/com/universe/uni/domain/entity/MissionContent.java b/src/main/java/com/universe/uni/domain/entity/MissionContent.java new file mode 100644 index 0000000..db692e0 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/MissionContent.java @@ -0,0 +1,35 @@ +package com.universe.uni.domain.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Table(name = "mission_content") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class MissionContent { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_content_id", nullable = false) + private Long id; + + @Column(name = "mission_category_id") + private Long missionCategoryId; + + @Column(name = "content", nullable = false) + private String content; + + @Column(name = "image", nullable = false) + private String image; +} diff --git a/src/main/java/com/universe/uni/domain/entity/RoundHistory.java b/src/main/java/com/universe/uni/domain/entity/RoundHistory.java new file mode 100644 index 0000000..b8469df --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/RoundHistory.java @@ -0,0 +1,51 @@ +package com.universe.uni.domain.entity; + +import static javax.persistence.GenerationType.*; +import static lombok.AccessLevel.*; + +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import com.universe.uni.domain.MatchResult; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "round_history") +@NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor(access = PROTECTED) +public class RoundHistory { + + @Id + @Column(name = "round_history_id") + @GeneratedValue(strategy = IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "round_match_id", nullable = false) + private RoundMatch roundMatch; + + @Column(name = "user_id", nullable = false) + private Long userId; + + @Column(name = "result") + private MatchResult result; + + @OneToMany(mappedBy = "mission_content_id") + private List roundMissionList; + + @Column(name = "user_match_history_id", nullable = false) + private Long userMatchHistoryId; +} diff --git a/src/main/java/com/universe/uni/domain/entity/RoundMatch.java b/src/main/java/com/universe/uni/domain/entity/RoundMatch.java new file mode 100644 index 0000000..86dff09 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/RoundMatch.java @@ -0,0 +1,39 @@ +package com.universe.uni.domain.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "round_match") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class RoundMatch { + + @Id + @Column(name = "round_match_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "match_id", nullable = false) + private Long matchId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_category_id", nullable = false) + private MissionCategory missionCategory; + + @Column(name = "enable", nullable = false) + private Boolean enable; +} diff --git a/src/main/java/com/universe/uni/domain/entity/RoundMission.java b/src/main/java/com/universe/uni/domain/entity/RoundMission.java new file mode 100644 index 0000000..7a6466e --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/RoundMission.java @@ -0,0 +1,49 @@ +package com.universe.uni.domain.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import com.universe.uni.domain.MatchResult; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "round_mission") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class RoundMission { + + @Id + @Column(name = "round_mission_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "round_match_id", nullable = false) + private Long roundMatchId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_content_id", nullable = false) + private MissionContent missionContent; + + @Column(name = "user_id", nullable = false) + private Long userId; + + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + @Column(name = "result") + private MatchResult result; +} diff --git a/src/main/java/com/universe/uni/domain/entity/ShortMatch.java b/src/main/java/com/universe/uni/domain/entity/ShortMatch.java new file mode 100644 index 0000000..0b8d9b2 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/ShortMatch.java @@ -0,0 +1,20 @@ +package com.universe.uni.domain.entity; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.PrimaryKeyJoinColumn; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@DiscriminatorValue("ShortMatch") +@PrimaryKeyJoinColumn(name = "match_id") +public class ShortMatch extends Match { + +} diff --git a/src/main/java/com/universe/uni/domain/entity/User.java b/src/main/java/com/universe/uni/domain/entity/User.java new file mode 100644 index 0000000..306a7bd --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/User.java @@ -0,0 +1,46 @@ +package com.universe.uni.domain.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.universe.uni.domain.SnsType; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "user") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "user_id", nullable = false) + private Long id; + + @Column(name = "nickname") + private String nickname; + + @Column(name = "sns_type", nullable = false) + private SnsType snsType; + + @Column(name = "sns_auth", nullable = false) + private String snsAuthCode; + + @Column(name = "image") + private String image; + + @Column(name = "fcm_token") + private String fcmToken; + + @Column(name = "couple_id") + private Long coupleId; +} diff --git a/src/main/java/com/universe/uni/domain/entity/UserMatchHistory.java b/src/main/java/com/universe/uni/domain/entity/UserMatchHistory.java new file mode 100644 index 0000000..bbe948e --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/UserMatchHistory.java @@ -0,0 +1,53 @@ +package com.universe.uni.domain.entity; + +import static javax.persistence.GenerationType.*; +import static lombok.AccessLevel.*; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import com.universe.uni.domain.MatchResult; +import com.universe.uni.domain.MatchType; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "user_match_history") +@NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class UserMatchHistory { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "user_match_history_id") + private Long id; + + @Column(name = "user_id", nullable = false) + private Long userId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "match_id", nullable = false) + private Match match; + + @Column(name = "result") + private MatchResult result; + + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + @Column(name = "match_type") + private MatchType matchType; + +} diff --git a/src/main/java/com/universe/uni/domain/entity/WishCoupon.java b/src/main/java/com/universe/uni/domain/entity/WishCoupon.java new file mode 100644 index 0000000..3bf3204 --- /dev/null +++ b/src/main/java/com/universe/uni/domain/entity/WishCoupon.java @@ -0,0 +1,53 @@ +package com.universe.uni.domain.entity; + +import static javax.persistence.GenerationType.*; +import static lombok.AccessLevel.*; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.universe.uni.domain.MatchType; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "wish_coupon") +@NoArgsConstructor(access = PROTECTED) +@Getter +public class WishCoupon { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "wish_coupon_id") + private Long id; + + @Column(name = "image") + private String image; + + @Column(name = "content") + private String content; + + @Column(name = "is_visible", nullable = false) + private boolean isVisible; + + @Column(name = "is_used", nullable = false) + private boolean isUsed; + + @Column(name = "used_at") + private LocalDateTime usedAt; + + @Column(name = "user_id", nullable = false) + private Long userId; + + @Column(name = "match_id", nullable = false) + private Long matchId; + + @Column(name = "match_type", nullable = false) + private MatchType matchType; +} diff --git a/src/test/java/com/universe/uni/UniApplicationTests.java b/src/test/java/com/universe/uni/UniApplicationTests.java index 9a73a91..cc1d94d 100644 --- a/src/test/java/com/universe/uni/UniApplicationTests.java +++ b/src/test/java/com/universe/uni/UniApplicationTests.java @@ -6,8 +6,8 @@ @SpringBootTest class UniApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } }