Skip to content

Commit 4b666aa

Browse files
committed
feat(community): communityComment Entity, Repository 추가
1 parent 6094c71 commit 4b666aa

File tree

5 files changed

+96
-28
lines changed

5 files changed

+96
-28
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.somemore.community.domain;
2+
3+
import com.somemore.global.common.BaseEntity;
4+
import jakarta.persistence.*;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.util.UUID;
10+
11+
import static lombok.AccessLevel.PROTECTED;
12+
13+
14+
@Getter
15+
@NoArgsConstructor(access = PROTECTED)
16+
@Entity
17+
@Table(name = "Community_comment")
18+
public class CommunityComment extends BaseEntity {
19+
20+
@Id
21+
@GeneratedValue(strategy = GenerationType.IDENTITY)
22+
@Column(name = "id", nullable = false)
23+
private Long id;
24+
25+
@Column(name = "writer_id", nullable = false, length = 16)
26+
private UUID writerId;
27+
28+
@Lob
29+
@Column(name = "content", nullable = false)
30+
private String content;
31+
32+
@Column(name = "parent_comment_id")
33+
private Long parentCommentId;
34+
35+
@Builder
36+
public CommunityComment(UUID writerId, String content, Long parentCommentId) {
37+
this.writerId = writerId;
38+
this.content = content;
39+
this.parentCommentId = parentCommentId;
40+
}
41+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.somemore.community.repository.comment;
2+
3+
import com.somemore.community.domain.CommunityComment;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface CommunityCommentJpaRepository extends JpaRepository<CommunityComment, Long> {
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.somemore.community.repository.comment;
2+
3+
import com.somemore.community.domain.CommunityComment;
4+
5+
import java.util.Optional;
6+
7+
public interface CommunityCommentRepository {
8+
CommunityComment save(CommunityComment communityComment);
9+
Optional<CommunityComment> findById(Long id);
10+
void deleteAllInBatch();
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.somemore.community.repository.comment;
2+
3+
import com.querydsl.jpa.impl.JPAQueryFactory;
4+
import com.somemore.community.domain.CommunityComment;
5+
import com.somemore.community.domain.QCommunityBoard;
6+
import com.somemore.community.domain.QCommunityComment;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Repository;
9+
10+
import java.util.Optional;
11+
12+
@RequiredArgsConstructor
13+
@Repository
14+
public class CommunityCommentRepositoryImpl implements CommunityCommentRepository {
15+
16+
private final JPAQueryFactory queryFactory;
17+
private final CommunityCommentJpaRepository communityCommentJpaRepository;
18+
19+
@Override
20+
public CommunityComment save(CommunityComment communityComment) {
21+
return communityCommentJpaRepository.save(communityComment);
22+
}
23+
24+
@Override
25+
public Optional<CommunityComment> findById(Long id) {
26+
QCommunityComment communityComment = QCommunityComment.communityComment;
27+
28+
return Optional.ofNullable(queryFactory
29+
.selectFrom(communityComment)
30+
.where(communityComment.id.eq(id)
31+
.and(communityComment.deleted.eq(false)))
32+
.fetchOne());
33+
}
34+
35+
@Override
36+
public void deleteAllInBatch() { communityCommentJpaRepository.deleteAllInBatch(); }
37+
}

src/main/java/com/somemore/domains/CommunityComment.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)