Skip to content

Commit

Permalink
[BSVR-123] DB 컨벤션에 맞춰 BaseEntity 생성 (#20)
Browse files Browse the repository at this point in the history
* feat: BaseEntity 생성

* feat: 모든 entity에 BaseEntity 적용
  • Loading branch information
EunjiShin authored Jul 13, 2024
1 parent ad8dd29 commit 6c5de58
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 367 deletions.
30 changes: 3 additions & 27 deletions domain/src/main/java/org/depromeet/spot/domain/review/Review.java
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
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

0 comments on commit 6c5de58

Please sign in to comment.