Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Chat-ITC/WithYou
Browse files Browse the repository at this point in the history
  • Loading branch information
YongGoose committed Nov 12, 2023
2 parents 6509286 + c669aec commit 066631c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class ChatGptRequestDto {
private List<Message> 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;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/WithYou/domain/ai/service/ChatGptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,19 +15,22 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequiredArgsConstructor
public class CommentController {
private final CommentService commentService;
private final PostService postService;

@PostMapping("/comment/regist/{id}")
public ResponseEntity<CommentRegistDto> registComment(@AuthenticationPrincipal MemberPrincipal memberPrincipal,
public ResponseEntity<CommentPostVo> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}
1 change: 1 addition & 0 deletions src/main/java/WithYou/domain/comment/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/WithYou/domain/comment/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,4 +49,11 @@ public List<Comment> findCommentByPostId(Long id) {
private void pluscommentCount(Post post) {
post.plusCommentCount();
}

public CommentPostVo createResponseDto(Post post) {
PostLookupDto lookupDto = PostLookupDto.of(post);
List<CommentResponseDto> commentResponseDtos = changeCommentListToDtoList(post.getCommentList());
CommentPostVo commentPostVo = new CommentPostVo(commentResponseDtos, lookupDto);
return commentPostVo;
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/WithYou/domain/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/WithYou/domain/scrap/entity/Scrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +22,7 @@ public class Scrap extends BaseEntity {
private Long postId;

private String title;
@Column(length = 5000)
private String content;
private String imageUrl;

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/WithYou/global/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 066631c

Please sign in to comment.