-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] ProfileCard와 ProfileCardLike 엔티티 구현
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/io/oeid/mogakgo/domain/profile/domain/entity/ProfileCard.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,49 @@ | ||
package io.oeid.mogakgo.domain.profile.domain.entity; | ||
|
||
import io.oeid.mogakgo.domain.user.domain.User; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "profile_card_tb") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ProfileCard { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "profile_card_id") | ||
private Long id; | ||
|
||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "user_id", updatable = false) | ||
private User user; | ||
|
||
@Column(name = "total_like_amount", nullable = false) | ||
private Long totalLikeAmount; | ||
|
||
@Builder | ||
private ProfileCard(User user) { | ||
this.user = user; | ||
this.totalLikeAmount = 0L; | ||
} | ||
|
||
public static ProfileCard from(User user) { | ||
return ProfileCard.builder() | ||
.user(user) | ||
.build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/io/oeid/mogakgo/domain/profile/domain/entity/ProfileCardLike.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,60 @@ | ||
package io.oeid.mogakgo.domain.profile.domain.entity; | ||
|
||
import io.oeid.mogakgo.domain.user.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "profile_card_like_tb") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class ProfileCardLike { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "profile_card_like_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "sender_id", updatable = false) | ||
private User sender; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "receiver_id", updatable = false) | ||
private User receiver; | ||
|
||
@CreatedDate | ||
@Column(name = "created_at") | ||
private LocalDateTime createdAt; | ||
|
||
@Builder | ||
private ProfileCardLike(User sender, User receiver) { | ||
this.sender = sender; | ||
this.receiver = receiver; | ||
} | ||
|
||
public static ProfileCardLike of(User sender, User receiver) { | ||
return ProfileCardLike.builder() | ||
.sender(sender) | ||
.receiver(receiver) | ||
.build(); | ||
} | ||
} |