Update Like, ApiResponse

Thanh
Thanhzxcn 5 months ago
parent 3cbc6d31f8
commit 989f94de81
  1. 8
      BE/src/main/java/org/example/repositories/UserRepository.java
  2. 5
      BE/src/main/java/org/example/services/UserService.java

@ -21,12 +21,12 @@ public interface UserRepository extends Neo4jRepository<User, Long> {
@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")

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

Loading…
Cancel
Save