From 8f59b4dea3ce19304aeaba678d099acda81ada11 Mon Sep 17 00:00:00 2001 From: Eunbeen Noh <101248968+EunbeenDev@users.noreply.github.com> Date: Sun, 7 Jan 2024 15:15:28 +0900 Subject: [PATCH] [FIX]: edu/news/content to enum (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FEAT] #3 ChatGPT 응답 단답 확인 과정 테스트 * [FIX] #3 SecurityConfig permitAll 추가 * [FEAT] #3 ChatgptRequest 추가 GPT Request DTO format * [FIX] #3 Chatgpt dependencies 추가 * [FEAT] #14 EduContent DTO 생성 * [FIX] #14 Post AccessLevel 수정 * [FEAT] #14 educontent 저장 api 구현 * [FEAT] #14 educontent 조회/상세조회/수정/삭제 api 구현 * [FEAT] #15 newscontent 저장/조회/상세조회/수정/삭제 api 구현 * [FEAT] #19 content 저장/조회/상세조회/수정/삭제 api 구현 * [FEAT] #19 swagger 설정 추가 * [FEAT] #19 readOnly를 위한 Transactional 어노테이션 추가 * [FEAT] #39 chatbot, comment 파일 추가 * fix: chat gpt 수정 * [FIX] #19 Transactional annotation readOnly default 수정 * Revert "[FIX] #19 Transactional annotation readOnly default 수정" This reverts commit 4a18b0ebce60ff41bdacac044fd6c365adf49ca4. * [FIX] #19 Transactional annotation readOnly default 수정 * [FEAT] #39 챗봇 질의응답 기능 개발 인사말 추가, 질의응답, 조회 기능 * [FEAT] educontent created_at 요청/응답 필드 추가 * [FIX] #39 챗봇 요청/응답값 UserId 부분 수정 * [FIX] #39 챗봇 요청/응답값 UserId 부분 수정 * [FIX] #39 swagger 코드 추가 * [FIX] #52 Post Entity enum type 추가 --------- Co-authored-by: 박세진 Co-authored-by: Sejin Park <95167215+sejineer@users.noreply.github.com> --- .../domain/chatgpt/application/ChatGptService.java | 1 + .../domain/comment/application/CommentService.java | 3 +-- .../domain/educontent/domain/EduContent.java | 11 +++++++++++ .../educontent/dto/request/EduContentRequest.java | 1 - .../educontent/dto/response/EduContentResponse.java | 1 - .../domain/newscontent/domain/NewsContent.java | 9 +++++++++ .../com/finfellows/domain/post/domain/Content.java | 6 ++++++ .../finfellows/domain/post/domain/ContentType.java | 7 +++++++ .../java/com/finfellows/domain/post/domain/Post.java | 7 ++++++- 9 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/finfellows/domain/post/domain/ContentType.java diff --git a/src/main/java/com/finfellows/domain/chatgpt/application/ChatGptService.java b/src/main/java/com/finfellows/domain/chatgpt/application/ChatGptService.java index 0fa7e4f..da6ba38 100644 --- a/src/main/java/com/finfellows/domain/chatgpt/application/ChatGptService.java +++ b/src/main/java/com/finfellows/domain/chatgpt/application/ChatGptService.java @@ -32,5 +32,6 @@ public String getChatResponse(String prompt) { return "request error"; } } + } diff --git a/src/main/java/com/finfellows/domain/comment/application/CommentService.java b/src/main/java/com/finfellows/domain/comment/application/CommentService.java index 6bf2e86..2b741d8 100644 --- a/src/main/java/com/finfellows/domain/comment/application/CommentService.java +++ b/src/main/java/com/finfellows/domain/comment/application/CommentService.java @@ -40,6 +40,7 @@ public class CommentService { @Autowired private RestTemplate restTemplate; + @Value("${chatgpt.api-key}") private String apiKey; private final ObjectMapper objectMapper = new ObjectMapper() @@ -56,7 +57,6 @@ public HttpEntity buildHttpEntity(ChatgptRequest chatGptRequest) // gpt 단답 public ChatgptResponse getResponse(HttpEntity chatGptRequestHttpEntity) { - SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(60000); //답변이 길어질 경우 TimeOut Error가 발생하니 1분정도 설정해줍니다. @@ -91,7 +91,6 @@ public ChatgptResponse askQuestion(ChatgptQuestionRequest questionRequest) { ); } - public String getChatResponse(String question){ String responseFromGPT=chatGptService.getChatResponse(question); return responseFromGPT; diff --git a/src/main/java/com/finfellows/domain/educontent/domain/EduContent.java b/src/main/java/com/finfellows/domain/educontent/domain/EduContent.java index 420223b..37dc0f1 100644 --- a/src/main/java/com/finfellows/domain/educontent/domain/EduContent.java +++ b/src/main/java/com/finfellows/domain/educontent/domain/EduContent.java @@ -1,6 +1,7 @@ package com.finfellows.domain.educontent.domain; import com.finfellows.domain.common.BaseEntity; +import com.finfellows.domain.post.domain.ContentType; import com.finfellows.domain.post.domain.Post; import jakarta.persistence.*; import lombok.AccessLevel; @@ -25,6 +26,10 @@ public class EduContent extends BaseEntity { @JoinColumn(name="post_id") private Post post; + @Enumerated(EnumType.STRING) + @Column(name="contentType") + private ContentType contentType; + @Column(name="title") private String title; @@ -37,6 +42,12 @@ public EduContent(Post post, String title, String content){ this.post=post; this.title=title; this.content=content; + this.contentType = ContentType.EDU_CONTENT; + } + + public void updateContent(String title, String content) { + this.title = title; + this.content = content; } public void updateContent(String title, String content) { diff --git a/src/main/java/com/finfellows/domain/educontent/dto/request/EduContentRequest.java b/src/main/java/com/finfellows/domain/educontent/dto/request/EduContentRequest.java index e09677a..e8c2b3c 100644 --- a/src/main/java/com/finfellows/domain/educontent/dto/request/EduContentRequest.java +++ b/src/main/java/com/finfellows/domain/educontent/dto/request/EduContentRequest.java @@ -5,7 +5,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; - import java.time.LocalDateTime; @Getter diff --git a/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java b/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java index 1422270..a2231c6 100644 --- a/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java +++ b/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java @@ -7,7 +7,6 @@ import java.time.LocalDateTime; - @Getter @Builder @AllArgsConstructor diff --git a/src/main/java/com/finfellows/domain/newscontent/domain/NewsContent.java b/src/main/java/com/finfellows/domain/newscontent/domain/NewsContent.java index 5d6006c..3a83299 100644 --- a/src/main/java/com/finfellows/domain/newscontent/domain/NewsContent.java +++ b/src/main/java/com/finfellows/domain/newscontent/domain/NewsContent.java @@ -1,6 +1,9 @@ package com.finfellows.domain.newscontent.domain; import com.finfellows.domain.common.BaseEntity; + +import com.finfellows.domain.post.domain.ContentType; + import com.finfellows.domain.post.domain.Post; import jakarta.persistence.*; import lombok.Builder; @@ -29,11 +32,17 @@ public class NewsContent extends BaseEntity { @Column(name="content") private String content; + @Enumerated(EnumType.STRING) + @Column(name="contentType") + private ContentType contentType; + @Builder public NewsContent(Post post, String title, String content){ this.post=post; this.title=title; this.content=content; + this.contentType = ContentType.NEWS_CONTENT; + } public void updateContent(String title, String content) { diff --git a/src/main/java/com/finfellows/domain/post/domain/Content.java b/src/main/java/com/finfellows/domain/post/domain/Content.java index c5f3db5..a865285 100644 --- a/src/main/java/com/finfellows/domain/post/domain/Content.java +++ b/src/main/java/com/finfellows/domain/post/domain/Content.java @@ -32,12 +32,18 @@ public class Content { @Column(name="content") private String content; + @Enumerated(EnumType.STRING) + @Column(name="contentType") + private ContentType contentType; + @Builder public Content(Post post_id, String title, String content){ this.post_id=post_id; this.title=title; this.content=content; + this.contentType = ContentType.CONTENT; + } public void updateContent(String title, String content) { diff --git a/src/main/java/com/finfellows/domain/post/domain/ContentType.java b/src/main/java/com/finfellows/domain/post/domain/ContentType.java new file mode 100644 index 0000000..a0f2316 --- /dev/null +++ b/src/main/java/com/finfellows/domain/post/domain/ContentType.java @@ -0,0 +1,7 @@ +package com.finfellows.domain.post.domain; + +public enum ContentType { + EDU_CONTENT, + NEWS_CONTENT, + CONTENT +} diff --git a/src/main/java/com/finfellows/domain/post/domain/Post.java b/src/main/java/com/finfellows/domain/post/domain/Post.java index 5231c18..f661ccf 100644 --- a/src/main/java/com/finfellows/domain/post/domain/Post.java +++ b/src/main/java/com/finfellows/domain/post/domain/Post.java @@ -26,9 +26,14 @@ public class Post extends BaseEntity { @JoinColumn(name="writer_id") private User writer; + @Enumerated(EnumType.STRING) + @Column(name="contentType") + private ContentType contentType; + @Builder - public Post(User writer){ + public Post(User writer, ContentType contentType){ this.writer=writer; + this.contentType=contentType; } }