-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Spring Data Elasticsearch 의존성 추가 * feat: 설정 파일에 elasticsearch 엔드포인트 추가 (application.yml) * chore: 직렬화 문제로 DTO에 @NoArgsConstructor 추가 * feat: ElasticsearchConfig 작성 * feat: PostDocument 작성 * feat: PostElasticsearchRepository 작성 * feat: 게시글 리스트 조회(findAllPosts)시 ES 사용하도록 변경 * chore: 사용하지 않는 클래스 삭제 (QuerydslPredicate, QuerydslRepository) * feat: 개별 게시글 조회시 ES 사용하도록 변경 * feat: 게시글 추가시 ES에도 반영 * feat: 게시글 수정시 ES에도 반영 * feat: 게시글 삭제시 ES에도 반영 * feat: self-injection 방식으로 내부 호출 문제 해결 방식 변경 <문제 상황> findAllPosts()에서 getPostPage()를 내부 호출하기 때문에 getPostPage()의 @Cacheable 작동하지 않음 <기존 해결 방식> 별도 클래스에 getPostPage() 구현하여 findAllPosts()에서 호출 <기존 방식 문제점> 불필요하게 클래스 수 증가 <수정된 해결 방식> PostService 에서 자기 자신을 주입하도록 하여 내부 호출시에도 @Cacheable 작동 되도록 함
- Loading branch information
Showing
20 changed files
with
453 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
backend/src/main/java/com/bootme/comment/dto/CommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/bootme/config/ElasticsearchConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.bootme.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.elasticsearch.client.ClientConfiguration; | ||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration; | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; | ||
|
||
@Configuration | ||
@EnableElasticsearchRepositories(basePackages = "com.bootme.post.repository") | ||
public class ElasticsearchConfig extends ElasticsearchConfiguration { | ||
|
||
@Value("${elasticsearch.host:10.0.6.174}") | ||
private String elasticsearchHost; | ||
|
||
@Value("${elasticsearch.port:9200}") | ||
private int elasticsearchPort; | ||
|
||
@Override | ||
public ClientConfiguration clientConfiguration() { | ||
return ClientConfiguration.builder() | ||
.connectedTo(elasticsearchHost + ":" + elasticsearchPort) | ||
.build(); | ||
} | ||
|
||
} |
130 changes: 130 additions & 0 deletions
130
backend/src/main/java/com/bootme/post/domain/PostDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.bootme.post.domain; | ||
|
||
import com.bootme.post.dto.PostRequest; | ||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.springframework.data.elasticsearch.annotations.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.bootme.common.util.TimeConverter.*; | ||
|
||
@Data | ||
@Document(indexName = "post") | ||
public class PostDocument { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Field(type = FieldType.Long, name = "postId") | ||
private Long postId; | ||
|
||
@Field(type = FieldType.Long, name = "memberId") | ||
private Long writerId; | ||
|
||
@Field(type = FieldType.Text, name = "writerNickname") | ||
private String writerNickname; | ||
|
||
@Field(type = FieldType.Text, name = "writerProfileImage") | ||
private String writerProfileImage; | ||
|
||
@Field(type = FieldType.Text, name = "topic") | ||
private String topic; | ||
|
||
@Field(type = FieldType.Text, name = "title") | ||
private String title; | ||
|
||
@Field(type = FieldType.Text, name = "content") | ||
private String content; | ||
|
||
@Field(type = FieldType.Integer, name = "commentCount") | ||
private int commentCount; | ||
|
||
@Field(type = FieldType.Integer, name = "likes") | ||
private int likes; | ||
|
||
@Field(type = FieldType.Integer, name = "clicks") | ||
private int clicks; | ||
|
||
@Field(type = FieldType.Integer, name = "bookmarks") | ||
private int bookmarks; | ||
|
||
@Field(type = FieldType.Keyword, name = "status") | ||
private String status; | ||
|
||
@Field(type = FieldType.Long, name = "createdAt") | ||
private long createdAt; | ||
|
||
@Field(type = FieldType.Long, name = "modifiedAt") | ||
private long modifiedAt; | ||
|
||
@Builder | ||
public PostDocument(String id, Long postId, Long writerId, String writerNickname, String writerProfileImage, String topic, | ||
String title, String content, int commentCount, int likes, int clicks, int bookmarks, | ||
String status, long createdAt, long modifiedAt) { | ||
this.id = id; | ||
this.postId = postId; | ||
this.writerId = writerId; | ||
this.writerNickname = writerNickname; | ||
this.writerProfileImage = writerProfileImage; | ||
this.topic = topic; | ||
this.title = title; | ||
this.content = content; | ||
this.commentCount = commentCount; | ||
this.likes = likes; | ||
this.clicks = clicks; | ||
this.bookmarks = bookmarks; | ||
this.status = status; | ||
this.createdAt = createdAt; | ||
this.modifiedAt = modifiedAt; | ||
} | ||
|
||
public static PostDocument fromPost(Post post) { | ||
return PostDocument.builder() | ||
.postId(post.getId()) | ||
.writerId(post.getMember().getId()) | ||
.writerNickname(post.getWriterNickname()) | ||
.writerProfileImage(post.getMember().getProfileImage()) | ||
.topic(post.getTopic()) | ||
.title(post.getTitle().getValue()) | ||
.content(post.getContent().getValue()) | ||
.commentCount(post.getComments().size()) | ||
.likes(post.getLikes()) | ||
.clicks(post.getClicks()) | ||
.bookmarks(post.getBookmarks()) | ||
.status(post.getStatus().name()) | ||
.createdAt(convertLocalDateTimeToLong(post.getCreatedAt())) | ||
.modifiedAt(convertLocalDateTimeToLong(post.getModifiedAt())) | ||
.build(); | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("id", this.id); | ||
map.put("postId", this.postId); | ||
map.put("writerId", this.writerId); | ||
map.put("writerNickname", this.writerNickname); | ||
map.put("writerProfileImage", this.writerProfileImage); | ||
map.put("topic", this.topic); | ||
map.put("title", this.title); | ||
map.put("content", this.content); | ||
map.put("commentCount", this.commentCount); | ||
map.put("likes", this.likes); | ||
map.put("clicks", this.clicks); | ||
map.put("bookmarks", this.bookmarks); | ||
map.put("status", this.status); | ||
map.put("createdAt", this.createdAt); | ||
map.put("modifiedAt", this.modifiedAt); | ||
return map; | ||
} | ||
|
||
public void updateFromRequest(PostRequest postRequest) { | ||
this.setTopic(postRequest.getTopic()); | ||
this.setTitle(postRequest.getTitle()); | ||
this.setContent(postRequest.getContent()); | ||
this.setModifiedAt(System.currentTimeMillis()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.