Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6094c71
test(community): communityComment 생성 기능 테스트 작성
ayoung-dev Nov 28, 2024
4b666aa
feat(community): communityComment Entity, Repository 추가
ayoung-dev Nov 28, 2024
e087c0c
feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현
ayoung-dev Nov 28, 2024
9a4c087
refactor(community): CommunityBoardRepository 네이밍 변경
ayoung-dev Nov 28, 2024
58038ee
refactor(community): community board/comment 폴더 구조 변경
ayoung-dev Nov 28, 2024
b686152
chore(community): 불필요한 import 및 public 키워드 제거
ayoung-dev Nov 28, 2024
0be3598
Feature/36 s3 이미지 업로드 기능 구현 (#66)
7zrv Nov 28, 2024
f68bb02
test(community): 커뮤니티 댓글 생성 테스트 추가
ayoung-dev Nov 28, 2024
f265514
chore(community): 소문자로 네이밍 변경
ayoung-dev Nov 28, 2024
10a0dbb
fix(community): 커뮤니티 댓글 생성 requestDto 수정
ayoung-dev Nov 28, 2024
3151a8b
feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가
ayoung-dev Nov 28, 2024
21e7a2a
refactor(community): 코드 리뷰 사항 반영
ayoung-dev Nov 28, 2024
c5d8e3c
test(community): communityComment 생성 기능 테스트 작성
ayoung-dev Nov 28, 2024
dbaf67e
feat(community): communityComment Entity, Repository 추가
ayoung-dev Nov 28, 2024
3c306dc
feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현
ayoung-dev Nov 28, 2024
f4a5f6b
refactor(community): CommunityBoardRepository 네이밍 변경
ayoung-dev Nov 28, 2024
0f23e4a
refactor(community): community board/comment 폴더 구조 변경
ayoung-dev Nov 28, 2024
b43a5e6
chore(community): 불필요한 import 및 public 키워드 제거
ayoung-dev Nov 28, 2024
7835bb2
test(community): 커뮤니티 댓글 생성 테스트 추가
ayoung-dev Nov 28, 2024
6c0def6
chore(community): 소문자로 네이밍 변경
ayoung-dev Nov 28, 2024
62aa1e5
fix(community): 커뮤니티 댓글 생성 requestDto 수정
ayoung-dev Nov 28, 2024
01656ce
feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가
ayoung-dev Nov 28, 2024
b12b771
refactor(community): 코드 리뷰 사항 반영
ayoung-dev Nov 28, 2024
27a199a
Merge remote-tracking branch 'origin/feature/65-add-community-comment…
ayoung-dev Nov 28, 2024
d1caba6
feat(community): 커뮤니티 댓글 존재 여부 메서드 및 테스트 추가
ayoung-dev Nov 28, 2024
f7d3478
chore(community): 불필요한 import 제거
ayoung-dev Nov 28, 2024
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
41 changes: 41 additions & 0 deletions src/main/java/com/somemore/community/domain/CommunityComment.java
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Community_comment -> community_comment 하시면 좋을 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

앗 수정하겠습니다


@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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

parentCommentId는 어디서 오는지 궁금합니다!
requestDto에 필드에 담겨서 오는게 아닐까요?
아니면 대댓글 작성 API가 따로 있어서 Pathvariable에 담겨오는 걸까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

댓글 작성과 대댓글 작성 API가 분리되어 있는지 궁금하네요

아뇨! 하나예요
requestDto에 담겨서 오는 게 맞네요 (왜 갑자기 이렇게 생각했을까요...)
수정하겠습니다!

.writerId(writerId)
.content(content)
.parentCommentId(parentCommentId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.somemore.community.repository;
package com.somemore.community.repository.board;

import com.somemore.community.domain.CommunityBoard;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.somemore.community.repository;
package com.somemore.community.repository.board;

import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.domain.CommunityBoardView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.somemore.community.repository;
package com.somemore.community.repository.board;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
Expand All @@ -16,7 +16,7 @@

@RequiredArgsConstructor
@Repository
public class CommunityRepositoryImpl implements CommunityBoardRepository {
public class CommunityBoardRepositoryImpl implements CommunityBoardRepository {

private final JPAQueryFactory queryFactory;
private final CommunityBoardJpaRepository communityBoardJpaRepository;
Expand Down
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
@@ -1,11 +1,11 @@
package com.somemore.community.service;
package com.somemore.community.service.board;

import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.domain.CommunityBoardView;
import com.somemore.community.dto.response.CommunityBoardGetDetailResponseDto;
import com.somemore.community.dto.response.CommunityBoardGetResponseDto;
import com.somemore.community.repository.CommunityBoardRepository;
import com.somemore.community.usecase.CommunityBoardQueryUseCase;
import com.somemore.community.repository.board.CommunityBoardRepository;
import com.somemore.community.usecase.board.CommunityBoardQueryUseCase;
import com.somemore.global.exception.BadRequestException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.somemore.community.service;
package com.somemore.community.service.board;

import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.dto.request.CommunityBoardCreateRequestDto;
import com.somemore.community.repository.CommunityBoardRepository;
import com.somemore.community.usecase.CreateCommunityBoardUseCase;
import com.somemore.community.repository.board.CommunityBoardRepository;
import com.somemore.community.usecase.board.CreateCommunityBoardUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.somemore.community.service;
package com.somemore.community.service.board;

import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.repository.CommunityBoardRepository;
import com.somemore.community.usecase.DeleteCommunityBoardUseCase;
import com.somemore.community.repository.board.CommunityBoardRepository;
import com.somemore.community.usecase.board.DeleteCommunityBoardUseCase;
import com.somemore.global.exception.BadRequestException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.somemore.community.service;
package com.somemore.community.service.board;

import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.dto.request.CommunityBoardUpdateRequestDto;
import com.somemore.community.repository.CommunityBoardRepository;
import com.somemore.community.usecase.UpdateCommunityBoardUseCase;
import com.somemore.community.repository.board.CommunityBoardRepository;
import com.somemore.community.usecase.board.UpdateCommunityBoardUseCase;
import com.somemore.global.exception.BadRequestException;

import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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);

if (communityComment.getParentCommentId() != null) {
communityCommentRepository.findById(communityComment.getParentCommentId())
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

추상화된 private 메서드로 추출할 수 있을 것 같습니다.

Suggested change
if (communityComment.getParentCommentId() != null) {
communityCommentRepository.findById(communityComment.getParentCommentId())
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()));
}
checkParentComment(communityComment.getParentCommentId());

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정했습니다!


return communityCommentRepository.save(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 com.somemore.community.dto.response.CommunityBoardGetDetailResponseDto;
import com.somemore.community.dto.response.CommunityBoardGetResponseDto;
Expand Down
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 com.somemore.community.dto.request.CommunityBoardCreateRequestDto;

Expand Down
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;

Expand Down
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 com.somemore.community.dto.request.CommunityBoardUpdateRequestDto;

Expand Down
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);
}
28 changes: 0 additions & 28 deletions src/main/java/com/somemore/domains/CommunityComment.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum ExceptionMessage {
NOT_EXISTS_CENTER("존재하지 않는 기관 ID 입니다."),
NOT_EXISTS_COMMUNITY_BOARD("존재하지 않는 게시글 입니다."),
UNAUTHORIZED_COMMUNITY_BOARD("해당 게시글에 권한이 없습니다."),
NOT_EXISTS_COMMUNITY_COMMENT("존재하지 않는 댓글 입니다."),
NOT_EXISTS_LOCATION("존재하지 않는 위치 ID 입니다."),
NOT_EXISTS_RECRUIT_BOARD("존재하지 않는 봉사 모집글 ID 입니다."),
UNAUTHORIZED_RECRUIT_BOARD("자신이 작성한 봉사 모집글이 아닙니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.somemore.auth.oauth.OAuthProvider;
import com.somemore.community.domain.CommunityBoard;
import com.somemore.community.domain.CommunityBoardView;
import com.somemore.community.repository.board.CommunityBoardRepository;
import com.somemore.volunteer.domain.Volunteer;
import com.somemore.volunteer.repository.VolunteerRepository;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -18,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;

@Transactional
class CommunityRepositoryTest extends IntegrationTestSupport {
class CommunityBoardRepositoryTest extends IntegrationTestSupport {

@Autowired
private CommunityBoardRepository communityBoardRepository;
Expand Down
Loading