Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Thanhzxcn | 989f94de81 | 5 months ago |
Thanhzxcn | 3cbc6d31f8 | 5 months ago |
@ -1,25 +0,0 @@ |
|||||||
package org.example.controllers; |
|
||||||
|
|
||||||
|
|
||||||
import org.example.models.Category; |
|
||||||
import org.example.services.CategoryService; |
|
||||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
@RestController |
|
||||||
@RequestMapping("/category") |
|
||||||
public class CategoryController { |
|
||||||
private final CategoryService categoryService; |
|
||||||
|
|
||||||
public CategoryController(CategoryService categoryService) { |
|
||||||
this.categoryService = categoryService; |
|
||||||
} |
|
||||||
|
|
||||||
@GetMapping("/getAllCategories") |
|
||||||
public List<Category> getAllCategories(){ |
|
||||||
return categoryService.getAllCategories(); |
|
||||||
} |
|
||||||
} |
|
@ -1,39 +0,0 @@ |
|||||||
package org.example.controllers; |
|
||||||
|
|
||||||
import org.example.objects.CommentDTO; |
|
||||||
import org.example.objects.InteractionsDTO; |
|
||||||
import org.example.services.InteractService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.http.HttpStatus; |
|
||||||
import org.springframework.http.ResponseEntity; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
@RestController |
|
||||||
@RequestMapping("/interactions") |
|
||||||
public class InteractionController { |
|
||||||
private final InteractService interactionService; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
public InteractionController(InteractService interactionService) { |
|
||||||
this.interactionService = interactionService; |
|
||||||
} |
|
||||||
|
|
||||||
@PostMapping("/like") |
|
||||||
public ResponseEntity<Void> likePost(@RequestBody InteractionsDTO interactionsDTO) { |
|
||||||
interactionService.toggleLike(interactionsDTO.getUsername(), interactionsDTO.getPostId()); |
|
||||||
return new ResponseEntity<>(HttpStatus.OK); |
|
||||||
} |
|
||||||
|
|
||||||
@PostMapping("/comment") |
|
||||||
public ResponseEntity<Void> commentPost(@RequestBody CommentDTO interactionsDTO) { |
|
||||||
interactionService.commentPost(interactionsDTO.getUsername(), interactionsDTO.getPostId(), interactionsDTO.getContent()); |
|
||||||
return new ResponseEntity<>(HttpStatus.OK); |
|
||||||
} |
|
||||||
|
|
||||||
@PostMapping("/share") |
|
||||||
public ResponseEntity<Void> sharePost(@RequestBody InteractionsDTO interactionsDTO) { |
|
||||||
interactionService.sharePost(interactionsDTO.getUsername(), interactionsDTO.getPostId()); |
|
||||||
return new ResponseEntity<>(HttpStatus.OK); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -1,29 +0,0 @@ |
|||||||
package org.example.controllers; |
|
||||||
|
|
||||||
|
|
||||||
import ch.qos.logback.core.joran.sanity.Pair; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.User; |
|
||||||
import org.example.objects.SearchResultDTO; |
|
||||||
import org.example.services.SearchService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
@RestController |
|
||||||
@RequestMapping("/search") |
|
||||||
public class SearchController { |
|
||||||
@Autowired |
|
||||||
private final SearchService searchService; |
|
||||||
|
|
||||||
public SearchController(SearchService searchService) { |
|
||||||
this.searchService = searchService; |
|
||||||
} |
|
||||||
|
|
||||||
@GetMapping("/get") |
|
||||||
public List<Post> search(@RequestParam("condition") String condition) { |
|
||||||
System.out.println(condition); |
|
||||||
return searchService.searchResult(condition); |
|
||||||
} |
|
||||||
} |
|
@ -1,34 +0,0 @@ |
|||||||
package org.example.models; |
|
||||||
|
|
||||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
|
||||||
import org.springframework.data.neo4j.core.schema.Id; |
|
||||||
import org.springframework.data.neo4j.core.schema.Node; |
|
||||||
import org.springframework.data.neo4j.core.schema.Relationship; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Node |
|
||||||
public class Category { |
|
||||||
@Id |
|
||||||
@GeneratedValue |
|
||||||
private Long id; |
|
||||||
private String name; |
|
||||||
|
|
||||||
public Long getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(Long id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() { |
|
||||||
return name; |
|
||||||
} |
|
||||||
|
|
||||||
public void setName(String name) { |
|
||||||
this.name = name; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,26 @@ |
|||||||
|
package org.example.models; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.*; |
||||||
|
import lombok.experimental.FieldDefaults; |
||||||
|
import org.neo4j.ogm.annotation.EndNode; |
||||||
|
import org.neo4j.ogm.annotation.RelationshipEntity; |
||||||
|
import org.neo4j.ogm.annotation.StartNode; |
||||||
|
|
||||||
|
@Data |
||||||
|
@Builder |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@FieldDefaults(level = AccessLevel.PRIVATE) |
||||||
|
@RelationshipEntity(type = "LIKE") |
||||||
|
public class Like { |
||||||
|
Long userId; |
||||||
|
Long postId; |
||||||
|
String status; |
||||||
|
|
||||||
|
@StartNode |
||||||
|
private User user; |
||||||
|
|
||||||
|
@EndNode |
||||||
|
private Post post; |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package org.example.objects; |
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
import lombok.*; |
||||||
|
import lombok.experimental.FieldDefaults; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
@FieldDefaults(level = AccessLevel.PRIVATE) |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public class ApiResponse<T>{ |
||||||
|
int code = 1000; |
||||||
|
String message; |
||||||
|
T result; |
||||||
|
} |
@ -1,31 +0,0 @@ |
|||||||
package org.example.objects; |
|
||||||
|
|
||||||
public class CommentDTO { |
|
||||||
private String username; |
|
||||||
private Long postId; |
|
||||||
private String content; |
|
||||||
|
|
||||||
public String getUsername() { |
|
||||||
return username; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUsername(String username) { |
|
||||||
this.username = username; |
|
||||||
} |
|
||||||
|
|
||||||
public Long getPostId() { |
|
||||||
return postId; |
|
||||||
} |
|
||||||
|
|
||||||
public void setPostId(Long postId) { |
|
||||||
this.postId = postId; |
|
||||||
} |
|
||||||
|
|
||||||
public String getContent() { |
|
||||||
return content; |
|
||||||
} |
|
||||||
|
|
||||||
public void setContent(String content) { |
|
||||||
this.content = content; |
|
||||||
} |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
package org.example.objects; |
|
||||||
|
|
||||||
public class FriendDTO { |
|
||||||
private String username1,username2; |
|
||||||
|
|
||||||
public String getUsername1() { |
|
||||||
return username1; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUsername1(String username1) { |
|
||||||
this.username1 = username1; |
|
||||||
} |
|
||||||
|
|
||||||
public String getUsername2() { |
|
||||||
return username2; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUsername2(String username2) { |
|
||||||
this.username2 = username2; |
|
||||||
} |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
package org.example.objects; |
|
||||||
|
|
||||||
public class InteractionsDTO { |
|
||||||
private String username; |
|
||||||
private Long postId; |
|
||||||
|
|
||||||
public String getUsername() { |
|
||||||
return username; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUsername(String username) { |
|
||||||
this.username = username; |
|
||||||
} |
|
||||||
|
|
||||||
public Long getPostId() { |
|
||||||
return postId; |
|
||||||
} |
|
||||||
|
|
||||||
public void setPostId(Long postId) { |
|
||||||
this.postId = postId; |
|
||||||
} |
|
||||||
} |
|
@ -1,39 +0,0 @@ |
|||||||
package org.example.objects; |
|
||||||
|
|
||||||
import org.example.models.Image; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.Video; |
|
||||||
import org.springframework.data.neo4j.core.schema.Node; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class PostWithMedia { |
|
||||||
private Post post; |
|
||||||
private List<Image> images; |
|
||||||
private List<Video> videos; |
|
||||||
|
|
||||||
// Getters and setters
|
|
||||||
public Post getPost() { |
|
||||||
return post; |
|
||||||
} |
|
||||||
|
|
||||||
public void setPost(Post post) { |
|
||||||
this.post = post; |
|
||||||
} |
|
||||||
|
|
||||||
public List<Image> getImages() { |
|
||||||
return images; |
|
||||||
} |
|
||||||
|
|
||||||
public void setImages(List<Image> images) { |
|
||||||
this.images = images; |
|
||||||
} |
|
||||||
|
|
||||||
public List<Video> getVideos() { |
|
||||||
return videos; |
|
||||||
} |
|
||||||
|
|
||||||
public void setVideos(List<Video> videos) { |
|
||||||
this.videos = videos; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -1,36 +0,0 @@ |
|||||||
package org.example.objects; |
|
||||||
|
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.User; |
|
||||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
|
||||||
import org.springframework.data.neo4j.core.schema.Id; |
|
||||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||||
|
|
||||||
public class SearchResultDTO { |
|
||||||
@Id |
|
||||||
@GeneratedValue |
|
||||||
private Long id; |
|
||||||
private User user; |
|
||||||
private Post post; |
|
||||||
|
|
||||||
public SearchResultDTO(Post post, User user) { |
|
||||||
this.user = user; |
|
||||||
this.post = post; |
|
||||||
} |
|
||||||
|
|
||||||
public User getUser() { |
|
||||||
return user; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUser(User user) { |
|
||||||
this.user = user; |
|
||||||
} |
|
||||||
|
|
||||||
public Post getPost() { |
|
||||||
return post; |
|
||||||
} |
|
||||||
|
|
||||||
public void setPost(Post post) { |
|
||||||
this.post = post; |
|
||||||
} |
|
||||||
} |
|
@ -1,61 +0,0 @@ |
|||||||
package org.example.realtionship; |
|
||||||
|
|
||||||
import org.example.models.User; |
|
||||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
|
||||||
import org.springframework.data.neo4j.core.schema.Id; |
|
||||||
import org.springframework.data.neo4j.core.schema.RelationshipProperties; |
|
||||||
import org.springframework.data.neo4j.core.schema.TargetNode; |
|
||||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||||
|
|
||||||
import java.time.LocalDateTime; |
|
||||||
|
|
||||||
@RelationshipProperties |
|
||||||
public class CommentRelationship { |
|
||||||
@Id |
|
||||||
@GeneratedValue |
|
||||||
private Long id; |
|
||||||
private String content; |
|
||||||
private LocalDateTime timestamp; |
|
||||||
|
|
||||||
@TargetNode private User user; |
|
||||||
|
|
||||||
public CommentRelationship(String content, LocalDateTime timestamp, User user) { |
|
||||||
this.content = content; |
|
||||||
this.timestamp = timestamp; |
|
||||||
this.user = user; |
|
||||||
} |
|
||||||
|
|
||||||
public Long getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(Long id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public String getContent() { |
|
||||||
return content; |
|
||||||
} |
|
||||||
|
|
||||||
public void setContent(String content) { |
|
||||||
this.content = content; |
|
||||||
} |
|
||||||
|
|
||||||
public LocalDateTime getTimestamp() { |
|
||||||
return timestamp; |
|
||||||
} |
|
||||||
|
|
||||||
public void setTimestamp(LocalDateTime timestamp) { |
|
||||||
this.timestamp = timestamp; |
|
||||||
} |
|
||||||
|
|
||||||
public User getUser() { |
|
||||||
return user; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUser(User user) { |
|
||||||
this.user = user; |
|
||||||
} |
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
} |
|
@ -1,51 +0,0 @@ |
|||||||
package org.example.realtionship; |
|
||||||
|
|
||||||
import org.example.models.User; |
|
||||||
import org.springframework.data.annotation.Id; |
|
||||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
|
||||||
import org.springframework.data.neo4j.core.schema.RelationshipProperties; |
|
||||||
import org.springframework.data.neo4j.core.schema.TargetNode; |
|
||||||
|
|
||||||
import java.time.LocalDateTime; |
|
||||||
|
|
||||||
@RelationshipProperties |
|
||||||
public class ShareRelationship { |
|
||||||
@Id |
|
||||||
@GeneratedValue |
|
||||||
private Long id; |
|
||||||
private LocalDateTime timestamp; |
|
||||||
|
|
||||||
@TargetNode |
|
||||||
private User user; |
|
||||||
|
|
||||||
public ShareRelationship(LocalDateTime timestamp, User user) { |
|
||||||
this.timestamp = timestamp; |
|
||||||
this.user = user; |
|
||||||
} |
|
||||||
|
|
||||||
public Long getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(Long id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public LocalDateTime getTimestamp() { |
|
||||||
return timestamp; |
|
||||||
} |
|
||||||
|
|
||||||
public void setTimestamp(LocalDateTime timestamp) { |
|
||||||
this.timestamp = timestamp; |
|
||||||
} |
|
||||||
|
|
||||||
public User getUser() { |
|
||||||
return user; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUser(User user) { |
|
||||||
this.user = user; |
|
||||||
} |
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
} |
|
@ -1,26 +0,0 @@ |
|||||||
package org.example.repositories; |
|
||||||
|
|
||||||
import org.example.models.Category; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.objects.PostDTO; |
|
||||||
import org.example.objects.PostWithMedia; |
|
||||||
import org.springframework.data.neo4j.repository.Neo4jRepository; |
|
||||||
import org.springframework.data.neo4j.repository.query.Query; |
|
||||||
import org.springframework.data.repository.query.Param; |
|
||||||
import org.springframework.stereotype.Repository; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
@Repository |
|
||||||
public interface CategoryRepository extends Neo4jRepository<Category, Long> { |
|
||||||
Category findByName(String name); |
|
||||||
@Query("MATCH (c:Category)<-[:HAS_CATEGORY]-(p:Post)\n" + |
|
||||||
"WHERE c.name = $categoryName\n" + |
|
||||||
"OPTIONAL MATCH (p)-[:HAS_IMAGE]->(image:Image)\n" + |
|
||||||
"OPTIONAL MATCH (p)-[:HAS_VIDEO]->(video:Video)\n" + |
|
||||||
"RETURN ID(p)") |
|
||||||
List<Long> findPostsByCategoryNames(@Param("categoryName") String categoryName); |
|
||||||
|
|
||||||
@Query("MATCH (post:Post)-[HAS_CATEGORY]->(cate:Category) WHERE ID(post)=$postId return cate") |
|
||||||
Category getCategory(@Param("postId") Long postId); |
|
||||||
} |
|
@ -1,23 +0,0 @@ |
|||||||
package org.example.repositories; |
|
||||||
|
|
||||||
import ch.qos.logback.core.joran.sanity.Pair; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.User; |
|
||||||
import org.example.objects.SearchResultDTO; |
|
||||||
import org.springframework.data.neo4j.repository.Neo4jRepository; |
|
||||||
import org.springframework.data.neo4j.repository.query.Query; |
|
||||||
import org.springframework.data.repository.CrudRepository; |
|
||||||
import org.springframework.data.repository.query.Param; |
|
||||||
import org.springframework.stereotype.Repository; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.Objects; |
|
||||||
|
|
||||||
@Repository |
|
||||||
public interface SearchRepository extends Neo4jRepository<Post,Long> { |
|
||||||
@Query("MATCH (p:Post)<-[:createPost]-(u:User)\n" + |
|
||||||
"WHERE p.title CONTAINS $condition OR p.content CONTAINS $condition OR u.username CONTAINS $condition \n" + |
|
||||||
"RETURN p \n") |
|
||||||
List<Post> search(@Param("condition") String condition); |
|
||||||
} |
|
@ -1,53 +1,36 @@ |
|||||||
package org.example.repositories; |
package org.example.repositories; |
||||||
|
|
||||||
import org.example.models.Category; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.User; |
import org.example.models.User; |
||||||
import org.example.objects.FriendDTO; |
|
||||||
import org.example.queryresults.PostQueryResult; |
import org.example.queryresults.PostQueryResult; |
||||||
import org.example.services.UserService; |
|
||||||
import org.springframework.data.neo4j.repository.Neo4jRepository; |
import org.springframework.data.neo4j.repository.Neo4jRepository; |
||||||
import org.springframework.data.neo4j.repository.query.Query; |
import org.springframework.data.neo4j.repository.query.Query; |
||||||
import org.springframework.data.repository.query.Param; |
import org.springframework.data.repository.query.Param; |
||||||
import org.springframework.stereotype.Repository; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Optional; |
import java.util.Optional; |
||||||
|
|
||||||
@Repository |
|
||||||
public interface UserRepository extends Neo4jRepository<User, Long> { |
public interface UserRepository extends Neo4jRepository<User, Long> { |
||||||
|
|
||||||
|
|
||||||
Optional<User> findUserByUsername(String username); |
Optional<User> findUserByUsername(String username); |
||||||
|
User findUserBy(String username); |
||||||
boolean existsByUsername(String username); |
boolean existsByUsername(String username); |
||||||
|
|
||||||
@Query("MATCH (u:User {name:$username1}), (f:User {name:$username2})\n" + |
|
||||||
"OPTIONAL MATCH (u)-[fr:Friend]->(f), (f)-[fr1:Friend]->(u)\n" + |
@Query("MATCH (user:User), (course:Course) WHERE user.username = $username AND course.identifier = $identifier " + |
||||||
"WITH u, f, collect(fr) as friendships1, collect(fr1) as friendships2\n" + |
"RETURN EXISTS((user)-[:ENROLLED_IN]->(course))") |
||||||
"FOREACH (_ IN CASE WHEN size(friendships1) = 0 AND size(friendships2) = 0 THEN [1] ELSE [] END | \n" + |
Boolean findEnrolmentStatus(String username, String identifier); |
||||||
" CREATE (u)-[:Friend]->(f) \n" + |
|
||||||
" CREATE (f)-[:Friend]->(u))\n" + |
@Query("match (u:User), (p:POST)\n" + |
||||||
"FOREACH (_ IN CASE WHEN size(friendships1) > 0 AND size(friendships2) > 0 THEN [1] ELSE [] END | \n" + |
"WHERE id(u) = $nameId AND id(p) = $postId\n" + |
||||||
" DELETE friendships1[0], friendships2[0])\n") |
"create (u) - [:LIKE] -> (p)") |
||||||
void addFriend(@Param("username1") String username1, @Param("username2") String username2); |
void createLike(@Param("nameId") Long nameId, @Param("postId*") Long postId); |
||||||
|
|
||||||
|
@Query("match (a:User)-[r:LIKE]-> (b:POST)\n" + |
||||||
|
"WHERE id(a) = $id AND id(b) = $idd\n" + |
||||||
@Query("MATCH (u:User {username:$username})-[:Friend]->(f:User)\n" + |
"RETURN COUNT(r) > 0 AS Relationship") |
||||||
"match (f)-[:createPost]->(p:Post)RETURN ID(p)") |
boolean checkLike(@Param("id") Long userId,@Param("idd") Long postId); |
||||||
List<Long> findFriendPosts(@Param("username") String username); |
|
||||||
|
// @Query("MATCH (user:User), (course:Course) WHERE user.username = $username AND course.identifier = $identifier " +
|
||||||
@Query("MATCH (u:User {username: $username})-[r:LIKED|COMMENTED|SHARED]->(p:Post)\n" + |
// "CREATE (user)-[:ENROLLED_IN]->(course) RETURN user, course")
|
||||||
"OPTIONAL MATCH (p)<-[like:LIKED]-(:User)\n" + |
// CourseEnrolmentQueryResult createEnrolmentRelationship(String username, String identifier);
|
||||||
"OPTIONAL MATCH (p)<-[comment:COMMENTED]-(:User)\n" + |
|
||||||
"OPTIONAL MATCH (p)<-[share:SHARED]-(:User)\n" + |
|
||||||
"OPTIONAL MATCH (p)-[:HAS_CATEGORY]->(c:Category)\n" + |
|
||||||
"WITH p, COUNT(DISTINCT like) AS likeCount, COUNT(DISTINCT comment) AS commentCount, COUNT(DISTINCT share) AS shareCount, c.name AS categories \n" + |
|
||||||
"WHERE likeCount > 0 OR commentCount > 0 OR shareCount > 0\n" + |
|
||||||
"RETURN categories \n" + |
|
||||||
"ORDER BY (likeCount + commentCount + shareCount) DESC") |
|
||||||
List<String> findInteractedCategories(@Param("username") String username); |
|
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,15 @@ |
|||||||
|
package org.example.requests; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.*; |
||||||
|
import lombok.experimental.FieldDefaults; |
||||||
|
|
||||||
|
@Data |
||||||
|
@Builder |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@FieldDefaults(level = AccessLevel.PRIVATE) |
||||||
|
public class CreateLikeRequest { |
||||||
|
Long userId; |
||||||
|
Long postId; |
||||||
|
} |
@ -1,23 +0,0 @@ |
|||||||
package org.example.services; |
|
||||||
|
|
||||||
|
|
||||||
import org.example.models.Category; |
|
||||||
import org.example.repositories.CategoryRepository; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
@Service |
|
||||||
public class CategoryService { |
|
||||||
private final CategoryRepository categoryRepository; |
|
||||||
|
|
||||||
public CategoryService(CategoryRepository categoryRepository) { |
|
||||||
this.categoryRepository = categoryRepository; |
|
||||||
} |
|
||||||
|
|
||||||
public List<Category> getAllCategories() { |
|
||||||
List<Category> categories = categoryRepository.findAll(); |
|
||||||
return categories; |
|
||||||
} |
|
||||||
} |
|
@ -1,45 +0,0 @@ |
|||||||
package org.example.services; |
|
||||||
|
|
||||||
import org.example.models.*; |
|
||||||
import org.example.realtionship.CommentRelationship; |
|
||||||
import org.example.realtionship.ShareRelationship; |
|
||||||
import org.example.repositories.*; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
import org.springframework.transaction.annotation.Transactional; |
|
||||||
|
|
||||||
import java.time.LocalDateTime; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Optional; |
|
||||||
|
|
||||||
@Service |
|
||||||
public class InteractService { |
|
||||||
private final PostRepository postRepository; |
|
||||||
private final UserRepository userRepository; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
public InteractService(PostRepository postRepository, UserRepository userRepository) { |
|
||||||
this.postRepository = postRepository; |
|
||||||
this.userRepository = userRepository; |
|
||||||
} |
|
||||||
|
|
||||||
@Transactional |
|
||||||
public void toggleLike(String username , Long postId) { |
|
||||||
boolean removed = postRepository.toggleLike(username, postId); |
|
||||||
if (!removed) { |
|
||||||
postRepository.likePost(username, postId); |
|
||||||
System.out.println("Liked"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Transactional |
|
||||||
public void commentPost(String username, Long postId, String content) { |
|
||||||
postRepository.commentPost(username, postId, content); |
|
||||||
} |
|
||||||
|
|
||||||
@Transactional |
|
||||||
public void sharePost(String username, Long postId) { |
|
||||||
postRepository.sharePost(username, postId); |
|
||||||
} |
|
||||||
} |
|
@ -1,67 +0,0 @@ |
|||||||
package org.example.services; |
|
||||||
|
|
||||||
|
|
||||||
import org.example.models.Category; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.objects.PostDTO; |
|
||||||
import org.example.objects.PostWithMedia; |
|
||||||
import org.example.repositories.CategoryRepository; |
|
||||||
import org.example.repositories.PostRepository; |
|
||||||
import org.example.repositories.UserRepository; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.HashSet; |
|
||||||
import java.util.List; |
|
||||||
import java.util.stream.Collectors; |
|
||||||
|
|
||||||
@Service |
|
||||||
public class RecommendationService { |
|
||||||
private final PostRepository postRepository; |
|
||||||
private final UserRepository userRepository; |
|
||||||
private final CategoryRepository categoryRepository; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
public RecommendationService(PostRepository postRepository, UserRepository userRepository, CategoryRepository categoryRepository) { |
|
||||||
this.postRepository = postRepository; |
|
||||||
this.userRepository = userRepository; |
|
||||||
this.categoryRepository = categoryRepository; |
|
||||||
} |
|
||||||
|
|
||||||
public List<Post> getRecommendationPosts(String username) { |
|
||||||
List<Post> recommendationPosts = new ArrayList<>(); |
|
||||||
//tim kiem bai viết phổ biến theo số lượng interact
|
|
||||||
List<Post> postsInteracts = new ArrayList<>(); |
|
||||||
postsInteracts=postRepository.findTop10ByInteractions(); |
|
||||||
for (Post post : postsInteracts) { |
|
||||||
post.setImgUrl(postRepository.getImage(post.getId())); |
|
||||||
recommendationPosts.add(post); |
|
||||||
} |
|
||||||
//tìm kiếm các bài post có chung chủ đề
|
|
||||||
List<String> categoriesNames = userRepository.findInteractedCategories(username); |
|
||||||
for (String categoryName : categoriesNames) { |
|
||||||
System.out.println(categoryName); |
|
||||||
List<Long> IDposts = categoryRepository.findPostsByCategoryNames(categoryName); |
|
||||||
for(Long IDpost : IDposts) { |
|
||||||
System.out.println(IDpost); |
|
||||||
Post post= postRepository.findById(IDpost).get(); |
|
||||||
if(!recommendationPosts.contains(post)) { |
|
||||||
recommendationPosts.add(post); |
|
||||||
post.setImgUrl(postRepository.getImage(IDpost)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
List<Long> postsFriend; |
|
||||||
postsFriend=userRepository.findFriendPosts(username); |
|
||||||
for (Long postID : postsFriend) { |
|
||||||
Post post = postRepository.findById(postID).get(); |
|
||||||
if(!recommendationPosts.contains(post)) { |
|
||||||
post.setImgUrl(postRepository.getImage(post.getId())); |
|
||||||
recommendationPosts.add(post); |
|
||||||
} |
|
||||||
} |
|
||||||
return recommendationPosts.stream().distinct().collect(Collectors.toList()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,40 +0,0 @@ |
|||||||
package org.example.services; |
|
||||||
|
|
||||||
|
|
||||||
import ch.qos.logback.core.joran.sanity.Pair; |
|
||||||
import org.example.models.Post; |
|
||||||
import org.example.models.User; |
|
||||||
import org.example.objects.SearchResultDTO; |
|
||||||
import org.example.repositories.CategoryRepository; |
|
||||||
import org.example.repositories.PostRepository; |
|
||||||
import org.example.repositories.SearchRepository; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.stream.Collectors; |
|
||||||
|
|
||||||
@Service |
|
||||||
public class SearchService { |
|
||||||
@Autowired |
|
||||||
private final SearchRepository searchRepository; |
|
||||||
@Autowired |
|
||||||
private final PostRepository postRepository; |
|
||||||
@Autowired |
|
||||||
private final CategoryRepository categoryRepository; |
|
||||||
|
|
||||||
public SearchService(SearchRepository searchRepository, PostRepository postRepository,CategoryRepository categoryRepository) { |
|
||||||
this.searchRepository = searchRepository; |
|
||||||
this.postRepository = postRepository; |
|
||||||
this.categoryRepository = categoryRepository; |
|
||||||
} |
|
||||||
public List<Post> searchResult(String condition) { |
|
||||||
List<Post> posts= searchRepository.search(condition); |
|
||||||
for(Post post: posts) { |
|
||||||
post.setImgUrl(postRepository.getImage(post.getId())); |
|
||||||
post.setCategory(categoryRepository.getCategory(post.getId())); |
|
||||||
} |
|
||||||
return posts; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,3 +1,4 @@ |
|||||||
spring.neo4j.uri=neo4j://localhost:7687 |
spring.neo4j.uri=neo4j://localhost:7687 |
||||||
spring.neo4j.authentication.username=neo4j |
spring.neo4j.authentication.username=neo4j |
||||||
spring.neo4j.authentication.password=12345678 |
spring.neo4j.authentication.password=12345678 |
||||||
|
file_upload = C:/Users/P R O B O O K/Documents/Facebook/BE/images |
Loading…
Reference in new issue