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

Review Domain 작성 #8

Merged
merged 14 commits into from
Sep 15, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.wypl.common.exception;

public enum GlobalErrorCode implements ServerErrorCode {
INTERNAL_SERVER_ERROR(500, "GLOBAL_001", "알 수 없는 서버의 오류입니다."),
;

private final int statusCode;
private final String errorCode;
private final String message;

private GlobalErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
}

@Override
public String getErrorCode() {
return errorCode;
}

@Override
public String getMessage() {
return message;
}

@Override
public int getStatusCode() {
return statusCode;
}
}
4 changes: 3 additions & 1 deletion domain/jpa-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ java {
}

dependencies {
implementation project(':common')

api('org.springframework.boot:spring-boot-starter-data-jpa')

runtimeOnly 'com.h2database:h2'
runtimeOnly('com.h2database:h2')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wypl.jpacore;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@Configuration
public class JpaAuditingConfig {
}
56 changes: 56 additions & 0 deletions domain/jpa-core/src/main/java/com/wypl/jpacore/JpaBaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.wypl.jpacore;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.wypl.common.exception.WyplException;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@MappedSuperclass
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public abstract class JpaBaseEntity {

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

@LastModifiedDate
@Column(name = "modified_at", nullable = false)
private LocalDateTime modifiedAt;

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

public void delete() {
if (isDeleted()) {
throw new WyplException(JpaErrorCode.ALREADY_DELETED_ENTITY);
}
this.deletedAt = LocalDateTime.now();
}

public void restore() {
if (isNotDeleted()) {
throw new WyplException(JpaErrorCode.NON_DELETED_ENTITY);
}
this.deletedAt = null;
}

public boolean isNotDeleted() {
return deletedAt == null;
}

public boolean isDeleted() {
return !isNotDeleted();
}
}
20 changes: 20 additions & 0 deletions domain/jpa-core/src/main/java/com/wypl/jpacore/JpaErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wypl.jpacore;

import com.wypl.common.exception.ServerErrorCode;

import lombok.Getter;

@Getter
public enum JpaErrorCode implements ServerErrorCode {
ALREADY_DELETED_ENTITY(400, "JPA_001", "이미 삭제된 데이터입니다"),
NON_DELETED_ENTITY(400, "JPA_002", "삭제되지 않은 데이터는 복구할 수 없습니다.");
private final int statusCode;
private final String errorCode;
private final String message;

private JpaErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
}
}
Empty file.
13 changes: 13 additions & 0 deletions domain/jpamongo-review-domain/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

dependencies {
implementation project(':common')
implementation project(':domain:jpa-core')
implementation project(':domain:jpa-member-domain')
implementation project(':domain:jpa-calendar-domain')
implementation project(':domain:mongo-core')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.wypl.jpamongoreviewdomain.review.domain;

import org.hibernate.annotations.SQLRestriction;

import com.wypl.jpacore.JpaBaseEntity;
import com.wypl.jpamemberdomain.member.Member;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
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 lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
@Entity
public class Review extends JpaBaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "review_id")
private Long reviewId;

@Column(nullable = false, length = 50)
private String title;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

// TODO: 추후 schedule 와 `@ManyToOne` 관계가 필요
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wypl.jpamongoreviewdomain.review.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.wypl.jpamongoreviewdomain.review.domain.Review;

public interface ReviewRepository extends JpaRepository<Review, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.wypl.jpamongoreviewdomain.reviewcontents.domain;

import java.util.List;
import java.util.Map;

import org.springframework.data.mongodb.core.mapping.Document;

import com.wypl.mongocore.MongoBaseEntity;

import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Document(collection = "review_contents")
public class ReviewContents extends MongoBaseEntity {
@Id
private Long reviewId;

private List<Map<String, Object>> contents;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wypl.jpamongoreviewdomain.reviewcontents.repository;

import org.springframework.data.mongodb.repository.MongoRepository;

import com.wypl.jpamongoreviewdomain.reviewcontents.domain.ReviewContents;

public interface ReviewContentsRepository extends MongoRepository<ReviewContents, Long> {
}
2 changes: 2 additions & 0 deletions domain/mongo-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ java {
}

dependencies {
implementation project(':common')

/* Database */
api('org.springframework.boot:spring-boot-starter-data-mongodb')
implementation('de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring31x:4.11.0')
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wypl.mongocore;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.EnableMongoAuditing;

@EnableMongoAuditing
@Configuration
public class MongoAuditingConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.wypl.mongocore;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Field;

import com.wypl.common.exception.WyplException;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class MongoBaseEntity {
@CreatedDate
@Field(name = "created_at", write = Field.Write.NON_NULL)
private LocalDateTime createdAt;

@LastModifiedDate
@Field(name = "modified_at", write = Field.Write.NON_NULL)
private LocalDateTime modifiedAt;

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

public void delete() {
if (isDeleted()) {
throw new WyplException(MongoErrorCode.ALREADY_DELETED_ENTITY);
}
this.deletedAt = LocalDateTime.now();
}

public void restore() {
if (isNotDeleted()) {
throw new WyplException(MongoErrorCode.NON_DELETED_ENTITY);
}
this.deletedAt = null;
}

public boolean isNotDeleted() {
return deletedAt == null;
}

public boolean isDeleted() {
return !isNotDeleted();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wypl.mongocore;

import com.wypl.common.exception.ServerErrorCode;

import lombok.Getter;

@Getter
public enum MongoErrorCode implements ServerErrorCode {
ALREADY_DELETED_ENTITY(400, "JPA_001", "이미 삭제된 요소는 삭제할 수 없습니다."),
NON_DELETED_ENTITY(400, "JPA_002", "삭제되지 않은 요소는 복구할 수 없습니다.");
private final int statusCode;
private final String errorCode;
private final String message;

private MongoErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
}
}
Empty file.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include ':domain'
include ':domain:jpa-core'
include ':domain:jpa-calendar-domain'
include ':domain:jpa-member-domain'
include ':domain:jpamongo-review-domain'
include ':domain:mongo-core'

/* Client Module */
Expand Down
Loading