-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/65 커뮤니티 댓글 생성 기능 #67
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
Changes from 6 commits
6094c71
4b666aa
e087c0c
9a4c087
58038ee
b686152
0be3598
f68bb02
f265514
10a0dbb
3151a8b
21e7a2a
c5d8e3c
dbaf67e
3c306dc
f4a5f6b
0f23e4a
b43a5e6
7835bb2
6c0def6
62aa1e5
01656ce
b12b771
27a199a
d1caba6
f7d3478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.somemore.community.domain; | ||
|
|
||
| import com.somemore.global.common.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static lombok.AccessLevel.PROTECTED; | ||
|
|
||
|
|
||
| @Getter | ||
| @NoArgsConstructor(access = PROTECTED) | ||
| @Entity | ||
| @Table(name = "Community_comment") | ||
| public class CommunityComment extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id", nullable = false) | ||
| private Long id; | ||
|
|
||
| @Column(name = "writer_id", nullable = false, length = 16) | ||
| private UUID writerId; | ||
|
|
||
| @Lob | ||
| @Column(name = "content", nullable = false) | ||
| private String content; | ||
|
|
||
| @Column(name = "parent_comment_id") | ||
| private Long parentCommentId; | ||
|
|
||
| @Builder | ||
| public CommunityComment(UUID writerId, String content, Long parentCommentId) { | ||
| this.writerId = writerId; | ||
| this.content = content; | ||
| this.parentCommentId = parentCommentId; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.somemore.community.dto.request; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.community.domain.CommunityComment; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Builder; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| @Builder | ||
| public record CommunityCommentCreateRequestDto( | ||
| @Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.") | ||
| @NotBlank(message = "댓글 내용은 필수 값입니다.") | ||
| String content | ||
| ) { | ||
| public CommunityComment toEntity(UUID writerId, Long parentCommentId) { | ||
| return CommunityComment.builder() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parentCommentId는 어디서 오는지 궁금합니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
아뇨! 하나예요 |
||
| .writerId(writerId) | ||
| .content(content) | ||
| .parentCommentId(parentCommentId) | ||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.somemore.community.repository.comment; | ||
|
|
||
| import com.somemore.community.domain.CommunityComment; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CommunityCommentJpaRepository extends JpaRepository<CommunityComment, Long> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.somemore.community.repository.comment; | ||
|
|
||
| import com.somemore.community.domain.CommunityComment; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface CommunityCommentRepository { | ||
| CommunityComment save(CommunityComment communityComment); | ||
| Optional<CommunityComment> findById(Long id); | ||
| void deleteAllInBatch(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.somemore.community.repository.comment; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import com.somemore.community.domain.CommunityComment; | ||
| import com.somemore.community.domain.QCommunityComment; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class CommunityCommentRepositoryImpl implements CommunityCommentRepository { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
| private final CommunityCommentJpaRepository communityCommentJpaRepository; | ||
|
|
||
| @Override | ||
| public CommunityComment save(CommunityComment communityComment) { | ||
| return communityCommentJpaRepository.save(communityComment); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<CommunityComment> findById(Long id) { | ||
| QCommunityComment communityComment = QCommunityComment.communityComment; | ||
|
|
||
| return Optional.ofNullable(queryFactory | ||
| .selectFrom(communityComment) | ||
| .where(communityComment.id.eq(id) | ||
| .and(communityComment.deleted.eq(false))) | ||
| .fetchOne()); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAllInBatch() { communityCommentJpaRepository.deleteAllInBatch(); } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.somemore.community.service.comment; | ||
|
|
||
| import com.somemore.community.domain.CommunityComment; | ||
| import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; | ||
| import com.somemore.community.repository.comment.CommunityCommentRepository; | ||
| import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class CreateCommunityCommentService implements CreateCommunityCommentUseCase { | ||
|
|
||
| private final CommunityCommentRepository communityCommentRepository; | ||
|
|
||
| @Override | ||
| public Long CreateCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId, Long parentCommunityId) { | ||
|
|
||
| CommunityComment communityComment = requestDto.toEntity(writerId, parentCommunityId); | ||
|
|
||
| communityCommentRepository.save(communityComment); | ||
|
|
||
| return communityComment.getId(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package com.somemore.community.usecase; | ||
| package com.somemore.community.usecase.board; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.somemore.community.usecase.comment; | ||
|
|
||
| import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface CreateCommunityCommentUseCase { | ||
| Long CreateCommunityComment( | ||
| CommunityCommentCreateRequestDto requestDto, | ||
| UUID writerId, | ||
| Long parentCommunityId); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||
| package com.somemore.community.repository; | ||||||
|
|
||||||
| import com.somemore.IntegrationTestSupport; | ||||||
| import com.somemore.community.domain.CommunityComment; | ||||||
| import com.somemore.community.repository.comment.CommunityCommentRepository; | ||||||
| import org.junit.jupiter.api.DisplayName; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||
| import java.util.UUID; | ||||||
|
|
||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||
|
|
||||||
| @Transactional | ||||||
| class CommunityCommentRepositoryTest extends IntegrationTestSupport { | ||||||
| @Autowired | ||||||
| CommunityCommentRepository communityCommentRepository; | ||||||
|
|
||||||
| @DisplayName("커뮤니티 게시글에 댓글을 생성할 수 있다. (Repository)") | ||||||
| @Test | ||||||
| void createCommunityComment() { | ||||||
|
|
||||||
| //given | ||||||
| UUID writerId = UUID.randomUUID(); | ||||||
|
|
||||||
| CommunityComment communityComment = CommunityComment.builder() | ||||||
| .writerId(writerId) | ||||||
| .content("커뮤니티 댓글 테스트 내용") | ||||||
| .parentCommentId(null) | ||||||
| .build(); | ||||||
|
|
||||||
| //when | ||||||
| CommunityComment savedComment = communityCommentRepository.save(communityComment); | ||||||
|
|
||||||
| //then | ||||||
| assertThat(savedComment.getWriterId()).isEqualTo(writerId); | ||||||
| assertThat(savedComment.getContent()).isEqualTo("커뮤니티 댓글 테스트 내용"); | ||||||
| assertThat(savedComment.getParentCommentId()).isNull(); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("커뮤니티 게시글에 대댓글을 생성할 수 있다. (Repository)") | ||||||
|
||||||
| @DisplayName("커뮤니티 게시글에 대댓글을 생성할 수 있다. (Repository)") | |
| @DisplayName("댓글에 대댓글을 생성할 수 있다. (Repository)") |
이런 맥락이 더 좋지 않을까요?
그런 의미에서 parent가 없는 경우에 대한 검증이 여기서나 서비스 테스트에서 필요할 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 네임은 바꾸겠습니다!
부모 댓글 검증을 조회에서만 생각했네요
추가하겠습니다! 감사합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!
board와 comment 파일이 헷갈릴 수 있겠다고 판단하여 폴더로 한 번 더 나누었는데 괜찮은지 여쭤봅니다.
이 부분도 저는 좋은 것 같습니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재중님 생각해봤는데
댓글 생성 쪽에서는 삭제된 댓글에는 대댓글 생성을 못하도록 하고
댓글 조회 쪽에서 삭제된 경우에도 대댓글이 있으면 조회를 하도록 해야할 거 같은데
혹시 더 생각해야할 부분이 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Community_comment -> community_comment하시면 좋을 것 같습니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 수정하겠습니다