Skip to content

Commit e087c0c

Browse files
committed
feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현
1 parent 4b666aa commit e087c0c

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.somemore.community.dto.request;
2+
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
5+
import com.somemore.community.domain.CommunityComment;
6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
import jakarta.validation.constraints.NotBlank;
8+
import lombok.Builder;
9+
10+
import java.util.UUID;
11+
12+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
13+
@Builder
14+
public record CommunityCommentCreateRequestDto(
15+
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
16+
@NotBlank(message = "댓글 내용은 필수 값입니다.")
17+
String content
18+
) {
19+
public CommunityComment toEntity(UUID writerId, Long parentCommentId) {
20+
return CommunityComment.builder()
21+
.writerId(writerId)
22+
.content(content)
23+
.parentCommentId(parentCommentId)
24+
.build();
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.somemore.community.service.comment;
2+
3+
import com.somemore.community.domain.CommunityComment;
4+
import com.somemore.community.dto.request.CommunityCommentCreateRequestDto;
5+
import com.somemore.community.repository.comment.CommunityCommentRepository;
6+
import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Transactional;
10+
11+
import java.util.UUID;
12+
13+
@RequiredArgsConstructor
14+
@Transactional
15+
@Service
16+
public class CreateCommunityCommentService implements CreateCommunityCommentUseCase {
17+
18+
private final CommunityCommentRepository communityCommentRepository;
19+
20+
@Override
21+
public Long CreateCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId, Long parentCommunityId) {
22+
23+
CommunityComment communityComment = requestDto.toEntity(writerId, parentCommunityId);
24+
25+
communityCommentRepository.save(communityComment);
26+
27+
return communityComment.getId();
28+
}
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.somemore.community.usecase.comment;
2+
3+
import com.somemore.community.domain.CommunityComment;
4+
import com.somemore.community.dto.request.CommunityCommentCreateRequestDto;
5+
6+
import java.util.UUID;
7+
8+
public interface CreateCommunityCommentUseCase {
9+
Long CreateCommunityComment(
10+
CommunityCommentCreateRequestDto requestDto,
11+
UUID writerId,
12+
Long parentCommunityId);
13+
}

0 commit comments

Comments
 (0)