Skip to content

Commit

Permalink
Auto tag pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
문준호 authored and 문준호 committed Mar 14, 2024
1 parent 246663c commit 1873eda
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 12 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.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-03-13T13:37:51+0900",
date = "2024-03-14T18:31:05+0900",
comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-03-13T13:37:51+0900",
date = "2024-03-14T18:31:05+0900",
comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)"
)
@Component
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/example/just/Controller/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class SearchController {
@GetMapping("/get/search/post")
@Operation(summary = "게시글 내용 검색", description = "해당 keyword를 content에 포함하는 게시글 검색\n태그검색구현시 추후 변경 가능")
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "{\n"
+ " \"message\": \"로그인 후 검색가능합니다.\"\n"
@ApiResponse(responseCode = "404", description = "{\n"
+ " \"message\": \"로그인 후 검색가능합니다.\", \"페이지를 초과하엿습니다.\"\n"
+ "}")
})
public ResponseEntity getPosts(@RequestParam String keyword,@RequestParam int page, HttpServletRequest request) {
Expand All @@ -44,8 +44,8 @@ public ResponseEntity getPosts(@RequestParam String keyword,@RequestParam int pa
@GetMapping("/get/search/tag")
@Operation(summary = "태그로 게시 검색", description = "해당 태그와 일치하는 값을 가진 게시글 검색\n")
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "{\n"
+ " \"message\": \"로그인 후 검색가능합니다.\"\n"
@ApiResponse(responseCode = "404", description = "{\n"
+ " \"message\": \"로그인 후 검색가능합니다.\", \"페이지를 초과하엿습니다.\"\n"
+ "}")
})
public ResponseEntity getTagPost(@RequestParam String keyword,@RequestParam int page, HttpServletRequest request) {
Expand All @@ -54,7 +54,12 @@ public ResponseEntity getTagPost(@RequestParam String keyword,@RequestParam int

@GetMapping("/get/search/auto/tag")
@Operation(summary = "태그 자동완성", description = "해당 keyword를 포함하는 태그 전체 검색\n 자음만으로는 검색불가무조건 모음까지 합친 글자로만 검색가능\n ex) ㅇ -> 검색불가\n 연-> 연애,연구")
public ResponseEntity getAutoTag(@RequestParam(required = false, defaultValue = "") String keyword) {
return searchService.getAutoTag(keyword);
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "{\n"
+ " \"message\": \"태그가 존재하지 않습니다.\", \"페이지를 초과하엿습니다.\"\n"
+ "}")
})
public ResponseEntity getAutoTag(@RequestParam(required = false, defaultValue = "") String keyword,@RequestParam int page) {
return searchService.getAutoTag(keyword,page-1);
}
}
20 changes: 16 additions & 4 deletions src/main/java/com/example/just/Service/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,32 @@ public ResponseEntity searchPostContent(HttpServletRequest request,String keywor
PageRequest pageRequest = PageRequest.of(page,10);
result.sort(Comparator.comparing(ResponseSearchDto::getPost_create_time).reversed());
int start = (int) pageRequest.getOffset();
if (start >= result.size()) {
return new ResponseEntity(new ResponseMessage("페이지를 초과하엿습니다."),null,HttpStatus.BAD_REQUEST);
}
int end = Math.min((start + pageRequest.getPageSize()),result.size());
Page<ResponseSearchDto> postPage = new PageImpl<>(result.subList(start,end), pageRequest, result.size());
return ResponseEntity.ok(postPage);
}

public ResponseEntity getAutoTag(String str){
public ResponseEntity getAutoTag(String str,int page){
List<HashTagDocument> hashTagDocuments = new ArrayList<HashTagDocument>();
if(str.equals("") || str.equals(null)){
hashTagDocuments = hashTagESRepository.findAll(Sort.by(Direction.DESC,"tagCount"));
}else {
hashTagDocuments = hashTagESRepository.findByNameContaining(str,Sort.by(Direction.DESC,"tagCount"));
}
if(hashTagDocuments.equals(null)) {
return new ResponseEntity(new ResponseMessage("태그 없음"), null, HttpStatus.BAD_REQUEST);
return new ResponseEntity(new ResponseMessage("태그가 존재하지 않습니다."), null, HttpStatus.BAD_REQUEST);
}
PageRequest pageRequest = PageRequest.of(page,10);
int start = (int) pageRequest.getOffset();
if (start >= hashTagDocuments.size()) {
return new ResponseEntity(new ResponseMessage("페이지를 초과하엿습니다."),null,HttpStatus.BAD_REQUEST);
}
System.out.println(hashTagDocuments.size());
return ResponseEntity.ok(hashTagDocuments);
int end = Math.min((start + pageRequest.getPageSize()),hashTagDocuments.size());
Page<HashTagDocument> postPage = new PageImpl<>(hashTagDocuments.subList(start,end), pageRequest, hashTagDocuments.size());
return ResponseEntity.ok(postPage);
}

public ResponseEntity searchTagPost(HttpServletRequest request,String tag,int page){
Expand Down Expand Up @@ -126,6 +135,9 @@ public ResponseEntity searchTagPost(HttpServletRequest request,String tag,int pa
PageRequest pageRequest = PageRequest.of(page,10);
result.sort(Comparator.comparing(ResponseSearchDto::getPost_create_time).reversed());//최신순 조회
int start = (int) pageRequest.getOffset();
if (start >= result.size()) {
return new ResponseEntity(new ResponseMessage("페이지를 초과하엿습니다."),null,HttpStatus.BAD_REQUEST);
}
int end = Math.min((start + pageRequest.getPageSize()),result.size());
Page<ResponseSearchDto> postPage = new PageImpl<>(result.subList(start,end), pageRequest, result.size());
return ResponseEntity.ok(postPage);
Expand Down

0 comments on commit 1873eda

Please sign in to comment.