From e9cfbe311050b64b32c7941247b71251cf9d0b86 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 10:59:32 +0300 Subject: [PATCH 1/9] Add recommendation query --- .../Repositories/QuestionRepository.java | 16 ++++++++++++++++ .../Services/QuestionService.java | 12 ++++++++++-- .../Services/UserService.java | 6 ++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Repositories/QuestionRepository.java b/backend/src/main/java/com/group1/programminglanguagesforum/Repositories/QuestionRepository.java index 42120529..58c541d2 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Repositories/QuestionRepository.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Repositories/QuestionRepository.java @@ -31,6 +31,22 @@ Page searchQuestions( @Param("difficulty") DifficultyLevel difficulty, Pageable pageable); + @Query("SELECT DISTINCT q FROM Question q " + + "LEFT JOIN q.tags t " + + "WHERE (:query IS NULL OR " + + " LOWER(q.title) LIKE LOWER(CONCAT('%', :query, '%')) OR " + + " LOWER(q.questionBody) LIKE LOWER(CONCAT('%', :query, '%'))) " + + "AND (:tagIds IS NULL OR t.id IN :tagIds) " + + "AND (:difficulty IS NULL OR q.difficulty = :difficulty) " + + "ORDER BY " + + " CASE WHEN :authorIds IS NOT NULL AND q.askedBy.id IN :authorIds THEN 1 ELSE 0 END DESC") + Page searchQuestionsByRecommended( + @Param("query") String query, + @Param("authorIds") List authorIds, + @Param("tagIds") List tagIds, + @Param("difficulty") DifficultyLevel difficulty, + Pageable pageable); + @Query("SELECT q FROM Question q WHERE q.askedBy.id = :author") List findByAuthorId(@Param("author") Long authorId); diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index 6db81f66..a9613530 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -218,7 +218,9 @@ public Page searchQuestions( String tagIdsStr, DifficultyLevel difficulty, int page, - int pageSize) { + int pageSize, + String sort, + User currentUser) { List tagIds = null; if (tagIdsStr != null && !tagIdsStr.isEmpty()) { @@ -228,7 +230,13 @@ public Page searchQuestions( } PageRequest pageable = PageRequest.of(page - 1, pageSize); - return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); + if (Objects.equals(sort, "default") || Objects.equals(currentUser, null)) { + return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); + } else { + List authorIds = getFollowingIds(currentUser); + return questionRepository.searchQuestionsByRecommended(query, authorIds, tagIds, difficulty, pageable); + } + } public static QuestionSummaryDto mapToQuestionSummary(Question question) { diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java index 646ba34e..3fe8307c 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java @@ -107,4 +107,10 @@ public Page searchUsers(String query, int page, int pageSize) { public List getFollowing(User user) { return user.getFollowing().stream().toList(); } + + public List getFollowingIds(User user) { + return user.getFollowing().stream() + .map(User::getId) // Map each User to its ID + .collect(Collectors.toList()); // Collect the IDs into a List + } } From 95643445d8d9d01a2871916405a2772f4d82400d Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 11:10:35 +0300 Subject: [PATCH 2/9] Resolve import issues --- .../Controllers/QuestionController.java | 7 +++++-- .../Services/QuestionService.java | 5 ++++- .../programminglanguagesforum/Services/UserService.java | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java index 352590c0..f0ad2b7d 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java @@ -31,6 +31,7 @@ import com.group1.programminglanguagesforum.DTOs.Responses.QuestionSummaryDto; import com.group1.programminglanguagesforum.Entities.DifficultyLevel; import com.group1.programminglanguagesforum.Entities.Question; +import com.group1.programminglanguagesforum.Entities.User; import com.group1.programminglanguagesforum.Exceptions.ExceptionResponseHandler; import com.group1.programminglanguagesforum.Exceptions.UnauthorizedAccessException; import com.group1.programminglanguagesforum.Services.QuestionDifficultyRateService; @@ -123,9 +124,11 @@ public ResponseEntity>> searchQuestions( @RequestParam(required = false) String tags, @RequestParam(required = false) DifficultyLevel difficulty, @RequestParam(defaultValue = "1") int page, - @RequestParam(defaultValue = "20") int pageSize) { + @RequestParam(defaultValue = "20") int pageSize, + @RequestParam(defaultValue = "recommended") String sort, + @RequestParam(required = false) User currentUser) { - Page questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize); + Page questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sort, currentUser); List questionSummaries = questionPage.getContent().stream() .map(QuestionService::mapToQuestionSummary) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index a9613530..e546aa59 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -10,6 +10,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.Objects; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -233,7 +234,9 @@ public Page searchQuestions( if (Objects.equals(sort, "default") || Objects.equals(currentUser, null)) { return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); } else { - List authorIds = getFollowingIds(currentUser); + List authorIds = currentUser.getFollowing().stream() + .map(User::getId) // Map each User to its ID + .collect(Collectors.toList()); // Collect the IDs into a List return questionRepository.searchQuestionsByRecommended(query, authorIds, tagIds, difficulty, pageable); } diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java index 3fe8307c..46e18d54 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor From 9ee87282a8671da4cf36acda3ca7239eab0393d1 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 13:06:59 +0300 Subject: [PATCH 3/9] Add api info --- .../Controllers/QuestionController.java | 6 +++--- .../Services/QuestionService.java | 8 +++++--- .../src/services/api/programmingForumComponents.ts | 14 ++++++++++++++ swagger/openapi.yml | 12 ++++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java index f0ad2b7d..5304b0c0 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java @@ -125,10 +125,10 @@ public ResponseEntity>> 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 questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sort, currentUser); + Page questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sortBy, currentUserId); List questionSummaries = questionPage.getContent().stream() .map(QuestionService::mapToQuestionSummary) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index e546aa59..2d88d4f4 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -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 findById(Long id) { @@ -220,8 +221,8 @@ public Page searchQuestions( DifficultyLevel difficulty, int page, int pageSize, - String sort, - User currentUser) { + String sortBy, + Long currentUserId) { List tagIds = null; if (tagIdsStr != null && !tagIdsStr.isEmpty()) { @@ -231,9 +232,10 @@ public Page 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 authorIds = currentUser.getFollowing().stream() .map(User::getId) // Map each User to its ID .collect(Collectors.toList()); // Collect the IDs into a List diff --git a/frontend/src/services/api/programmingForumComponents.ts b/frontend/src/services/api/programmingForumComponents.ts index 63141bb8..490f4b48 100644 --- a/frontend/src/services/api/programmingForumComponents.ts +++ b/frontend/src/services/api/programmingForumComponents.ts @@ -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<{ diff --git a/swagger/openapi.yml b/swagger/openapi.yml index c5f3a194..86ed232c 100644 --- a/swagger/openapi.yml +++ b/swagger/openapi.yml @@ -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 From 0cb47524cd7fa775ac8d5ce4faaba38e8cc5187d Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 13:42:58 +0300 Subject: [PATCH 4/9] Integrate with frontend --- frontend/src/components/SearchBar.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index ac352793..2f8efd71 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -2,6 +2,7 @@ import { Hash, MessageSquare, Search } from "lucide-react"; import { useEffect, useId, useRef, useState } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import { Button } from "./ui/button"; +import useAuthStore from "@/services/auth"; import { DropdownMenu, DropdownMenuContent, @@ -23,6 +24,7 @@ const searchTypes = [ { id: "questions", label: "Questions", icon: MessageSquare }, ] as const; + export const SearchBar = () => { const id = useId(); const [params] = useSearchParams(); @@ -35,6 +37,8 @@ export const SearchBar = () => { const inputRef = useRef(null); const navigate = useNavigate(); + const { selfProfile } = useAuthStore(); + // Get current search type info const currentSearchType = searchTypes.find((type) => type.id === searchType); const SearchTypeIcon = currentSearchType?.icon || Hash; @@ -97,6 +101,10 @@ export const SearchBar = () => { const params = new URLSearchParams(); params.append("type", searchType); params.append("q", search); + // Safely append currentUserId only if selfProfile is available + if (selfProfile?.id) { + params.append("currentUserId", selfProfile.id.toString()); + } navigate("/search?" + params.toString()); }; From c8d0bb05de1343d8e864a3f6ff12fb1fb36c41d1 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 13:48:08 +0300 Subject: [PATCH 5/9] Add sortBy to parameters --- frontend/src/components/SearchBar.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index 2f8efd71..8260bfe7 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -105,6 +105,7 @@ export const SearchBar = () => { if (selfProfile?.id) { params.append("currentUserId", selfProfile.id.toString()); } + params.append("sortBy", "recommended"); navigate("/search?" + params.toString()); }; From 44e34535af570b86a3726ef7b12350335e9fb9b7 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 13:53:12 +0300 Subject: [PATCH 6/9] Fix sortBy --- frontend/src/services/api/programmingForumComponents.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/services/api/programmingForumComponents.ts b/frontend/src/services/api/programmingForumComponents.ts index 490f4b48..16a6d8b4 100644 --- a/frontend/src/services/api/programmingForumComponents.ts +++ b/frontend/src/services/api/programmingForumComponents.ts @@ -1983,15 +1983,13 @@ export type SearchQuestionsQueryParams = { * * @default "recommended" */ - sortBy: string; + sortBy?: string; /** * Current user Id * * @default -1 */ currentUserId?: number; - - }; export type SearchQuestionsError = Fetcher.ErrorWrapper<{ From 5acc44ca369416e6f65643c7ac2f2ac1039ce454 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 15:42:05 +0300 Subject: [PATCH 7/9] Get User from UserContextService --- .../Controllers/QuestionController.java | 6 ++---- .../Services/QuestionService.java | 14 +++++++++----- .../Services/UserService.java | 6 ------ frontend/src/components/SearchBar.tsx | 8 -------- .../src/services/api/programmingForumComponents.ts | 10 ++-------- .../src/services/api/programmingForumSchemas.ts | 2 +- swagger/openapi.yml | 8 +------- 7 files changed, 15 insertions(+), 39 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java index 5304b0c0..96ed50ad 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/QuestionController.java @@ -31,7 +31,6 @@ import com.group1.programminglanguagesforum.DTOs.Responses.QuestionSummaryDto; import com.group1.programminglanguagesforum.Entities.DifficultyLevel; import com.group1.programminglanguagesforum.Entities.Question; -import com.group1.programminglanguagesforum.Entities.User; import com.group1.programminglanguagesforum.Exceptions.ExceptionResponseHandler; import com.group1.programminglanguagesforum.Exceptions.UnauthorizedAccessException; import com.group1.programminglanguagesforum.Services.QuestionDifficultyRateService; @@ -125,10 +124,9 @@ public ResponseEntity>> searchQuestions( @RequestParam(required = false) DifficultyLevel difficulty, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int pageSize, - @RequestParam(defaultValue = "recommended") String sortBy, - @RequestParam(defaultValue = "-1") Long currentUserId) { + @RequestParam(defaultValue = "recommended") String sortBy) { - Page questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sortBy, currentUserId); + Page questionPage = questionService.searchQuestions(query, tags, difficulty, page, pageSize, sortBy); List questionSummaries = questionPage.getContent().stream() .map(QuestionService::mapToQuestionSummary) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index 2d88d4f4..e4bc9b81 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -43,7 +43,6 @@ 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 findById(Long id) { @@ -221,8 +220,7 @@ public Page searchQuestions( DifficultyLevel difficulty, int page, int pageSize, - String sortBy, - Long currentUserId) { + String sortBy) { List tagIds = null; if (tagIdsStr != null && !tagIdsStr.isEmpty()) { @@ -230,12 +228,18 @@ public Page searchQuestions( .map(Long::parseLong) .collect(Collectors.toList()); } + User currentUser; + try { + currentUser = userContextService.getCurrentUser(); + } catch (UnauthorizedAccessException e) { + currentUser = null; + } PageRequest pageable = PageRequest.of(page - 1, pageSize); - if (Objects.equals(sortBy, "default") || currentUserId == -1) { + if (Objects.equals(sortBy, "default") || Objects.equals(currentUser, null)) { return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); } else { - User currentUser = userService.getUserById(currentUserId).get(); + List authorIds = currentUser.getFollowing().stream() .map(User::getId) // Map each User to its ID .collect(Collectors.toList()); // Collect the IDs into a List diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java index 46e18d54..118f6a23 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/UserService.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -109,9 +108,4 @@ public List getFollowing(User user) { return user.getFollowing().stream().toList(); } - public List getFollowingIds(User user) { - return user.getFollowing().stream() - .map(User::getId) // Map each User to its ID - .collect(Collectors.toList()); // Collect the IDs into a List - } } diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index 8260bfe7..5ef44760 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -2,7 +2,6 @@ import { Hash, MessageSquare, Search } from "lucide-react"; import { useEffect, useId, useRef, useState } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import { Button } from "./ui/button"; -import useAuthStore from "@/services/auth"; import { DropdownMenu, DropdownMenuContent, @@ -24,7 +23,6 @@ const searchTypes = [ { id: "questions", label: "Questions", icon: MessageSquare }, ] as const; - export const SearchBar = () => { const id = useId(); const [params] = useSearchParams(); @@ -37,8 +35,6 @@ export const SearchBar = () => { const inputRef = useRef(null); const navigate = useNavigate(); - const { selfProfile } = useAuthStore(); - // Get current search type info const currentSearchType = searchTypes.find((type) => type.id === searchType); const SearchTypeIcon = currentSearchType?.icon || Hash; @@ -101,10 +97,6 @@ export const SearchBar = () => { const params = new URLSearchParams(); params.append("type", searchType); params.append("q", search); - // Safely append currentUserId only if selfProfile is available - if (selfProfile?.id) { - params.append("currentUserId", selfProfile.id.toString()); - } params.append("sortBy", "recommended"); navigate("/search?" + params.toString()); }; diff --git a/frontend/src/services/api/programmingForumComponents.ts b/frontend/src/services/api/programmingForumComponents.ts index 16a6d8b4..b05bc956 100644 --- a/frontend/src/services/api/programmingForumComponents.ts +++ b/frontend/src/services/api/programmingForumComponents.ts @@ -1980,16 +1980,10 @@ export type SearchQuestionsQueryParams = { pageSize?: number; /** * Sorting type - * - * @default "recommended" + * + * @default recommended */ sortBy?: string; - /** - * Current user Id - * - * @default -1 - */ - currentUserId?: number; }; export type SearchQuestionsError = Fetcher.ErrorWrapper<{ diff --git a/frontend/src/services/api/programmingForumSchemas.ts b/frontend/src/services/api/programmingForumSchemas.ts index 59344b8f..4080d5ec 100644 --- a/frontend/src/services/api/programmingForumSchemas.ts +++ b/frontend/src/services/api/programmingForumSchemas.ts @@ -96,7 +96,7 @@ export type UserProfileUpdate = { }; /** - * @example {"id":1,"username":"john_doe","reputationPoints":100,"profilePicture":"frontend\src\assets\placeholder_profile.png","name":"John Doe"} + * @example {"id":1,"username":"john_doe","reputationPoints":100,"profilePicture":"https://placehold.co/640x640","name":"John Doe"} */ export type UserSummary = { id: number; diff --git a/swagger/openapi.yml b/swagger/openapi.yml index 86ed232c..499f1a48 100644 --- a/swagger/openapi.yml +++ b/swagger/openapi.yml @@ -938,18 +938,12 @@ paths: schema: type: integer default: 20 - - name: sortBy + - 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 From 0c1d2c9b5b3ccc008601c520f624cc13554ac891 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 18:22:44 +0300 Subject: [PATCH 8/9] Update sortBy parameter and conditions --- .../programminglanguagesforum/Services/QuestionService.java | 3 +-- frontend/src/components/SearchQuestionsList.tsx | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index e4bc9b81..6408b490 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -236,10 +236,9 @@ public Page searchQuestions( } PageRequest pageable = PageRequest.of(page - 1, pageSize); - if (Objects.equals(sortBy, "default") || Objects.equals(currentUser, null)) { + if (Objects.equals(sortBy, "default") || Objects.equals(sortBy, null) || Objects.equals(currentUser, null) || ) { return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); } else { - List authorIds = currentUser.getFollowing().stream() .map(User::getId) // Map each User to its ID .collect(Collectors.toList()); // Collect the IDs into a List diff --git a/frontend/src/components/SearchQuestionsList.tsx b/frontend/src/components/SearchQuestionsList.tsx index b5dc4046..e93d703c 100644 --- a/frontend/src/components/SearchQuestionsList.tsx +++ b/frontend/src/components/SearchQuestionsList.tsx @@ -32,6 +32,7 @@ export const SearchQuestionsList = () => { q: params.get("q") ?? "", pageSize, ...(difficulty && { difficulty }), + sortBy: params.get("sortBy") ?? "recommended" }, }); From 0cc94c68b95acbf9fdf6e1c33446ebb841f2673b Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Mon, 16 Dec 2024 18:25:39 +0300 Subject: [PATCH 9/9] Fix typo --- .../programminglanguagesforum/Services/QuestionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java index 6408b490..35efcf9e 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/QuestionService.java @@ -236,7 +236,7 @@ public Page searchQuestions( } PageRequest pageable = PageRequest.of(page - 1, pageSize); - if (Objects.equals(sortBy, "default") || Objects.equals(sortBy, null) || Objects.equals(currentUser, null) || ) { + if (Objects.equals(sortBy, "default") || Objects.equals(sortBy, null) || Objects.equals(currentUser, null)) { return questionRepository.searchQuestions(query, tagIds, difficulty, pageable); } else { List authorIds = currentUser.getFollowing().stream()