Skip to content

Commit

Permalink
dlp request
Browse files Browse the repository at this point in the history
  • Loading branch information
문준호 authored and 문준호 committed Mar 6, 2024
1 parent ca80471 commit d13cf81
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 80 deletions.
Binary file modified .gradle/7.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main/generated/com/example/just/Dao/QHashTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
Expand All @@ -23,6 +24,8 @@ public class QHashTag extends EntityPathBase<HashTag> {

public final StringPath name = createString("name");

public final ListPath<Post, QPost> posts = this.<Post, QPost>createList("posts", Post.class, QPost.class, PathInits.DIRECT2);

public final NumberPath<Long> tagCount = createNumber("tagCount", Long.class);

public QHashTag(String variable) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/generated/com/example/just/Dao/QPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class QPost extends EntityPathBase<Post> {

public final StringPath emoticon = createString("emoticon");

public final ListPath<Post, QPost> hashTags = this.<Post, QPost>createList("hashTags", Post.class, QPost.class, PathInits.DIRECT2);
public final ListPath<HashTag, QHashTag> hashTags = this.<HashTag, QHashTag>createList("hashTags", HashTag.class, QHashTag.class, PathInits.DIRECT2);

public final ListPath<Member, QMember> likedMembers = this.<Member, QMember>createList("likedMembers", Member.class, QMember.class, PathInits.DIRECT2);

Expand Down
32 changes: 16 additions & 16 deletions src/main/generated/com/example/just/Mapper/MemberMapperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-03-06T13:28:25+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.11 (AdoptOpenJDK)"
date = "2024-03-06T15:49:26+0900",
comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)"
)
@Component
public class MemberMapperImpl implements MemberMapper {

@Override
public Member toEntity(MemberDto arg0) {
if ( arg0 == null ) {
public Member toEntity(MemberDto dto) {
if ( dto == null ) {
return null;
}

Member.MemberBuilder member = Member.builder();

member.id( arg0.getId() );
member.email( arg0.getEmail() );
member.provider( arg0.getProvider() );
member.provider_id( arg0.getProvider_id() );
List<Post> list = arg0.getPosts();
member.id( dto.getId() );
member.email( dto.getEmail() );
member.provider( dto.getProvider() );
member.provider_id( dto.getProvider_id() );
List<Post> list = dto.getPosts();
if ( list != null ) {
member.posts( new ArrayList<Post>( list ) );
}
Expand All @@ -37,18 +37,18 @@ public Member toEntity(MemberDto arg0) {
}

@Override
public MemberDto toDto(Member arg0) {
if ( arg0 == null ) {
public MemberDto toDto(Member entity) {
if ( entity == null ) {
return null;
}

MemberDto.MemberDtoBuilder memberDto = MemberDto.builder();

memberDto.id( arg0.getId() );
memberDto.email( arg0.getEmail() );
memberDto.provider( arg0.getProvider() );
memberDto.provider_id( arg0.getProvider_id() );
List<Post> list = arg0.getPosts();
memberDto.id( entity.getId() );
memberDto.email( entity.getEmail() );
memberDto.provider( entity.getProvider() );
memberDto.provider_id( entity.getProvider_id() );
List<Post> list = entity.getPosts();
if ( list != null ) {
memberDto.posts( new ArrayList<Post>( list ) );
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/generated/com/example/just/Mapper/PostMapperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-03-06T13:28:25+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.11 (AdoptOpenJDK)"
date = "2024-03-06T15:49:26+0900",
comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)"
)
@Component
public class PostMapperImpl implements PostMapper {

@Override
public Post toEntity(PutPostDto arg0) {
if ( arg0 == null ) {
public Post toEntity(PutPostDto dto) {
if ( dto == null ) {
return null;
}

Post.PostBuilder post = Post.builder();

post.post_id( arg0.getPost_id() );
post.post_picture( arg0.getPost_picture() );
post.post_create_time( arg0.getPost_create_time() );
post.secret( arg0.getSecret() );
post.member( arg0.getMember() );
List<Comment> list = arg0.getComments();
post.post_id( dto.getPost_id() );
post.post_picture( dto.getPost_picture() );
post.post_create_time( dto.getPost_create_time() );
post.secret( dto.getSecret() );
post.member( dto.getMember() );
List<Comment> list = dto.getComments();
if ( list != null ) {
post.comments( new ArrayList<Comment>( list ) );
}
Expand All @@ -38,19 +38,19 @@ public Post toEntity(PutPostDto arg0) {
}

@Override
public PutPostDto toDto(Post arg0) {
if ( arg0 == null ) {
public PutPostDto toDto(Post entity) {
if ( entity == null ) {
return null;
}

PutPostDto putPostDto = new PutPostDto();

putPostDto.setPost_id( arg0.getPost_id() );
putPostDto.setPost_picture( arg0.getPost_picture() );
putPostDto.setPost_create_time( arg0.getPost_create_time() );
putPostDto.setSecret( arg0.getSecret() );
putPostDto.setMember( arg0.getMember() );
List<Comment> list = arg0.getComments();
putPostDto.setPost_id( entity.getPost_id() );
putPostDto.setPost_picture( entity.getPost_picture() );
putPostDto.setPost_create_time( entity.getPost_create_time() );
putPostDto.setSecret( entity.getSecret() );
putPostDto.setMember( entity.getMember() );
List<Comment> list = entity.getComments();
if ( list != null ) {
putPostDto.setComments( new ArrayList<Comment>( list ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.example.just.Dao.Member;
import com.example.just.Dao.Post;
import com.example.just.Document.PostDocument;
import com.example.just.Document.PostDocument.PostDocumentBuilder;
import com.example.just.Service.SearchService;
import com.example.just.jwt.JwtProvider;
import io.swagger.annotations.Api;
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/example/just/Dao/HashTag.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.example.just.Dao;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class HashTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -28,7 +31,14 @@ public class HashTag {
@Column(name = "tag_count")
private Long tagCount;

public HashTag(String name) {
this.name = name;
}
@ManyToMany()
@JoinTable(
name = "hash_tag_map",
joinColumns = @JoinColumn(name = "hash_tag_id"),
inverseJoinColumns = @JoinColumn(name = "post_id")
)
@JsonIgnore
@Builder.Default
private List<Post> posts = new ArrayList<>();

}
17 changes: 2 additions & 15 deletions src/main/java/com/example/just/Dao/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ public class Post {
@Builder.Default
private List<Member> likedMembers = new ArrayList<>();

@ManyToMany()
@JoinTable(
name = "hash_tag_map",
joinColumns = @JoinColumn(name = "hash_tag_id"),
inverseJoinColumns = @JoinColumn(name = "post_id")
)
@JsonIgnore
@Builder.Default
private List<Post> hashTags = new ArrayList<>();
@ManyToMany(mappedBy = "posts")
private List<HashTag> hashTags = new ArrayList<>();

@ManyToOne()
@JoinColumn(name = "member_id") //글을쓴 Member_id
Expand All @@ -86,13 +80,6 @@ public void prePersist() {
public void writePost(PostPostDto postDto, Member member) { // 글 쓰기 생성자
List<String> contentList = postDto.getPost_content();
this.postContent = contentList;
if (postDto.getHash_tag() != null) {
for (int i = 0; i < postDto.getHash_tag().size(); i++) {
String hashTag_name = postDto.getHash_tag().get(i);
HashTag hashTag = new HashTag(hashTag_name);

}
}
this.post_picture = postDto.getPost_picture();
this.secret = postDto.getSecret();
this.emoticon = "";
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/example/just/Document/HasgTagDocument.java

This file was deleted.

54 changes: 54 additions & 0 deletions src/main/java/com/example/just/Service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@
import com.example.just.Repository.PostRepository;

import com.example.just.jwt.JwtProvider;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.*;
import java.util.stream.Collectors;
import org.springframework.web.client.RestTemplate;


@Service
Expand Down Expand Up @@ -95,6 +106,11 @@ public PostPostDto write(Long member_id, PostPostDto postDto) { //글 작성
List<String> tag = gptService.getTag(gptRequestDto);
postDto.setHash_tag(tag);
}
List<String> content = new ArrayList<>();
for(int i = 0; i<postDto.getPost_content().size();i++){
content.add(getConvertString(postDto.getPost_content().get(i)));
}
postDto.setPost_content(content);
post.writePost(postDto, member);
Post p = postRepository.save(post);
postContentESRespository.save(new PostDocument(p));
Expand Down Expand Up @@ -123,6 +139,11 @@ public ResponsePutPostDto putPost(Long member_id, PutPostDto postDto) throws Not
// for (int i = 0; i < hashTags.size(); i++) {
// hashTagRepository.deleteById(hashTags.get(i).getId());
// }
List<String> content = new ArrayList<>();
for(int i = 0; i<postDto.getPost_content().size();i++){
content.add(getConvertString(postDto.getPost_content().get(i)));
}
postDto.setPost_content(content);
checkPost.changePost(postDto, member, checkPost);
postContentESRespository.save(new PostDocument(checkPost));
postRepository.save(checkPost);
Expand Down Expand Up @@ -293,4 +314,37 @@ public List<ResponseGetMemberPostDto> getLikeMemberPost(Long member_id) throws N
List<ResponseGetMemberPostDto> getPostDtos = createResponseGetMemberPostDto(results, member_id);
return getPostDtos;
}

public String getConvertString(String str){
RestTemplate restTemplate = new RestTemplate();

String requestBody = "{\"question\":\"" + str + "\",\"deny_list\":[\"string\"]}";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

HttpEntity<String> request = new HttpEntity<>(requestBody,headers);

ResponseEntity<String> responseEntity = restTemplate.exchange(
"http://203.241.228.51:8000/anonymize/",
HttpMethod.POST,
request,
String.class);

String responseBody = responseEntity.getBody();
String convertStr =parsingJson(responseBody);
return convertStr;
}

public String parsingJson(String json){
String response;
try {
JSONParser parser = new JSONParser();
JSONObject elem = (JSONObject) parser.parse(json);
response = elem.get("convertedQuestion").toString();
} catch (ParseException e) {
throw new RuntimeException(e);
}
return response;
}
}

0 comments on commit d13cf81

Please sign in to comment.