Skip to content

Comment: comment 모듈 추가 및 application, api 작성 #68

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8653bd8
feat(comment): add comment-service build gradle file
seonghooni May 3, 2025
fe8311f
fix(board): add flyway to board.database-local.yml
seonghooni May 3, 2025
11a0274
feat(comment/reply): create domain, exception, read-model to api module
seonghooni May 3, 2025
6a8053d
feat(comment/reply): create port to application module
seonghooni May 3, 2025
95edb7d
feat(comment/reply): create entity to driven/entity module
seonghooni May 3, 2025
e41ab5b
build(comment/reply): create yml, postgresql script to entity module
seonghooni May 3, 2025
223fd5d
build(comment/reply): build comment module configurations (settings.g…
seonghooni May 3, 2025
7efcd78
fix: merge conflict resolved in build.gradle.kts
seonghooni May 11, 2025
22bb9f3
fix(comment/reply): rename postgresql files
seonghooni May 11, 2025
734e71c
fix(comment/reply): fix typo/syntax in entity
seonghooni May 11, 2025
caf146d
build(comment/reply): modify build.gradle.kts, settings.gradle.kts
seonghooni May 11, 2025
de2beaa
feat(comment/reply): add EntityStatusConverter
seonghooni May 11, 2025
2a2af19
fix(comment/reply): modify comment/driven/rdb/build.gradle.kts
seonghooni May 11, 2025
746daea
fix(comment/reply): resolve conflict monolith/main-runner/build.gradl…
seonghooni May 11, 2025
970cfc4
refactor(comment/reply): add builder method to entity
seonghooni May 18, 2025
8bb4c97
refactor(comment/reply): add fk to domain
seonghooni May 18, 2025
c8814aa
feat(comment/reply): add RDB adapter(command,query)
seonghooni May 18, 2025
c4c602f
refactor(comment/reply): remove getter annotation from entity
seonghooni May 18, 2025
5b77667
refactor(comment/reply): modify function, parameter of port and adapter
seonghooni May 19, 2025
0488fb9
feat(comment/reply): add QueryService, CommandService, UseCase
seonghooni May 19, 2025
f0d73b2
refactor(comment/reply): modify readModels, port, adapter
seonghooni May 19, 2025
7097736
feat(comment/reply): add command service, query service
seonghooni May 19, 2025
a990533
feat(comment/reply): add command api, query api, dto to web-mvc module
seonghooni May 19, 2025
d0062f7
refactor(comment/reply): modify base-package according to #86
seonghooni May 19, 2025
b007832
refactor(comment/reply): add boardId field to CommentDetail
seonghooni May 19, 2025
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
1 change: 1 addition & 0 deletions monolith/main-runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation(project(":cors-webmvc"))
// service
implementation(project(":board"))
implementation(project(":comment"))
// webmvc
implementation("org.springframework.boot:spring-boot-starter-web")
// db
Expand Down
1 change: 1 addition & 0 deletions monolith/main-runner/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ spring:
import:
- properties.web/main.cors.yml
- board.yml
- comment.yml

server:
port: 5000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${BOARD_POSTGRESQL_URL:jdbc:postgresql://localhost:5433/demo}
username: ${BOARD_POSTGRESQL_USERNAME:root}
password: ${BOARD_POSTGRESQL_PASSWORD:root}

flyway:
baseline-on-migrate: true
locations:
- db/postgresql/migration/v1_0
5 changes: 5 additions & 0 deletions services/comment/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies {
api(project(":comment:api:domain"))
api(project(":comment:api:exception"))
api(project(":comment:api:readmodel"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package nettee.comment;

import java.time.Instant;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import nettee.comment.type.CommentStatus;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Comment {

private Long id;

private String content;

private CommentStatus status;

private Instant createdAt;

private Instant updatedAt;

@Builder(
builderClassName = "updateCommentBuilder",
builderMethodName = "prepareUpdate",
buildMethodName = "update"
)
public void update(String content) {
Objects.requireNonNull(content, "content cannot be null");

this.content = content;
this.updatedAt = Instant.now();
}

public void softDelete() {
this.status = CommentStatus.REMOVED;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package nettee.comment.type;

import java.util.EnumSet;
import java.util.Set;

public enum CommentStatus {

PENDING,
ACTIVE,
REMOVED;

private static final Set<CommentStatus> GENERAL_QUERY_STATUS = EnumSet.of(ACTIVE);

public static Set<CommentStatus> getGeneralQueryStatus() {
return GENERAL_QUERY_STATUS;
}

}
44 changes: 44 additions & 0 deletions services/comment/api/domain/src/main/java/nettee/reply/Reply.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nettee.reply;

import java.time.Instant;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import nettee.reply.type.ReplyStatus;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Reply {

private Long id;

private Long parentId;

private String content;

private ReplyStatus status;

private Instant createdAt;

private Instant updatedAt;

@Builder(
builderClassName = "updateReplyBuilder",
builderMethodName = "prepareUpdate",
buildMethodName = "update"
)
public void update(String content) {
Objects.requireNonNull(content, "content cannot be null");

this.content = content;
this.updatedAt = Instant.now();
}

public void softDelete() {
this.status = ReplyStatus.REMOVED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package nettee.reply.type;

import java.util.EnumSet;
import java.util.Set;

public enum ReplyStatus {

PENDING,
ACTIVE,
REMOVED;

private static final Set<ReplyStatus> GENERAL_QUERY_STATUS = EnumSet.of(ACTIVE);

public static Set<ReplyStatus> getGeneralQueryStatus() {
return GENERAL_QUERY_STATUS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package nettee.comment;

import java.util.Map;
import java.util.function.Supplier;
import nettee.common.ErrorCode;
import org.springframework.http.HttpStatus;

public enum CommentCommandErrorCode implements ErrorCode {
COMMENT_NOT_FOUND("댓글을 찾을 수 없습니다.", HttpStatus.NOT_FOUND),
COMMENT_GONE("더 이상 존재하지 않는 댓글입니다.", HttpStatus.GONE),
COMMENT_FORBIDDEN("권한이 없습니다.", HttpStatus.FORBIDDEN),
DEFAULT("댓글 조작 오류", HttpStatus.INTERNAL_SERVER_ERROR),
COMMENT_ALREADY_EXIST("댓글이 이미 존재합니다.", HttpStatus.CONFLICT);

private final String message;
private final HttpStatus httpStatus;

CommentCommandErrorCode(String message, HttpStatus httpStatus) {
this.message = message;
this.httpStatus = httpStatus;
}

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

@Override
public HttpStatus httpStatus() {
return httpStatus;
}

@Override
public CommentCommandException exception() {
return new CommentCommandException(this);
}

@Override
public CommentCommandException exception(Throwable cause) {
return new CommentCommandException(this, cause);
}

@Override
public RuntimeException exception(Runnable runnable) {
return new CommentCommandException(this, runnable);
}

@Override
public RuntimeException exception(Runnable runnable, Throwable cause) {
return new CommentCommandException(this, runnable, cause);
}

@Override
public RuntimeException exception(Supplier<Map<String, Object>> payload) {
return new CommentCommandException(this, payload);
}

@Override
public RuntimeException exception(Supplier<Map<String, Object>> payload, Throwable cause) {
return new CommentCommandException(this, payload, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nettee.comment;

import java.util.Map;
import java.util.function.Supplier;
import nettee.common.CustomException;
import nettee.common.ErrorCode;

public class CommentCommandException extends CustomException {

/**
* CommentErrorCodeLazyHolder를 파라미터로 받기 위해, ErrorCode 타입으로 임시 설정함.
*/
public CommentCommandException(ErrorCode errorCode) {
super(errorCode);
}

public CommentCommandException(ErrorCode errorCode, Throwable cause) {
super(errorCode, cause);
}

public CommentCommandException(ErrorCode errorCode, Runnable runnable) {
super(errorCode, runnable);
}

public CommentCommandException(ErrorCode errorCode, Runnable runnable, Throwable cause) {
super(errorCode, runnable, cause);
}

public CommentCommandException(ErrorCode errorCode, Supplier<Map<String, Object>> payload) {
super(errorCode, payload);
}

public CommentCommandException(ErrorCode errorCode, Supplier<Map<String, Object>> payload, Throwable cause) {
super(errorCode, payload, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package nettee.comment;

import java.util.Map;
import java.util.function.Supplier;
import nettee.common.ErrorCode;
import org.springframework.http.HttpStatus;

public enum CommentQueryErrorCode implements ErrorCode {
COMMENT_NOT_FOUND("댓글을 찾을 수 없습니다.", HttpStatus.NOT_FOUND),
COMMENT_GONE("더 이상 존재하지 않는 댓글입니다.", HttpStatus.GONE),
COMMENT_FORBIDDEN("권한이 없습니다.", HttpStatus.FORBIDDEN),
DEFAULT("댓글 조작 오류", HttpStatus.INTERNAL_SERVER_ERROR);

private final String message;
private final HttpStatus httpStatus;

CommentQueryErrorCode(String message, HttpStatus httpStatus) {
this.message = message;
this.httpStatus = httpStatus;
}

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

@Override
public HttpStatus httpStatus() {
return httpStatus;
}

@Override
public CommentQueryException exception() {
return new CommentQueryException(this);
}

@Override
public CommentQueryException exception(Throwable cause) {
return new CommentQueryException(this, cause);
}

@Override
public RuntimeException exception(Runnable runnable) {
return new CommentQueryException(this, runnable);
}

@Override
public RuntimeException exception(Runnable runnable, Throwable cause) {
return new CommentQueryException(this, runnable, cause);
}

@Override
public RuntimeException exception(Supplier<Map<String, Object>> payload) {
return new CommentQueryException(this, payload);
}

@Override
public RuntimeException exception(Supplier<Map<String, Object>> payload, Throwable cause) {
return new CommentQueryException(this, payload, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nettee.comment;

import java.util.Map;
import java.util.function.Supplier;
import nettee.common.CustomException;

public class CommentQueryException extends CustomException {
public CommentQueryException(CommentQueryErrorCode errorCode) {
super(errorCode);
}

public CommentQueryException(CommentQueryErrorCode errorCode, Throwable cause) {
super(errorCode, cause);
}

public CommentQueryException(CommentQueryErrorCode errorCode, Runnable runnable) {
super(errorCode, runnable);
}

public CommentQueryException(CommentQueryErrorCode errorCode, Runnable runnable, Throwable cause) {
super(errorCode, runnable, cause);
}

public CommentQueryException(CommentQueryErrorCode errorCode, Supplier<Map<String, Object>> payload) {
super(errorCode, payload);
}

public CommentQueryException(CommentQueryErrorCode errorCode, Supplier<Map<String, Object>> payload, Throwable cause) {
super(errorCode, payload, cause);
}
}
Loading