-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: challenge & friendship entity relations
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
core-module/src/main/java/com/foodgo/coremodule/community/domain/Challenge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
36 changes: 36 additions & 0 deletions
36
core-module/src/main/java/com/foodgo/coremodule/community/domain/ChallengeDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
core-module/src/main/java/com/foodgo/coremodule/community/domain/Friendship.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
2 changes: 0 additions & 2 deletions
2
core-module/src/main/java/com/foodgo/coremodule/user/domain/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters