diff --git a/BE/src/main/java/org/example/controllers/SearchController.java b/BE/src/main/java/org/example/controllers/SearchController.java index cb3b199..d9bfcab 100644 --- a/BE/src/main/java/org/example/controllers/SearchController.java +++ b/BE/src/main/java/org/example/controllers/SearchController.java @@ -1,6 +1,7 @@ package org.example.controllers; import org.example.objects.SearchDTO; +import org.example.queryresults.SearchQueryResult; import org.example.services.PostService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -19,8 +20,8 @@ public class SearchController { @GetMapping("/search_result") - public ResponseEntity> searchRelatedTopics(@RequestParam String key){ - List searchResult = postService.searchRelatedTopics(key); + public ResponseEntity> searchRelatedTopics(@RequestParam String key){ + List searchResult = postService.searchRelatedTopics(key); return new ResponseEntity<>(searchResult, HttpStatus.OK); } } diff --git a/BE/src/main/java/org/example/objects/SearchDTO.java b/BE/src/main/java/org/example/objects/SearchDTO.java index 6932664..1c4b8c7 100644 --- a/BE/src/main/java/org/example/objects/SearchDTO.java +++ b/BE/src/main/java/org/example/objects/SearchDTO.java @@ -1,27 +1,35 @@ package org.example.objects; +import org.example.models.Post; +import org.example.models.User; + +import java.util.List; + public class SearchDTO { - private String username; - private String title; - - public SearchDTO(String username, String title) { - this.username = username; - this.title = title; + private List posts; + private List users; + + public SearchDTO() { + } + + public SearchDTO(List posts, List users) { + this.posts = posts; + this.users = users; } - public String getUsername() { - return username; + public List getPosts() { + return posts; } - public void setUsername(String username) { - this.username = username; + public void setPosts(List posts) { + this.posts = posts; } - public String getTitle() { - return title; + public List getUsers() { + return users; } - public void setTitle(String title) { - this.title = title; + public void setUsers(List users) { + this.users = users; } } diff --git a/BE/src/main/java/org/example/queryresults/SearchQueryResult.java b/BE/src/main/java/org/example/queryresults/SearchQueryResult.java new file mode 100644 index 0000000..abeff01 --- /dev/null +++ b/BE/src/main/java/org/example/queryresults/SearchQueryResult.java @@ -0,0 +1,30 @@ +package org.example.queryresults; + +import org.example.models.Post; +import org.example.models.User; + +public class SearchQueryResult { +// private Post post; + private User user; + + public SearchQueryResult(Post post, User user) { +// this.post = post; + this.user = user; + } + +// public Post getPost() { +// return post; +// } +// +// public void setPost(Post post) { +// this.post = post; +// } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/BE/src/main/java/org/example/repositories/PostRepository.java b/BE/src/main/java/org/example/repositories/PostRepository.java index 1cf0a2a..a387fa2 100644 --- a/BE/src/main/java/org/example/repositories/PostRepository.java +++ b/BE/src/main/java/org/example/repositories/PostRepository.java @@ -5,6 +5,7 @@ import org.example.models.Image; import org.example.models.Post; import org.example.objects.SearchDTO; import org.example.queryresults.PostQueryResult; +import org.example.queryresults.SearchQueryResult; import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.neo4j.repository.query.Query; import org.springframework.data.repository.query.Param; @@ -63,5 +64,5 @@ public interface PostRepository extends Neo4jRepository { @Query("OPTIONAL MATCH (p:Post), (u:User) " + "WHERE toLower(p.title) CONTAINS toLower($input) OR toLower(u.username) CONTAINS toLower($input) " + "RETURN p, u;") - List search(@Param("input") String input); + List search(@Param("input") String input); } diff --git a/BE/src/main/java/org/example/services/PostService.java b/BE/src/main/java/org/example/services/PostService.java index 1632423..83ff593 100644 --- a/BE/src/main/java/org/example/services/PostService.java +++ b/BE/src/main/java/org/example/services/PostService.java @@ -9,6 +9,7 @@ import org.example.models.User; import org.example.models.Video; import org.example.objects.SearchDTO; import org.example.queryresults.PostQueryResult; +import org.example.queryresults.SearchQueryResult; import org.example.repositories.PostRepository; import org.example.repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -187,7 +188,7 @@ public class PostService { } @Transactional - public List searchRelatedTopics(String input){ + public List searchRelatedTopics(String input){ return postRepository.search(input); } }