-
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 all 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,30 @@ | ||
| 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.annotation.Nullable; | ||
| 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, | ||
| @Schema(description = "부모 댓글의 ID", example = "1234", nullable = true) | ||
| @Nullable | ||
| Long parentCommentId | ||
| ) { | ||
| public CommunityComment toEntity(UUID writerId) { | ||
| 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,12 @@ | ||
| 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); | ||
| boolean existsById(Long id); | ||
| void deleteAllInBatch(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 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 boolean existsById(Long id) { | ||
| QCommunityComment communityComment = QCommunityComment.communityComment; | ||
|
|
||
| return queryFactory | ||
| .selectOne() | ||
| .from(communityComment) | ||
| .where(communityComment.id.eq(id) | ||
| .and(communityComment.deleted.eq(false))) | ||
| .fetchFirst() != null; | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAllInBatch() { communityCommentJpaRepository.deleteAllInBatch(); } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 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 com.somemore.global.exception.BadRequestException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class CreateCommunityCommentService implements CreateCommunityCommentUseCase { | ||
|
|
||
| private final CommunityCommentRepository communityCommentRepository; | ||
|
|
||
| @Override | ||
| public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) { | ||
| CommunityComment communityComment = requestDto.toEntity(writerId); | ||
|
|
||
| validateParentCommentExists(communityComment.getParentCommentId()); | ||
|
|
||
| return communityCommentRepository.save(communityComment).getId(); | ||
| } | ||
|
|
||
| private void validateParentCommentExists(Long parentCommentId) { | ||
| if (parentCommentId != null && !communityCommentRepository.existsById(parentCommentId)) { | ||
| throw new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()); | ||
| } | ||
| } | ||
| } |
| 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,11 @@ | ||
| 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); | ||
| } |
This file was deleted.
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.
앗 수정하겠습니다