diff --git a/.gradle/7.2/executionHistory/executionHistory.bin b/.gradle/7.2/executionHistory/executionHistory.bin index 9fe8521b..e58e5b85 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.bin and b/.gradle/7.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.2/executionHistory/executionHistory.lock b/.gradle/7.2/executionHistory/executionHistory.lock index 80f6fee4..73318d0b 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.lock and b/.gradle/7.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.2/fileHashes/fileHashes.bin b/.gradle/7.2/fileHashes/fileHashes.bin index 653b989c..bbb3fa68 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.bin and b/.gradle/7.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.2/fileHashes/fileHashes.lock b/.gradle/7.2/fileHashes/fileHashes.lock index ac4944a9..f210bfa6 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.lock and b/.gradle/7.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.2/fileHashes/resourceHashesCache.bin b/.gradle/7.2/fileHashes/resourceHashesCache.bin index 95fd35e3..a20de939 100644 Binary files a/.gradle/7.2/fileHashes/resourceHashesCache.bin and b/.gradle/7.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 9a8206f1..426dbd1a 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/generated/com/example/just/Dao/QHashTag.java b/src/main/generated/com/example/just/Dao/QHashTag.java index ee8d0420..db048835 100644 --- a/src/main/generated/com/example/just/Dao/QHashTag.java +++ b/src/main/generated/com/example/just/Dao/QHashTag.java @@ -20,12 +20,12 @@ public class QHashTag extends EntityPathBase { public static final QHashTag hashTag = new QHashTag("hashTag"); + public final ListPath hashTagMaps = this.createList("hashTagMaps", HashTagMap.class, QHashTagMap.class, PathInits.DIRECT2); + public final NumberPath id = createNumber("id", Long.class); public final StringPath name = createString("name"); - public final ListPath posts = this.createList("posts", Post.class, QPost.class, PathInits.DIRECT2); - public final NumberPath tagCount = createNumber("tagCount", Long.class); public QHashTag(String variable) { diff --git a/src/main/generated/com/example/just/Dao/QHashTagMap.java b/src/main/generated/com/example/just/Dao/QHashTagMap.java new file mode 100644 index 00000000..1f03d710 --- /dev/null +++ b/src/main/generated/com/example/just/Dao/QHashTagMap.java @@ -0,0 +1,54 @@ +package com.example.just.Dao; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QHashTagMap is a Querydsl query type for HashTagMap + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QHashTagMap extends EntityPathBase { + + private static final long serialVersionUID = -1800252931L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QHashTagMap hashTagMap = new QHashTagMap("hashTagMap"); + + public final QHashTag hashTag; + + public final NumberPath id = createNumber("id", Long.class); + + public final QPost post; + + public QHashTagMap(String variable) { + this(HashTagMap.class, forVariable(variable), INITS); + } + + public QHashTagMap(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QHashTagMap(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QHashTagMap(PathMetadata metadata, PathInits inits) { + this(HashTagMap.class, metadata, inits); + } + + public QHashTagMap(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.hashTag = inits.isInitialized("hashTag") ? new QHashTag(forProperty("hashTag")) : null; + this.post = inits.isInitialized("post") ? new QPost(forProperty("post"), inits.get("post")) : null; + } + +} + diff --git a/src/main/generated/com/example/just/Dao/QPost.java b/src/main/generated/com/example/just/Dao/QPost.java index f849137a..b359a1f5 100644 --- a/src/main/generated/com/example/just/Dao/QPost.java +++ b/src/main/generated/com/example/just/Dao/QPost.java @@ -28,7 +28,7 @@ public class QPost extends EntityPathBase { public final StringPath emoticon = createString("emoticon"); - public final ListPath hashTags = this.createList("hashTags", HashTag.class, QHashTag.class, PathInits.DIRECT2); + public final ListPath hashTagMaps = this.createList("hashTagMaps", HashTagMap.class, QHashTagMap.class, PathInits.DIRECT2); public final ListPath likedMembers = this.createList("likedMembers", Member.class, QMember.class, PathInits.DIRECT2); diff --git a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java index 8d11afb6..9a987b9b 100644 --- a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java @@ -10,7 +10,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-03-06T15:49:26+0900", + date = "2024-03-07T17:11:37+0900", comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" ) @Component diff --git a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java index 0b0c9278..292ff997 100644 --- a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java @@ -10,7 +10,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-03-06T15:49:26+0900", + date = "2024-03-07T17:11:38+0900", comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" ) @Component diff --git a/src/main/java/com/example/just/Controller/CommentController.java b/src/main/java/com/example/just/Controller/CommentController.java index d1bc1d55..8b154d74 100644 --- a/src/main/java/com/example/just/Controller/CommentController.java +++ b/src/main/java/com/example/just/Controller/CommentController.java @@ -57,7 +57,7 @@ public class CommentController { + " \"child\": []\n" + " \"message\": \"입력 완료\"\n" + "}"), - @ApiResponse(responseCode = "404", description = "{\n" + @ApiResponse(responseCode = "400", description = "{\n" + " \"comment_id\": \"\",\n" + " \"comment_create_time\": 0\n" + " \"comment_create_time\": \"\",\n" @@ -109,7 +109,7 @@ public ResponseEntity deleteComment(@PathVariable Long post_id, @PathVar @ApiOperation(value = "댓글 수정") @ApiResponses(value = { @ApiResponse(responseCode = "200",description = "댓글 내용"), - @ApiResponse(responseCode = "404",description = "댓글이 존재하지 않습니다.\n게시물이 존재하지 않습니다.") + @ApiResponse(responseCode = "400",description = "댓글이 존재하지 않습니다.\n게시물이 존재하지 않습니다.") }) @PutMapping("/put/comment/{post_id}/{comment_id}") public ResponseEntity putComment(@PathVariable Long post_id, @PathVariable Long comment_id, diff --git a/src/main/java/com/example/just/Controller/SearchController.java b/src/main/java/com/example/just/Controller/SearchController.java index a94c1811..d045dbbd 100644 --- a/src/main/java/com/example/just/Controller/SearchController.java +++ b/src/main/java/com/example/just/Controller/SearchController.java @@ -32,6 +32,11 @@ public class SearchController { @GetMapping("/get/search/post") @Operation(summary = "게시글 내용 검색", description = "해당 keyword를 content에 포함하는 게시글 검색\n태그검색구현시 추후 변경 가능") + @ApiResponses(value = { + @ApiResponse(responseCode = "400", description = "{\n" + + " \"message\": \"로그인 후 검색가능합니다.\"\n" + + "}") + }) public ResponseEntity getPosts(@RequestParam String keyword,@RequestParam int page, HttpServletRequest request) { return searchService.searchPostContent(request,keyword,page-1); } diff --git a/src/main/java/com/example/just/Dao/HashTag.java b/src/main/java/com/example/just/Dao/HashTag.java index 89b29104..86633925 100644 --- a/src/main/java/com/example/just/Dao/HashTag.java +++ b/src/main/java/com/example/just/Dao/HashTag.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.ArrayList; import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,8 +13,12 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import lombok.Builder; +import lombok.Builder.Default; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Entity @@ -31,14 +36,18 @@ public class HashTag { @Column(name = "tag_count") private Long tagCount; - @ManyToMany() - @JoinTable( - name = "hash_tag_map", - joinColumns = @JoinColumn(name = "hash_tag_id"), - inverseJoinColumns = @JoinColumn(name = "post_id") - ) - @JsonIgnore - @Builder.Default - private List posts = new ArrayList<>(); + @OneToMany(mappedBy = "hashTag", cascade = CascadeType.REMOVE) + private List hashTagMaps = new ArrayList<>(); + + public HashTag() { + } + + public HashTag(String name) { + this.name = name; + } + + public void addHashTagMap(HashTagMap hashTagMap) { + this.hashTagMaps.add(hashTagMap); + } } \ No newline at end of file diff --git a/src/main/java/com/example/just/Dao/HashTagMap.java b/src/main/java/com/example/just/Dao/HashTagMap.java new file mode 100644 index 00000000..fff7c2ff --- /dev/null +++ b/src/main/java/com/example/just/Dao/HashTagMap.java @@ -0,0 +1,36 @@ +package com.example.just.Dao; + +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 lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor +public class HashTagMap { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + @Column(name = "id", nullable = false) + private Long id; + + @ManyToOne + @JoinColumn(name = "post_id") + private Post post; + + @ManyToOne + @JoinColumn(name = "hash_tag_id") + private HashTag hashTag; + + public HashTagMap(HashTag newHashTag, Post p) { + this.hashTag = newHashTag; + this.post = p; + } +} diff --git a/src/main/java/com/example/just/Dao/Post.java b/src/main/java/com/example/just/Dao/Post.java index 33f99e7e..4cd459b8 100644 --- a/src/main/java/com/example/just/Dao/Post.java +++ b/src/main/java/com/example/just/Dao/Post.java @@ -56,16 +56,15 @@ public class Post { @Builder.Default private List likedMembers = new ArrayList<>(); - @Builder.Default - @ManyToMany(mappedBy = "posts") - private List hashTags = new ArrayList<>(); + @OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE) + private List hashTagMaps = new ArrayList<>(); @ManyToOne() @JoinColumn(name = "member_id") //글을쓴 Member_id @JsonIgnore private Member member; - @OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "post", orphanRemoval = true) private List comments = new ArrayList<>(); @Column(name = "blamed_count") private Long blamedCount; @@ -123,7 +122,6 @@ public boolean getSecret() { } public void changePost(PutPostDto postDto, Member member, Post post) { - /* this.post_id = post.getPost_id(); this.member = member; this.setPost_create_time(new Date(System.currentTimeMillis())); @@ -131,16 +129,6 @@ public void changePost(PutPostDto postDto, Member member, Post post) { this.post_picture = postDto.getPost_picture(); this.secret = postDto.getSecret(); this.postContent = postDto.getPost_content(); - this.hash_tag = null; - if (postDto.getHash_tage() != null) { - for (int i = 0; i < postDto.getHash_tage().size(); i++) { - String hashTag_name = postDto.getHash_tage().get(i); - HashTag hashTag = new HashTag(hashTag_name); - addHashTag(hashTag); - } - } - - */ } public List getHashTag() { @@ -155,4 +143,9 @@ public List getHashTag() { */ return array; } + + + public void addHashTagMaps(HashTagMap hashTagMap) { + this.hashTagMaps.add(hashTagMap); + } } \ No newline at end of file diff --git a/src/main/java/com/example/just/Response/ResponseMessage.java b/src/main/java/com/example/just/Response/ResponseMessage.java new file mode 100644 index 00000000..10aaf96d --- /dev/null +++ b/src/main/java/com/example/just/Response/ResponseMessage.java @@ -0,0 +1,13 @@ +package com.example.just.Response; + +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class ResponseMessage { + private String message; + public ResponseMessage(String m){ + message = m; + } +} diff --git a/src/main/java/com/example/just/Service/SearchService.java b/src/main/java/com/example/just/Service/SearchService.java index 7024fc07..912ba9d4 100644 --- a/src/main/java/com/example/just/Service/SearchService.java +++ b/src/main/java/com/example/just/Service/SearchService.java @@ -6,6 +6,7 @@ import com.example.just.Repository.MemberRepository; import com.example.just.Repository.PostContentESRespository; import com.example.just.Repository.PostRepository; +import com.example.just.Response.ResponseMessage; import com.example.just.Response.ResponseSearchDto; import com.example.just.jwt.JwtProvider; import java.util.Comparator; @@ -16,6 +17,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -39,6 +41,9 @@ public class SearchService { public ResponseEntity searchPostContent(HttpServletRequest request,String keyword,int page){ String token = jwtProvider.getAccessToken(request); + if(token == null){ + return new ResponseEntity(new ResponseMessage("로그인 후 검색가능합니다."),null, HttpStatus.BAD_REQUEST); + } Long id = Long.valueOf(jwtProvider.getIdFromToken(token)); //토큰 List blames = blameRepository.findByBlameMemberId(id); //유저가 신고한 게시글 id들