-
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.
chore : Separate the basic design for comment logic and time-related …
…columns into the BaseTimeEntity abstract class. #8
- Loading branch information
Showing
16 changed files
with
179 additions
and
187 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
src/main/java/com/games/balancegameback/domain/game/GameComments.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/main/java/com/games/balancegameback/domain/game/GameResourceComments.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,32 @@ | ||
package com.games.balancegameback.domain.game; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
public class GameResourceComments { | ||
|
||
private Long id; | ||
private String comment; | ||
private GameResources gameResources; | ||
private Long parentId; | ||
private LocalDateTime createdDate; | ||
private LocalDateTime updatedDate; | ||
private List<GameResourceComments> children; | ||
|
||
@Builder | ||
public GameResourceComments(Long id, String comment, GameResources gameResources, Long parentId, | ||
LocalDateTime createdDate, LocalDateTime updatedDate, | ||
List<GameResourceComments> children) { | ||
this.id = id; | ||
this.comment = comment; | ||
this.gameResources = gameResources; | ||
this.parentId = parentId; | ||
this.createdDate = createdDate; | ||
this.updatedDate = updatedDate; | ||
this.children = children; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/games/balancegameback/domain/game/GameResultComments.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,15 @@ | ||
package com.games.balancegameback.domain.game; | ||
|
||
import lombok.Builder; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record GameResultComments(Long id, String comment, Games games, Long parentId, | ||
LocalDateTime createdDate, LocalDateTime updatedDate, List<GameResultComments> children) { | ||
|
||
@Builder | ||
public GameResultComments { | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/games/balancegameback/infra/entity/BaseTimeEntity.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,25 @@ | ||
package com.games.balancegameback.infra.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
|
||
@Column(updatable = false) | ||
@CreatedDate | ||
private LocalDateTime createdDate; | ||
|
||
@Column | ||
@LastModifiedDate | ||
private LocalDateTime updatedDate; | ||
} |
72 changes: 0 additions & 72 deletions
72
src/main/java/com/games/balancegameback/infra/entity/GameCommentsEntity.java
This file was deleted.
Oops, something went wrong.
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
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/games/balancegameback/infra/entity/GameResourceCommentsEntity.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 com.games.balancegameback.infra.entity; | ||
|
||
import com.games.balancegameback.domain.game.GameResourceComments; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "game_resource_comments") | ||
public class GameResourceCommentsEntity extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String comment; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "parent_id") | ||
private GameResourceCommentsEntity parent; | ||
|
||
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<GameResourceCommentsEntity> children = new ArrayList<>(); | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "game_resources_id") | ||
private GameResourcesEntity gameResources; | ||
|
||
public static GameResourceCommentsEntity from(GameResourceComments gameResourceComments) { | ||
GameResourceCommentsEntity gameResourceCommentsEntity = new GameResourceCommentsEntity(); | ||
gameResourceCommentsEntity.comment = gameResourceComments.getComment(); | ||
gameResourceCommentsEntity.gameResources = GameResourcesEntity.from(gameResourceComments.getGameResources()); | ||
|
||
// 부모 댓글 설정 | ||
if (gameResourceComments.getParentId() != null) { | ||
GameResourceCommentsEntity parent = new GameResourceCommentsEntity(); | ||
parent.id = gameResourceComments.getParentId(); | ||
gameResourceCommentsEntity.parent = parent; | ||
} | ||
|
||
return gameResourceCommentsEntity; | ||
} | ||
|
||
public GameResourceComments toModel() { | ||
return GameResourceComments.builder() | ||
.id(id) | ||
.comment(comment) | ||
.parentId(parent != null ? parent.getId() : null) | ||
.gameResources(gameResources.toModel()) | ||
.createdDate(this.getCreatedDate()) | ||
.updatedDate(this.getUpdatedDate()) | ||
.children(children.stream() // 대댓글 리스트 변환 | ||
.map(GameResourceCommentsEntity::toModel) | ||
.toList()) | ||
.build(); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/games/balancegameback/infra/entity/GameResultCommentsEntity.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,40 @@ | ||
package com.games.balancegameback.infra.entity; | ||
|
||
import com.games.balancegameback.domain.game.GameResultComments; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "game_result_comments") | ||
public class GameResultCommentsEntity extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String comment; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "games_id") | ||
private GamesEntity games; | ||
|
||
public static GameResultCommentsEntity from(GameResultComments gameResultComments) { | ||
GameResultCommentsEntity gameResultCommentsEntity = new GameResultCommentsEntity(); | ||
gameResultCommentsEntity.comment = gameResultComments.comment(); | ||
gameResultCommentsEntity.games = GamesEntity.from(gameResultComments.games()); | ||
|
||
return gameResultCommentsEntity; | ||
} | ||
|
||
public GameResultComments toModel() { | ||
return GameResultComments.builder() | ||
.id(id) | ||
.comment(comment) | ||
.games(games.toModel()) | ||
.createdDate(this.getCreatedDate()) | ||
.updatedDate(this.getUpdatedDate()) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.