-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: search condition & paging count 추가 및 최적화 적용 (#5)
포함하지 않았던 count query를 repository에서 계산 후 서비스가 사용
- Loading branch information
Showing
6 changed files
with
139 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 64 additions & 64 deletions
128
src/main/java/com/api/TaveShot/domain/Post/controller/PostIndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
package com.api.TaveShot.domain.Post.controller; | ||
|
||
import com.api.TaveShot.domain.Post.dto.PostDto; | ||
import com.api.TaveShot.domain.Post.service.PostService; | ||
import com.api.TaveShot.global.util.SecurityUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class PostIndexController { | ||
|
||
private final PostService postService; | ||
|
||
@GetMapping("/postlist") | ||
public ResponseEntity<Page<PostDto.Response>> index(@PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) { | ||
Page<PostDto.Response> list = postService.pageList(pageable); | ||
return ResponseEntity.ok(list); | ||
} | ||
|
||
@GetMapping("/post/read/{id}") | ||
public ResponseEntity<PostDto.Response> read(@PathVariable Long id) { | ||
PostDto.Response dto = postService.findById(id); | ||
return ResponseEntity.ok(dto); | ||
} | ||
|
||
@GetMapping("/post/write") | ||
public ResponseEntity<String> write() { | ||
// 현재 로그인한 사용자의 gitLoginId 가져오기 | ||
String currentUserId = SecurityUtil.getCurrentMember().getGitLoginId(); | ||
return ResponseEntity.ok(currentUserId); | ||
} | ||
|
||
@GetMapping("/post/update/{id}") | ||
public ResponseEntity<PostDto.Response> update(@PathVariable Long id) { | ||
PostDto.Response dto = postService.findById(id); | ||
|
||
// 현재 로그인한 사용자의 gitLoginId 가져오기 | ||
String currentUserId = SecurityUtil.getCurrentMember().getGitLoginId(); | ||
|
||
// 게시글 작성자의 아이디 | ||
String writerId = dto.getWriterId().toString(); | ||
|
||
// 현재 로그인한 사용자와 게시글 작성자를 비교하여 권한 확인 | ||
if (currentUserId.equals(writerId)) { | ||
return ResponseEntity.ok(dto); | ||
} else { | ||
return ResponseEntity.status(403).build(); | ||
} | ||
} | ||
|
||
@GetMapping("/post/search") | ||
public ResponseEntity<Page<PostDto.Response>> search(@RequestParam String keyword, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) { | ||
Page<PostDto.Response> searchList = postService.search(keyword, pageable); | ||
return ResponseEntity.ok(searchList); | ||
} | ||
} | ||
//package com.api.TaveShot.domain.Post.controller; | ||
// | ||
//import com.api.TaveShot.domain.Post.dto.PostDto; | ||
//import com.api.TaveShot.domain.Post.service.PostService; | ||
//import com.api.TaveShot.global.util.SecurityUtil; | ||
//import lombok.RequiredArgsConstructor; | ||
//import org.springframework.data.domain.Page; | ||
//import org.springframework.data.domain.Pageable; | ||
//import org.springframework.data.domain.Sort; | ||
//import org.springframework.data.web.PageableDefault; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.web.bind.annotation.*; | ||
// | ||
// | ||
//@RestController | ||
//@RequestMapping("/api/v1") | ||
//@RequiredArgsConstructor | ||
//public class PostIndexController { | ||
// | ||
// private final PostService postService; | ||
// | ||
// @GetMapping("/postlist") | ||
// public ResponseEntity<Page<PostDto.Response>> index(@PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) { | ||
// Page<PostDto.Response> list = postService.pageList(pageable); | ||
// return ResponseEntity.ok(list); | ||
// } | ||
// | ||
// @GetMapping("/post/read/{id}") | ||
// public ResponseEntity<PostDto.Response> read(@PathVariable Long id) { | ||
// PostDto.Response dto = postService.findById(id); | ||
// return ResponseEntity.ok(dto); | ||
// } | ||
// | ||
// @GetMapping("/post/write") | ||
// public ResponseEntity<String> write() { | ||
// // 현재 로그인한 사용자의 gitLoginId 가져오기 | ||
// String currentUserId = SecurityUtil.getCurrentMember().getGitLoginId(); | ||
// return ResponseEntity.ok(currentUserId); | ||
// } | ||
// | ||
// @GetMapping("/post/update/{id}") | ||
// public ResponseEntity<PostDto.Response> update(@PathVariable Long id) { | ||
// PostDto.Response dto = postService.findById(id); | ||
// | ||
// // 현재 로그인한 사용자의 gitLoginId 가져오기 | ||
// String currentUserId = SecurityUtil.getCurrentMember().getGitLoginId(); | ||
// | ||
// // 게시글 작성자의 아이디 | ||
// String writerId = dto.getWriterId().toString(); | ||
// | ||
// // 현재 로그인한 사용자와 게시글 작성자를 비교하여 권한 확인 | ||
// if (currentUserId.equals(writerId)) { | ||
// return ResponseEntity.ok(dto); | ||
// } else { | ||
// return ResponseEntity.status(403).build(); | ||
// } | ||
// } | ||
// | ||
// @GetMapping("/post/search") | ||
// public ResponseEntity<Page<PostDto.Response>> search(@RequestParam String keyword, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) { | ||
// Page<PostDto.Response> searchList = postService.search(keyword, pageable); | ||
// return ResponseEntity.ok(searchList); | ||
// } | ||
//} |
12 changes: 5 additions & 7 deletions
12
...ot/domain/Post/domain/PostRepository.java → ...omain/Post/repository/PostRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
src/main/java/com/api/TaveShot/domain/Post/repository/PostRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package com.api.TaveShot.domain.Post.repository; | ||
|
||
import com.api.TaveShot.domain.Post.dto.PostListResponse; | ||
import com.api.TaveShot.domain.Post.dto.PostResponse; | ||
import com.api.TaveShot.domain.Post.dto.PostSearchCondition; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface PostRepositoryCustom { | ||
List<PostResponse> searchPagePost(PostSearchCondition condition, Pageable pageable); | ||
// List<PostResponse> searchPagePost(PostSearchCondition condition, Pageable pageable); | ||
|
||
// Long searchCountPost(PostSearchCondition condition, Pageable pageable); | ||
|
||
Page<PostResponse> searchPagePost(PostSearchCondition condition, Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters