Skip to content

Commit

Permalink
feat: challenge & friendship entity relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 12, 2024
1 parent db719aa commit 97524f5
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
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;
}
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;
}

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;
}
}

Original file line number Diff line number Diff line change
@@ -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.*;

Expand Down

0 comments on commit 97524f5

Please sign in to comment.