-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#109
- Loading branch information
Showing
4 changed files
with
88 additions
and
3 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
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
30 changes: 30 additions & 0 deletions
30
...main/java/com/developer/wiki/question/presentation/question/QuestionSearchController.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.developer.wiki.question.presentation.question; | ||
|
||
import com.developer.wiki.oauth.User; | ||
import com.developer.wiki.question.query.application.QuestionSearchService; | ||
import com.developer.wiki.question.query.application.SummaryQuestionResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/questions") | ||
@RequiredArgsConstructor | ||
public class QuestionSearchController { | ||
|
||
private final QuestionSearchService questionSearchService; | ||
|
||
@GetMapping("/search") | ||
public ResponseEntity<Slice<SummaryQuestionResponse>> getSlice( | ||
@AuthenticationPrincipal User currentUser, @RequestParam String keyword, Pageable pageable) { | ||
Slice<SummaryQuestionResponse> summarySlice = questionSearchService.findPage(pageable, | ||
currentUser, keyword); | ||
return ResponseEntity.ok(summarySlice); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/developer/wiki/question/query/application/QuestionSearchService.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.developer.wiki.question.query.application; | ||
|
||
import com.developer.wiki.oauth.User; | ||
import com.developer.wiki.question.command.domain.QuestionSearchRepository; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class QuestionSearchService { | ||
|
||
private final QuestionSearchRepository questionSearchRepository; | ||
|
||
public Slice<SummaryQuestionResponse> findPage(Pageable pageable, | ||
User currentUser, String keyword) { | ||
Long userId = Objects.isNull(currentUser) ? null : currentUser.getId(); | ||
return questionSearchRepository.findPageByUserIdAndKeyword(pageable, userId, keyword); | ||
} | ||
} |