Compare commits

...

2 Commits

  1. 4
      BE/src/main/java/org/example/controllers/PostController.java
  2. 27
      BE/src/main/java/org/example/controllers/SearchController.java
  3. 1
      BE/src/main/java/org/example/models/Post.java
  4. 1
      BE/src/main/java/org/example/models/UserPostResult.java
  5. 35
      BE/src/main/java/org/example/objects/SearchDTO.java
  6. 30
      BE/src/main/java/org/example/queryresults/SearchQueryResult.java
  7. 8
      BE/src/main/java/org/example/repositories/PostRepository.java
  8. 6
      BE/src/main/java/org/example/services/PostService.java

@ -57,9 +57,7 @@ public class PostController {
}
}
@PostMapping
public Post createPost(
@RequestParam("title") String title,
public Post createPost(@RequestParam("title") String title,
@RequestParam("content") String content,
@RequestParam(value = "imageFile", required = false) MultipartFile imageFile,
@RequestParam(value = "videoFile", required = false) MultipartFile videoFile) throws IOException {

@ -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);
}
}

@ -16,7 +16,6 @@ import java.util.UUID;
@Getter
@Node
public class Post {
@Id
@GeneratedValue
private Long id;

@ -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;
}
}

@ -3,7 +3,9 @@ package org.example.repositories;
import org.example.controllers.UserController;
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;
@ -48,6 +50,7 @@ public interface PostRepository extends Neo4jRepository<Post,Long> {
")\n" +
"RETURN p")
Post updatePost(@Param("postId") Long postId, @Param("title") String title, @Param("content") String content, @Param("imageFile")MultipartFile imageFile, @Param("videoFile") MultipartFile videoFile);
@Query("MATCH (u:User {username: $username}), (p:Post) WHERE ID(p)=$postId CREATE (u)-[:LIKES]->(p)")
void createLike(@Param("username") String username,@Param("postId") Long postId);
@ -57,4 +60,9 @@ public interface PostRepository extends Neo4jRepository<Post,Long> {
@Query("MATCH (user:User {username: $username}),(post:Post )"+"where ID(post)=$postId"+ " CREATE (user)-[:createPost ]->(post)"+
"RETURN user, post")
PostQueryResult createPostRelationship(@Param("username") String username,@Param("postId") Long postId);
@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<SearchQueryResult> search(@Param("input") String input);
}

@ -7,7 +7,9 @@ import org.example.models.Image;
import org.example.models.Post;
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;
@ -185,4 +187,8 @@ public class PostService {
return video;
}
@Transactional
public List<SearchQueryResult> searchRelatedTopics(String input){
return postRepository.search(input);
}
}

Loading…
Cancel
Save