From 97524f5d54e24f35f46f84df71fb58f5ef1f43f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Tue, 13 Aug 2024 01:47:06 +0900 Subject: [PATCH] feat: challenge & friendship entity relations --- .../community/domain/Challenge.java | 25 +++++++++++ .../community/domain/ChallengeDetail.java | 36 +++++++++++++++ .../community/domain/Friendship.java | 44 +++++++++++++++++++ .../foodgo/coremodule/user/domain/User.java | 2 - 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 core-module/src/main/java/com/foodgo/coremodule/community/domain/Challenge.java create mode 100644 core-module/src/main/java/com/foodgo/coremodule/community/domain/ChallengeDetail.java create mode 100644 core-module/src/main/java/com/foodgo/coremodule/community/domain/Friendship.java diff --git a/core-module/src/main/java/com/foodgo/coremodule/community/domain/Challenge.java b/core-module/src/main/java/com/foodgo/coremodule/community/domain/Challenge.java new file mode 100644 index 0000000..95a4140 --- /dev/null +++ b/core-module/src/main/java/com/foodgo/coremodule/community/domain/Challenge.java @@ -0,0 +1,25 @@ +package com.foodgo.coremodule.community.domain; + +import com.foodgo.commonmodule.common.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Getter +@Entity +@Table(name = "challenges") +public class Challenge extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "challenge_id") + private Long id; + + @Column(name = "challenge_name", nullable = false) + private String name; + + @Column(name = "challenge_description") + private String description; +} diff --git a/core-module/src/main/java/com/foodgo/coremodule/community/domain/ChallengeDetail.java b/core-module/src/main/java/com/foodgo/coremodule/community/domain/ChallengeDetail.java new file mode 100644 index 0000000..8bcbddc --- /dev/null +++ b/core-module/src/main/java/com/foodgo/coremodule/community/domain/ChallengeDetail.java @@ -0,0 +1,36 @@ +package com.foodgo.coremodule.community.domain; + +import com.foodgo.commonmodule.common.BaseEntity; +import com.foodgo.coremodule.user.domain.User; +import jakarta.persistence.*; +import lombok.*; + +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Getter +@Entity +@Table(name = "challenge_deail") +public class ChallengeDetail extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "challenge_detail_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "challenge_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Challenge challenge; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private User user; + + @Column(name = "target_value", nullable = false) + private Integer targetValue; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "friendship_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Friendship friendship; +} + diff --git a/core-module/src/main/java/com/foodgo/coremodule/community/domain/Friendship.java b/core-module/src/main/java/com/foodgo/coremodule/community/domain/Friendship.java new file mode 100644 index 0000000..9ca7227 --- /dev/null +++ b/core-module/src/main/java/com/foodgo/coremodule/community/domain/Friendship.java @@ -0,0 +1,44 @@ +package com.foodgo.coremodule.community.domain; + +import com.foodgo.commonmodule.common.BaseEntity; +import com.foodgo.coremodule.user.domain.User; +import jakarta.persistence.*; +import lombok.*; + +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Entity +@Table(name = "friendship") +public class Friendship extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "friendship_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "user_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private User user; + + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "friend_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private User friend; + + @Column(name = "is_mutual", nullable = false) + private Boolean isMutual; + + public static Friendship createFriendship(User user, User friend) { + return Friendship.builder() + .user(user) + .friend(friend) + .isMutual(false) + .build(); + } + + public void markAsMutual() { + this.isMutual = true; + } +} + diff --git a/core-module/src/main/java/com/foodgo/coremodule/user/domain/User.java b/core-module/src/main/java/com/foodgo/coremodule/user/domain/User.java index f541f19..8d40bfb 100644 --- a/core-module/src/main/java/com/foodgo/coremodule/user/domain/User.java +++ b/core-module/src/main/java/com/foodgo/coremodule/user/domain/User.java @@ -1,12 +1,10 @@ package com.foodgo.coremodule.user.domain; -import com.fasterxml.jackson.annotation.JsonProperty; import com.foodgo.commonmodule.common.BaseEntity; import com.foodgo.coremodule.user.enums.DiseaseType; import com.foodgo.coremodule.user.enums.RoleType; import com.foodgo.coremodule.user.enums.UsageType; import com.foodgo.coremodule.user.enums.UserStatus; - import jakarta.persistence.*; import lombok.*;