Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
HuyDuong | 1b0f81d30a | 5 months ago |
HuyDuong | c88cfe904e | 5 months ago |
@ -0,0 +1,27 @@ |
||||
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; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/search") |
||||
public class SearchController { |
||||
private final PostService postService; |
||||
|
||||
public SearchController(PostService postService) { |
||||
this.postService = postService; |
||||
} |
||||
|
||||
|
||||
@GetMapping("/search_result") |
||||
public ResponseEntity<List<SearchQueryResult>> searchRelatedTopics(@RequestParam String key){ |
||||
List<SearchQueryResult> searchResult = postService.searchRelatedTopics(key); |
||||
return new ResponseEntity<>(searchResult, HttpStatus.OK); |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package org.example.objects; |
||||
|
||||
import org.example.models.Post; |
||||
import org.example.models.User; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class SearchDTO { |
||||
private List<Post> posts; |
||||
private List<User> users; |
||||
|
||||
public SearchDTO() { |
||||
} |
||||
|
||||
public SearchDTO(List<Post> posts, List<User> users) { |
||||
this.posts = posts; |
||||
this.users = users; |
||||
} |
||||
|
||||
public List<Post> getPosts() { |
||||
return posts; |
||||
} |
||||
|
||||
public void setPosts(List<Post> posts) { |
||||
this.posts = posts; |
||||
} |
||||
|
||||
public List<User> getUsers() { |
||||
return users; |
||||
} |
||||
|
||||
public void setUsers(List<User> users) { |
||||
this.users = users; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
Loading…
Reference in new issue