Skip to content

Commit

Permalink
[FEAT] ProfileCard와 ProfileCardLike 엔티티 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JIN-076 committed Feb 18, 2024
1 parent 5c07b8a commit 95f349d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
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();
}
}
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();
}
}

0 comments on commit 95f349d

Please sign in to comment.