Skip to content

Commit

Permalink
Add api info
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdentarikcan committed Dec 16, 2024
1 parent 9564344 commit 9ee8728
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public ResponseEntity<GenericApiResponse<Map<String, Object>>> searchQuestions(
@RequestParam(required = false) DifficultyLevel difficulty,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "20") int pageSize,
@RequestParam(defaultValue = "recommended") String sort,
@RequestParam(required = false) User currentUser) {
@RequestParam(defaultValue = "recommended") String sortBy,
@RequestParam(defaultValue = "-1") Long currentUserId) {

Page<Question> questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sort, currentUser);
Page<Question> questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sortBy, currentUserId);

List<QuestionSummaryDto> questionSummaries = questionPage.getContent().stream()
.map(QuestionService::mapToQuestionSummary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class QuestionService {
private final TagService tagService;
private final BookmarkRepository bookmarkRepository;
private final VoteRepository voteRepository;
private final UserService userService;
private final QuestionDifficultyRateService questionDifficultyRateService;

public Optional<Question> findById(Long id) {
Expand Down Expand Up @@ -220,8 +221,8 @@ public Page<Question> searchQuestions(
DifficultyLevel difficulty,
int page,
int pageSize,
String sort,
User currentUser) {
String sortBy,
Long currentUserId) {

List<Long> tagIds = null;
if (tagIdsStr != null && !tagIdsStr.isEmpty()) {
Expand All @@ -231,9 +232,10 @@ public Page<Question> searchQuestions(
}

PageRequest pageable = PageRequest.of(page - 1, pageSize);
if (Objects.equals(sort, "default") || Objects.equals(currentUser, null)) {
if (Objects.equals(sortBy, "default") || currentUserId == -1) {
return questionRepository.searchQuestions(query, tagIds, difficulty, pageable);
} else {
User currentUser = userService.getUserById(currentUserId).get();
List<Long> authorIds = currentUser.getFollowing().stream()
.map(User::getId) // Map each User to its ID
.collect(Collectors.toList()); // Collect the IDs into a List
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/services/api/programmingForumComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,20 @@ export type SearchQuestionsQueryParams = {
* @default 20
*/
pageSize?: number;
/**
* Sorting type
*
* @default "recommended"
*/
sortBy: string;
/**
* Current user Id
*
* @default -1
*/
currentUserId?: number;


};

export type SearchQuestionsError = Fetcher.ErrorWrapper<{
Expand Down
12 changes: 12 additions & 0 deletions swagger/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,18 @@ paths:
schema:
type: integer
default: 20
- name: sortBy
in: query
description: Sorting type
schema:
type: string
default: "recommended"
- name: currentUserId
in: query
description: Current user id
schema:
type: integer
default: -1
responses:
"200":
description: Successful response
Expand Down

0 comments on commit 9ee8728

Please sign in to comment.