diff --git a/BE/src/main/java/org/example/repositories/UserRepository.java b/BE/src/main/java/org/example/repositories/UserRepository.java index 5f091da..f234171 100644 --- a/BE/src/main/java/org/example/repositories/UserRepository.java +++ b/BE/src/main/java/org/example/repositories/UserRepository.java @@ -21,12 +21,12 @@ public interface UserRepository extends Neo4jRepository { @Query("match (u:User), (p:POST)\n" + "WHERE id(u) = $nameId AND id(p) = $postId\n" + "create (u) - [:LIKE] -> (p)") - void createLike(@Param("nameId") Long nameId, @Param("postId") Long postId); + void createLike(@Param("nameId") Long nameId, @Param("postId*") Long postId); - @Query("match (a:User)-[r:LIKE]-> (b:POST)" + - "WHERE id(a) = $id AND id(b) = $idd" + + @Query("match (a:User)-[r:LIKE]-> (b:POST)\n" + + "WHERE id(a) = $id AND id(b) = $idd\n" + "RETURN COUNT(r) > 0 AS Relationship") - boolean checkLike(Long userId, Long postId); + boolean checkLike(@Param("id") Long userId,@Param("idd") Long postId); // @Query("MATCH (user:User), (course:Course) WHERE user.username = $username AND course.identifier = $identifier " + // "CREATE (user)-[:ENROLLED_IN]->(course) RETURN user, course") diff --git a/BE/src/main/java/org/example/services/UserService.java b/BE/src/main/java/org/example/services/UserService.java index ac530d4..4266880 100644 --- a/BE/src/main/java/org/example/services/UserService.java +++ b/BE/src/main/java/org/example/services/UserService.java @@ -38,7 +38,12 @@ public class UserService { public CreateLikeRequest createLike(CreateLikeRequest request) { Long userId = request.getUserId(); Long postId = request.getPostId(); + if(userRepository.checkLike(userId, postId)){ + throw new IllegalArgumentException("Already liked"); + } userRepository.createLike(userId, postId); return request; } + + }