From afea4b58ff5b646efaf138db0ea3952c5dd7741d Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Wed, 8 Nov 2023 22:48:21 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8=20DNS=20?= =?UTF-8?q?CORS=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/WithYou/global/config/WebSecurityConfig.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/WithYou/global/config/WebSecurityConfig.java b/src/main/java/WithYou/global/config/WebSecurityConfig.java index c352e82..6c00b75 100644 --- a/src/main/java/WithYou/global/config/WebSecurityConfig.java +++ b/src/main/java/WithYou/global/config/WebSecurityConfig.java @@ -11,9 +11,7 @@ public class WebSecurityConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://10.114.10.20:3000", "http://192.168.0.26:3000", - "http://172.20.10.2:3000", "http://192.168.0.11:3000", - "http://192.168.0.155:3000", "http://10.114.10.15:3000/") // 허용할 도메인(Origin)을 명시적으로 지정 + .allowedOrigins("https://with-you-eight.vercel.app/") // 허용할 도메인(Origin)을 명시적으로 지정 .allowedHeaders("*") .exposedHeaders("accessToken", "refreshToken", "validation") .allowedMethods( From 44087c8fa88ef1715d078c681bde742f83e8d146 Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Thu, 9 Nov 2023 00:24:56 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20=EB=A1=9C=EC=BB=AC=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=20CORS=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/WithYou/global/config/WebSecurityConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/WithYou/global/config/WebSecurityConfig.java b/src/main/java/WithYou/global/config/WebSecurityConfig.java index 6c00b75..b0c2416 100644 --- a/src/main/java/WithYou/global/config/WebSecurityConfig.java +++ b/src/main/java/WithYou/global/config/WebSecurityConfig.java @@ -11,7 +11,8 @@ public class WebSecurityConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("https://with-you-eight.vercel.app/") // 허용할 도메인(Origin)을 명시적으로 지정 + .allowedOrigins("https://with-you-eight.vercel.app", "http://10.114.10.15:3000" + ,"http://192.168.0.26:3000") // 허용할 도메인(Origin)을 명시적으로 지정 .allowedHeaders("*") .exposedHeaders("accessToken", "refreshToken", "validation") .allowedMethods( From d8399cb424323c45e3dde37e243d18a81b4e19f5 Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Thu, 9 Nov 2023 00:39:09 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20Scrap=20content=20=EA=B8=B8=EC=9D=B4?= =?UTF-8?q?=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/WithYou/domain/scrap/entity/Scrap.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/WithYou/domain/scrap/entity/Scrap.java b/src/main/java/WithYou/domain/scrap/entity/Scrap.java index 360a246..5a5e309 100644 --- a/src/main/java/WithYou/domain/scrap/entity/Scrap.java +++ b/src/main/java/WithYou/domain/scrap/entity/Scrap.java @@ -2,13 +2,9 @@ import WithYou.domain.member.entity.Member; import WithYou.global.common.entity.BaseEntity; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; + +import javax.persistence.*; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -26,6 +22,7 @@ public class Scrap extends BaseEntity { private Long postId; private String title; + @Column(length = 5000) private String content; private String imageUrl; From 420a19dd95d93f3ddd50c6861ec8ebf016ed4c1b Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Fri, 10 Nov 2023 14:43:30 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix=20:=20post=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=8B=9C=20userLevel=EB=8F=84=20=EA=B0=99=EC=9D=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WithYou/domain/ai/dto/request/ChatGptRequestDto.java | 6 +++--- src/main/java/WithYou/domain/ai/service/ChatGptService.java | 4 ++-- .../WithYou/domain/post/dto/response/PostLookupDto.java | 5 ++++- .../domain/post/dto/response/PostRegistResponseDto.java | 1 + src/main/java/WithYou/domain/post/entity/Post.java | 3 +++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/WithYou/domain/ai/dto/request/ChatGptRequestDto.java b/src/main/java/WithYou/domain/ai/dto/request/ChatGptRequestDto.java index 95ccb06..55c1a70 100644 --- a/src/main/java/WithYou/domain/ai/dto/request/ChatGptRequestDto.java +++ b/src/main/java/WithYou/domain/ai/dto/request/ChatGptRequestDto.java @@ -10,11 +10,11 @@ public class ChatGptRequestDto { private List messages; private int max_tokens; - public ChatGptRequestDto(String model, String content, String major) { //매개변수에 학생 학과를 받아와서 사용하면 될듯 + public ChatGptRequestDto(String model, String content, String field) { //매개변수에 학생 학과를 받아와서 사용하면 될듯 this.model = model; this.messages = new ArrayList<>(); - this.messages.add(new Message("system", "너는 " + major + " 교수야. " + - "해당 전공에 대한 지식이 풍부하며, 질문에 대해서 항상 정확한 답변을 주고, 어떤 질문이든 반드시 대답할 수 있어.")); + this.messages.add(new Message("system", "너는 " + field + " 전문가야." + + "해당 분야에 대한 지식이 풍부하며, 질문에 대해서 항상 정확한 답변을 주고, 어떤 질문이든 반드시 대답할 수 있어.")); //@authenticationprincipal을 이용해서 User의 학과를 불러온 후 해당 학과 교수로서 답을 하도록 역할 부여할 예정 this.messages.add(new Message("user", content)); this.max_tokens = 800; diff --git a/src/main/java/WithYou/domain/ai/service/ChatGptService.java b/src/main/java/WithYou/domain/ai/service/ChatGptService.java index 10f3e69..2fbfe6f 100644 --- a/src/main/java/WithYou/domain/ai/service/ChatGptService.java +++ b/src/main/java/WithYou/domain/ai/service/ChatGptService.java @@ -58,8 +58,8 @@ public QuestionResponseDto askQuestion(QuestionRequestDto questionRequestDto) { return questionResponseDto; } - public String askQuestionGpt(String prompt, String major) { - ChatGptRequestDto chatGptRequestDto = new ChatGptRequestDto(model, prompt, major); + public String askQuestionGpt(String prompt, String field) { + ChatGptRequestDto chatGptRequestDto = new ChatGptRequestDto(model, prompt, field); RestTemplate restTemplate = new RestTemplate(); ChatGptResponseDto response = restTemplate.postForObject(apiUrl, getHttpEntity(chatGptRequestDto), ChatGptResponseDto.class); diff --git a/src/main/java/WithYou/domain/post/dto/response/PostLookupDto.java b/src/main/java/WithYou/domain/post/dto/response/PostLookupDto.java index 7eba6ac..66da72e 100644 --- a/src/main/java/WithYou/domain/post/dto/response/PostLookupDto.java +++ b/src/main/java/WithYou/domain/post/dto/response/PostLookupDto.java @@ -1,7 +1,9 @@ package WithYou.domain.post.dto.response; import WithYou.domain.post.entity.Post; + import java.time.LocalDateTime; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -15,12 +17,13 @@ public class PostLookupDto { private String userMajor; private int userGrade; private int commentCount; + private double userLevel; private LocalDateTime createdDate; private String imageUrl; public static PostLookupDto of(Post post) { return new PostLookupDto(post.getId(), post.getTitle(), post.getContent(), post.getUserNickName(), - post.getUserMajor(), post.getUserGrade(), post.getCommentCount(), post.getCreatedDate(), + post.getUserMajor(), post.getUserGrade(), post.getCommentCount(), post.getUserLevel(), post.getCreatedDate(), post.getImageUrl()); } } diff --git a/src/main/java/WithYou/domain/post/dto/response/PostRegistResponseDto.java b/src/main/java/WithYou/domain/post/dto/response/PostRegistResponseDto.java index 19153fb..05c00d6 100644 --- a/src/main/java/WithYou/domain/post/dto/response/PostRegistResponseDto.java +++ b/src/main/java/WithYou/domain/post/dto/response/PostRegistResponseDto.java @@ -22,6 +22,7 @@ public Post toEntity(Member member) { .content(content) .userGrade(member.getGrade()) .userMajor(member.getMajor()) + .userLevel(member.getLevel()) .userNickName(member.getNickName()) .imageUrl(imageUrl) .build(); diff --git a/src/main/java/WithYou/domain/post/entity/Post.java b/src/main/java/WithYou/domain/post/entity/Post.java index 66bba0b..d5089a8 100644 --- a/src/main/java/WithYou/domain/post/entity/Post.java +++ b/src/main/java/WithYou/domain/post/entity/Post.java @@ -2,6 +2,7 @@ import WithYou.domain.comment.entity.Comment; import WithYou.global.common.entity.BaseEntity; + import java.util.ArrayList; import java.util.List; import javax.persistence.CascadeType; @@ -11,6 +12,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -31,6 +33,7 @@ public class Post extends BaseEntity { private String userNickName; private String userMajor; private int userGrade; + private double userLevel; private int commentCount; @Column(length = 1000) private String imageUrl; From bf725ccf82178fd3b15505f28d57fd4b7c84e2db Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Fri, 10 Nov 2023 15:01:08 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix=20:=20=EB=8C=93=EA=B8=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20post=EC=9D=98=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=8F=84=20=EA=B0=99=EC=9D=B4=20=EB=B0=98=ED=99=98=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentController.java | 9 +++++++-- .../domain/comment/dto/request/CommentRegistDto.java | 1 + .../java/WithYou/domain/comment/entity/Comment.java | 1 + .../domain/comment/service/CommentService.java | 12 ++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/WithYou/domain/comment/controller/CommentController.java b/src/main/java/WithYou/domain/comment/controller/CommentController.java index f457b58..074eb22 100644 --- a/src/main/java/WithYou/domain/comment/controller/CommentController.java +++ b/src/main/java/WithYou/domain/comment/controller/CommentController.java @@ -1,9 +1,11 @@ package WithYou.domain.comment.controller; import WithYou.domain.comment.dto.request.CommentRegistDto; +import WithYou.domain.comment.entity.Comment; import WithYou.domain.comment.service.CommentService; import WithYou.domain.post.entity.Post; import WithYou.domain.post.service.PostService; +import WithYou.domain.post.vo.CommentPostVo; import WithYou.global.jwt.MemberPrincipal; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -13,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.Map; + @RestController @RequiredArgsConstructor public class CommentController { @@ -20,12 +24,13 @@ public class CommentController { private final PostService postService; @PostMapping("/comment/regist/{id}") - public ResponseEntity registComment(@AuthenticationPrincipal MemberPrincipal memberPrincipal, + public ResponseEntity registComment(@AuthenticationPrincipal MemberPrincipal memberPrincipal, @RequestBody CommentRegistDto commentRegistDto, @PathVariable Long id) { Post post = postService.findPostAndVerifyMember(id, memberPrincipal.getMember()); commentService.registComment(post, commentRegistDto, memberPrincipal.getMember()); + CommentPostVo resultVo = commentService.createResponseDto(post); return ResponseEntity.ok() - .body(commentRegistDto); + .body(resultVo); } } diff --git a/src/main/java/WithYou/domain/comment/dto/request/CommentRegistDto.java b/src/main/java/WithYou/domain/comment/dto/request/CommentRegistDto.java index 1aea97d..a4e6c9a 100644 --- a/src/main/java/WithYou/domain/comment/dto/request/CommentRegistDto.java +++ b/src/main/java/WithYou/domain/comment/dto/request/CommentRegistDto.java @@ -17,6 +17,7 @@ public Comment of(Member member, Post post) { .userNickName(member.getNickName()) .userMajor(member.getMajor()) .userGrade(member.getGrade()) + .userLevel(member.getLevel()) .post(post) .build(); } diff --git a/src/main/java/WithYou/domain/comment/entity/Comment.java b/src/main/java/WithYou/domain/comment/entity/Comment.java index 1e8b461..a1613f8 100644 --- a/src/main/java/WithYou/domain/comment/entity/Comment.java +++ b/src/main/java/WithYou/domain/comment/entity/Comment.java @@ -29,6 +29,7 @@ public class Comment extends BaseEntity { private String userNickName; private String userMajor; private int userGrade; + private double userLevel; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") private Post post; diff --git a/src/main/java/WithYou/domain/comment/service/CommentService.java b/src/main/java/WithYou/domain/comment/service/CommentService.java index e5b193a..c4f3d27 100644 --- a/src/main/java/WithYou/domain/comment/service/CommentService.java +++ b/src/main/java/WithYou/domain/comment/service/CommentService.java @@ -6,13 +6,18 @@ import WithYou.domain.comment.repository.CommentRepository; import WithYou.domain.member.entity.Member; import WithYou.domain.member.service.MemberService; +import WithYou.domain.post.dto.response.PostLookupDto; import WithYou.domain.post.entity.Post; import WithYou.domain.post.exception.PostNotFoundException; import WithYou.domain.post.repository.PostReporitoy; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; + +import WithYou.domain.post.vo.CommentPostVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; @Service @@ -44,4 +49,11 @@ public List findCommentByPostId(Long id) { private void pluscommentCount(Post post) { post.plusCommentCount(); } + + public CommentPostVo createResponseDto(Post post) { + PostLookupDto lookupDto = PostLookupDto.of(post); + List commentResponseDtos = changeCommentListToDtoList(post.getCommentList()); + CommentPostVo commentPostVo = new CommentPostVo(commentResponseDtos, lookupDto); + return commentPostVo; + } } From fbe7815353037cc3b722403fdb024dd6bdff1d4f Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Fri, 10 Nov 2023 15:06:56 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix=20:=20CommentResponseDto=EC=97=90=20use?= =?UTF-8?q?rLevel=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/dto/response/CommentResponseDto.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/WithYou/domain/comment/dto/response/CommentResponseDto.java b/src/main/java/WithYou/domain/comment/dto/response/CommentResponseDto.java index 2398312..63069b1 100644 --- a/src/main/java/WithYou/domain/comment/dto/response/CommentResponseDto.java +++ b/src/main/java/WithYou/domain/comment/dto/response/CommentResponseDto.java @@ -1,7 +1,9 @@ package WithYou.domain.comment.dto.response; import WithYou.domain.comment.entity.Comment; + import java.time.LocalDateTime; + import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -14,10 +16,11 @@ public class CommentResponseDto { private String userNickName; private String userMajor; private int userGrade; + private double userLevel; private LocalDateTime createdDate; public static CommentResponseDto of(Comment comment) { return new CommentResponseDto(comment.getContent(), comment.getUserNickName(), comment.getUserMajor(), - comment.getUserGrade(), comment.getCreatedDate()); + comment.getUserGrade(), comment.getUserLevel(), comment.getCreatedDate()); } } From c669aec3e3a79ec2072c5a0e761508b5fae95179 Mon Sep 17 00:00:00 2001 From: Wonbin Choi Date: Fri, 10 Nov 2023 16:01:36 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix=20:=20Prompt=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/WithYou/domain/ai/service/ChatGptService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/WithYou/domain/ai/service/ChatGptService.java b/src/main/java/WithYou/domain/ai/service/ChatGptService.java index 2fbfe6f..8b37d26 100644 --- a/src/main/java/WithYou/domain/ai/service/ChatGptService.java +++ b/src/main/java/WithYou/domain/ai/service/ChatGptService.java @@ -45,13 +45,11 @@ public QuestionResponseDto askQuestion(QuestionRequestDto questionRequestDto) { System.out.println("field = " + field); System.out.println("question = " + question); - String promptQuestion = field + "관련 질문이야. " + "다음 내용을 바탕으로 " + question + - "만약 질문에 답을 할 수 없다면 왜 답을 할 수 없는지에 대한 이유를 설명해주고 답변할 수 있는 질문의" + - "대체 표현을 하나 이상 알려줘\n" + ocrResult; + String promptQuestion = field + "관련 질문이야. " + "다음 내용을 바탕으로 " + question + ocrResult; String content = askQuestionGpt(promptQuestion, field); - String promptTitle = "다음 내용에 있는 키워드를 중점으로 간략하게 제목 만들어줘" + content; + String promptTitle = "다음 내용에 있는 키워드를 중점으로 10글자 이내로 제목 한 개만 만들어줘" + content; String title = askQuestionGpt(promptTitle, field); QuestionResponseDto questionResponseDto = new QuestionResponseDto(title, content);