Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7bdfd23
[remove] 더미파일 삭제(#97)
hd0rable Jul 23, 2025
18fdd7f
[feat] Comment 도메인 생성 책임 코드 추가 (#97)
hd0rable Jul 23, 2025
e07ccf6
[feat] CommentCommandController.createComment 작성 (#97)
hd0rable Jul 23, 2025
e832743
[feat] CommentCommandPersistenceAdapter.save / findById 작성 (#97)
hd0rable Jul 23, 2025
5e482df
[feat] CommentCommandPort 관련 함수 추가 작성 (#97)
hd0rable Jul 23, 2025
3b9b5d5
[feat] CommentCountUpdatable작성 (#97)
hd0rable Jul 23, 2025
a264cda
[feat] 댓글 생성 Command dto 작성 (#97)
hd0rable Jul 23, 2025
3a55c36
[feat] 댓글 생성 request dto 작성 (#97)
hd0rable Jul 23, 2025
81ff6ca
[feat] 댓글 생성 유즈케이스 구현체 CommentCreateService 작성 (#97)
hd0rable Jul 23, 2025
7c40758
[feat] 댓글 생성 유즈케이스 CommentCreateUseCase 작성 (#97)
hd0rable Jul 23, 2025
c189a0f
[feat] CommentIdResponse dto 작성 (#97)
hd0rable Jul 23, 2025
2fa454a
[feat] CommentJpaEntity에 postType,likeCount 추가 (#97)
hd0rable Jul 23, 2025
03fee58
[feat] CommentMapper 에 likeCount,postType 매핑추가 (#97)
hd0rable Jul 23, 2025
567c537
[feat] 관련 에러코드 추가 (#97)
hd0rable Jul 23, 2025
d6cb099
[feat] vote,record, feed CommentCountUpdatableincreaseCommentCount공통 …
hd0rable Jul 23, 2025
954f9d7
[feat] RecordCommandPersistenceAdapter.findById / update 작성 (#97)
hd0rable Jul 23, 2025
376be34
[feat] VoteCommandPersistenceAdapter.findById / updateVote 작성 (#97)
hd0rable Jul 23, 2025
ee6addf
[feat] RecordCommandPort 관련 함수 추가 (#97)
hd0rable Jul 23, 2025
8351056
[feat] VoteCommandPort 관련 함수 정의 (#97)
hd0rable Jul 23, 2025
6b6293d
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable Jul 23, 2025
1bde1e6
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable Jul 23, 2025
be08e43
[feat] PostType enum 작성 (#97)
hd0rable Jul 23, 2025
c704fe8
[remove] 안쓰는 함수 삭제 (#97)
hd0rable Jul 23, 2025
b1d1387
[test] 댓글 생성 단위 테스트코드 작성 (#97)
hd0rable Jul 23, 2025
0f90c97
[test] 댓글 생성 통합 테스트코드 작성 (#97)
hd0rable Jul 23, 2025
5c5e2e9
[test] Comment 도메인 단위 테스트 코드 작성 (#97)
hd0rable Jul 23, 2025
f09f794
[test] 테스트펙토리 메서드 누락 값 추가 (#97)
hd0rable Jul 23, 2025
2c01377
[test] 메서드 명 수정 (#97)
hd0rable Jul 23, 2025
a0c62cb
[test] postId 하드 코딩 수정 (#97)
hd0rable Jul 23, 2025
9dfe2d0
[refactor] todo 주석 수정(#97)
hd0rable Jul 23, 2025
4e77647
[fix] 누락 어노테이션 추가 (#97)
hd0rable Jul 24, 2025
2eacfd8
[test] 테스트 코드 수정 (#97)
hd0rable Jul 26, 2025
7c1249f
[refactor]RoomParticipantService 도메인 서비스 (#97)
hd0rable Jul 26, 2025
3d680a5
[refactor]validateCreateComment 검증 추가 (#97)
hd0rable Jul 26, 2025
770b6f2
[refactor] 관련 에러코드 수정및 추가(#97)
hd0rable Jul 26, 2025
4f7b632
[refactor] 댓글 생성시 권한 검증 로직 추가(#97)
hd0rable Jul 26, 2025
f438ba6
[refactor] CommentCountUpdatable.getRoomId 추가 (#97)
hd0rable Jul 26, 2025
791fee4
[test] 테스트마다 독립성 보장 어노테이션 추가 (#97)
hd0rable Jul 26, 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package konkuk.thip.comment.adapter.in.web;

import jakarta.validation.Valid;
import konkuk.thip.comment.adapter.in.web.request.CommentCreateRequest;
import konkuk.thip.comment.adapter.in.web.response.CommentIdResponse;
import konkuk.thip.comment.application.port.in.CommentCreateUseCase;
import konkuk.thip.common.dto.BaseResponse;
import konkuk.thip.common.security.annotation.UserId;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class CommentCommandController {

private final CommentCreateUseCase commentCreateUseCase;


/**
* 댓글/답글 작성
* parentId:{Long},isReplyRequest:true 답글
* parentId:null,isReplyRequest:false 댓글
*/
@PostMapping("/comments/{postId}")
public BaseResponse<CommentIdResponse> createComment(@RequestBody @Valid final CommentCreateRequest request,
@PathVariable("postId") final Long postId,
@UserId final Long userId) {
return BaseResponse.ok(CommentIdResponse.of(commentCreateUseCase.createComment(request.toCommand(userId,postId))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package konkuk.thip.comment.adapter.in.web.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import konkuk.thip.comment.application.port.in.dto.CommentCreateCommand;

public record CommentCreateRequest(

@NotBlank(message = "댓글 내용은 필수입니다.")
String content,

@NotNull(message = "답글 여부는 필수입니다.")
Boolean isReplyRequest,

Long parentId,

@NotBlank(message = "게시물 타입은 필수입니다.")
String postType

) {
public CommentCreateCommand toCommand(Long userId, Long postId) {
return new CommentCreateCommand(
content,
isReplyRequest,
parentId,
postType,
postId,
userId
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.comment.adapter.in.web.response;

public record CommentIdResponse(Long commentId) {
public static CommentIdResponse of(Long commentId) {
return new CommentIdResponse(commentId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import konkuk.thip.common.entity.BaseJpaEntity;
import konkuk.thip.common.post.PostType;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import lombok.*;
Expand All @@ -26,10 +27,19 @@ public class CommentJpaEntity extends BaseJpaEntity {
@Column(name = "report_count", nullable = false)
private int reportCount = 0;

@Builder.Default
@Column(name = "like_count", nullable = false)
private int likeCount = 0;

//TODO 상속구조 해지하면서 postType만 가질지, postId + postType가질지 논의 필요
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

상속 구조 해지하더라도, comment가 어떤 PostJpaEntity(= 도메인 상에서는 Feed, Vote, Record) 와 연관되어 있는지를 알아야 하므로, CommentJpaEntity 는

private PostJpaEntity targetPostJpaEntity;
private PostType targetPostType:

을 가지고 있으면 되지 않을까요??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

음 제가 구현할때 Feed, Vote, Record가 다른 테이블구조로 리펙된다고 생각했을때 적은 TODO라 그런것같습니당

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private PostJpaEntity postJpaEntity;

@Enumerated(EnumType.STRING)
@Column(name = "post_type", nullable = false, length = 10)
private PostType postType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private UserJpaEntity userJpaEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public class CommentMapper {
public CommentJpaEntity toJpaEntity(Comment comment, PostJpaEntity postJpaEntity, UserJpaEntity userJpaEntity, CommentJpaEntity commentJpaEntity) {
return CommentJpaEntity.builder()
.content(comment.getContent())
.likeCount(comment.getLikeCount())
.reportCount(comment.getReportCount())
.postJpaEntity(postJpaEntity)
.postType(comment.getPostType())
.userJpaEntity(userJpaEntity)
.parent(commentJpaEntity)
.build();
Expand All @@ -24,7 +26,9 @@ public Comment toDomainEntity(CommentJpaEntity commentJpaEntity) {
.id(commentJpaEntity.getCommentId())
.content(commentJpaEntity.getContent())
.reportCount(commentJpaEntity.getReportCount())
.likeCount(commentJpaEntity.getLikeCount())
.targetPostId(commentJpaEntity.getPostJpaEntity().getPostId())
.postType(commentJpaEntity.getPostType())
.creatorId(commentJpaEntity.getUserJpaEntity().getUserId())
.parentCommentId(commentJpaEntity.getParent() != null ? commentJpaEntity.getParent().getCommentId() : null)
.createdAt(commentJpaEntity.getCreatedAt())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
package konkuk.thip.comment.adapter.out.persistence;

import konkuk.thip.comment.adapter.out.jpa.CommentJpaEntity;
import konkuk.thip.comment.adapter.out.mapper.CommentMapper;
import konkuk.thip.comment.adapter.out.persistence.repository.CommentJpaRepository;
import konkuk.thip.comment.application.port.out.CommentCommandPort;
import konkuk.thip.comment.domain.Comment;
import konkuk.thip.common.exception.EntityNotFoundException;
import konkuk.thip.common.post.PostType;
import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.record.adapter.out.persistence.repository.RecordJpaRepository;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
import konkuk.thip.vote.adapter.out.persistence.repository.VoteJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Optional;

import static konkuk.thip.common.exception.code.ErrorCode.*;

@Repository
@RequiredArgsConstructor
public class CommentCommandPersistenceAdapter implements CommentCommandPort {

private final CommentJpaRepository commentJpaRepository;
private final FeedJpaRepository feedJpaRepository;
private final RecordJpaRepository recordJpaRepository;
private final VoteJpaRepository voteJpaRepository;
private final UserJpaRepository userJpaRepository;
private final CommentMapper commentMapper;

@Override
public Long save(Comment comment) {

// 1. 작성자(User) 조회 및 존재 검증
UserJpaEntity userJpaEntity = userJpaRepository.findById(comment.getCreatorId()).orElseThrow(
() -> new EntityNotFoundException(USER_NOT_FOUND)
);

// 2. 게시물(Post) 조회 및 존재 검증
PostJpaEntity postJpaEntity = findPostJpaEntity(comment.getPostType(), comment.getTargetPostId());

// 3. 부모 댓글 조회 (있을 경우)
CommentJpaEntity parentCommentJpaEntity = null;
if (comment.getParentCommentId() != null) {
parentCommentJpaEntity = commentJpaRepository.findById(comment.getParentCommentId())
.orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND));
}

return commentJpaRepository.save(
commentMapper.toJpaEntity(comment, postJpaEntity, userJpaEntity,parentCommentJpaEntity)
).getCommentId();
}

private PostJpaEntity findPostJpaEntity(PostType postType, Long postId) {
return switch (postType) {
case FEED -> feedJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(FEED_NOT_FOUND));
case RECORD -> recordJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(RECORD_NOT_FOUND));
case VOTE -> voteJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(VOTE_NOT_FOUND));
};
}

@Override
public Optional<Comment> findById(Long id) {
return commentJpaRepository.findById(id)
.map(commentMapper::toDomainEntity);
}
Comment on lines +34 to +72
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ public class CommentQueryPersistenceAdapter implements CommentQueryPort {
private final CommentJpaRepository jpaRepository;
private final CommentMapper userMapper;

@Override
public int countByPostId(Long postId) {
return jpaRepository.countByPostJpaEntity_PostId(postId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.comment.application.port.in;

import konkuk.thip.comment.application.port.in.dto.CommentCreateCommand;

public interface CommentCreateUseCase {
Long createComment(CommentCreateCommand command);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package konkuk.thip.comment.application.port.in.dto;

public record CommentCreateCommand(

String content,

Boolean isReplyRequest,

Long parentId,

String postType,

Long postId,

Long userId
)
{
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package konkuk.thip.comment.application.port.out;


import konkuk.thip.comment.domain.Comment;
import konkuk.thip.common.exception.EntityNotFoundException;

import java.util.Optional;

import static konkuk.thip.common.exception.code.ErrorCode.COMMENT_NOT_FOUND;

public interface CommentCommandPort {

Long save(Comment comment);

Optional<Comment> findById(Long id);

default Comment getByIdOrThrow(Long id) {
return findById(id)
.orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

public interface CommentQueryPort {

int countByPostId(Long postId);

}
Loading