Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BSVR-123] DB 컨벤션에 맞춰 BaseEntity 생성 #20

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.depromeet.spot.domain.review;

import java.time.LocalDate;
import java.time.LocalDateTime;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

누나 어떤건 builder로 하고 어떤 건 allargscontructor로 했던데, 혹시 도메인마다 다르게 적용한 이유가 있어?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 큰 이유는 없어! 빌더랑 allargsconstructor은 사실상 동시에 쓰여도 상관은 없당
내 티켓에서 빌더 쓴 이유는 동일한 자료형의 필드가 여러개 있어서, 생성자를 쓰면 순서 실수가 있을 것 같아서였어~
빌더나 생성자를 아예 팀 컨벤션으로 강제하기보단, 필요에 맞게 사용하면 될 듯 해!

public class Review {

private final Long id;
Expand All @@ -14,34 +15,9 @@ public class Review {
private final Long seatId;
private final Long rowId;
private final Long seatNumber;
private final LocalDate date; // 시간은 미표기
private final LocalDateTime dateTime;
private final String content;
private final LocalDateTime createdAt;
private final LocalDateTime updatedAt;
private final String status;

public Review(
Long id,
Long userId,
Long blockId,
Long seatId,
Long rowId,
Long seatNumber,
LocalDate date,
String content,
LocalDateTime createdAt,
LocalDateTime updatedAt,
String status) {
this.id = id;
this.userId = userId;
this.blockId = blockId;
this.seatId = seatId;
this.rowId = rowId;
this.seatNumber = seatNumber;
this.date = date;
this.content = content;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.jpa.common.entity.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "blocks")
@NoArgsConstructor
public class BlockEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@AllArgsConstructor
public class BlockEntity extends BaseEntity {

@Column(name = "stadium_id", nullable = false)
private Long stadiumId;
Expand All @@ -32,24 +28,12 @@ public class BlockEntity {
@Column(name = "max_rows", nullable = false)
private Integer maxRows;

public BlockEntity(Long id, Long stadiumId, Long sectionId, String code, Integer maxRows) {
this.id = id;
this.stadiumId = stadiumId;
this.sectionId = sectionId;
this.code = code;
this.maxRows = maxRows;
}

public static BlockEntity from(Block block) {
return new BlockEntity(
block.getId(),
block.getStadiumId(),
block.getSectionId(),
block.getCode(),
block.getMaxRows());
block.getStadiumId(), block.getSectionId(), block.getCode(), block.getMaxRows());
}

public Block toDomain() {
return new Block(id, stadiumId, sectionId, code, maxRows);
return new Block(this.getId(), stadiumId, sectionId, code, maxRows);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import org.depromeet.spot.domain.block.BlockRow;
import org.depromeet.spot.jpa.common.entity.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "block_rows")
@NoArgsConstructor
public class BlockRowEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;

@AllArgsConstructor
public class BlockRowEntity extends BaseEntity {
@Column(name = "block_id", nullable = false)
private Long blockId;

Expand All @@ -29,22 +24,12 @@ public class BlockRowEntity {
@Column(name = "max_seats", nullable = false)
private Long maxSeats;

public BlockRowEntity(Long id, Long blockId, Long number, Long maxSeats) {
this.id = id;
this.blockId = blockId;
this.number = number;
this.maxSeats = maxSeats;
}

public static BlockRowEntity from(BlockRow blockRow) {
return new BlockRowEntity(
blockRow.getId(),
blockRow.getBlockId(),
blockRow.getNumber(),
blockRow.getMaxSeats());
blockRow.getBlockId(), blockRow.getNumber(), blockRow.getMaxSeats());
}

public BlockRow toDomain() {
return new BlockRow(id, blockId, number, maxSeats);
return new BlockRow(this.getId(), blockId, number, maxSeats);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import org.depromeet.spot.domain.block.BlockTopKeyword;
import org.depromeet.spot.jpa.common.entity.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "block_top_keywords")
@NoArgsConstructor
public class BlockTopKeywordEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@AllArgsConstructor
public class BlockTopKeywordEntity extends BaseEntity {

@Column(name = "block_id", nullable = false)
private Long blockId;
Expand All @@ -29,22 +25,14 @@ public class BlockTopKeywordEntity {
@Column(name = "count", nullable = false)
private Long count;

public BlockTopKeywordEntity(Long id, Long blockId, Long keywordId, Long count) {
this.id = id;
this.blockId = blockId;
this.keywordId = keywordId;
this.count = count;
}

public static BlockTopKeywordEntity from(BlockTopKeyword blockTopKeyword) {
return new BlockTopKeywordEntity(
blockTopKeyword.getId(),
blockTopKeyword.getBlockId(),
blockTopKeyword.getKeywordId(),
blockTopKeyword.getCount());
}

public BlockTopKeyword toDomain() {
return new BlockTopKeyword(id, blockId, keywordId, count);
return new BlockTopKeyword(this.getId(), blockId, keywordId, count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.depromeet.spot.jpa.common.entity;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;

import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder
@MappedSuperclass
@AllArgsConstructor
@Where(clause = "deleted_at is null")
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class BaseEntity {

@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(updatable = false, name = "created_at")
private LocalDateTime createdAt;

@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@PrePersist
public void prePersist() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}

@PreUpdate
public void preUpdate() {
this.updatedAt = LocalDateTime.now();
}

public boolean isDeleted() {
return null != this.deletedAt;
}

public void delete() {
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package org.depromeet.spot.jpa.member.entity;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.jpa.common.entity.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "members")
@NoArgsConstructor
public class MemberEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id", nullable = false)
private Long userId;
@AllArgsConstructor
public class MemberEntity extends BaseEntity {

@Column(name = "email", nullable = false, unique = true, length = 50)
private String email;
Expand Down Expand Up @@ -52,44 +46,8 @@ public class MemberEntity {
@Column(name = "role", nullable = false)
private Integer role;

@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

public MemberEntity(
Long userId,
String email,
String name,
String nickname,
String phoneNumber,
Integer level,
String profileImage,
String snsProvider,
String idToken,
String myTeam,
Integer role,
LocalDateTime createdAt,
LocalDateTime deletedAt) {
this.userId = userId;
this.email = email;
this.name = name;
this.nickname = nickname;
this.phoneNumber = phoneNumber;
this.level = level;
this.profileImage = profileImage;
this.snsProvider = snsProvider;
this.idToken = idToken;
this.myTeam = myTeam;
this.role = role;
this.createdAt = createdAt;
this.deletedAt = deletedAt;
}

public static MemberEntity from(Member member) {
return new MemberEntity(
member.getUserId(),
member.getEmail(),
member.getName(),
member.getNickname(),
Expand All @@ -99,14 +57,12 @@ public static MemberEntity from(Member member) {
member.getSnsProvider(),
member.getIdToken(),
member.getMyTeam(),
member.getRole(),
member.getCreatedAt(),
member.getDeletedAt());
member.getRole());
}

public Member toDomain() {
return new Member(
userId,
this.getId(),
email,
name,
nickname,
Expand All @@ -117,7 +73,7 @@ public Member toDomain() {
idToken,
myTeam,
role,
createdAt,
deletedAt);
this.getCreatedAt(),
this.getDeletedAt());
}
}
Loading
Loading