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..8b37d26 100644 --- a/src/main/java/WithYou/domain/ai/service/ChatGptService.java +++ b/src/main/java/WithYou/domain/ai/service/ChatGptService.java @@ -45,21 +45,19 @@ 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); 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/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/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()); } } 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; + } } 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; 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; diff --git a/src/main/java/WithYou/global/config/WebSecurityConfig.java b/src/main/java/WithYou/global/config/WebSecurityConfig.java index c352e82..b0c2416 100644 --- a/src/main/java/WithYou/global/config/WebSecurityConfig.java +++ b/src/main/java/WithYou/global/config/WebSecurityConfig.java @@ -11,9 +11,8 @@ 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", "http://10.114.10.15:3000" + ,"http://192.168.0.26:3000") // 허용할 도메인(Origin)을 명시적으로 지정 .allowedHeaders("*") .exposedHeaders("accessToken", "refreshToken", "validation") .allowedMethods(