added likes on post
This commit is contained in:
@@ -10,15 +10,22 @@ import org.springframework.data.jpa.repository.Query;
|
||||
public interface FavoriteRepository extends JpaRepository<Favorite, Long> {
|
||||
|
||||
boolean existsByUserAndPost(User user, Post post);
|
||||
|
||||
List<Favorite> findByUser(User user);
|
||||
|
||||
void deleteByUserAndPost(User user, Post post);
|
||||
|
||||
@Query("""
|
||||
SELECT f.post.id FROM Favorite f
|
||||
WHERE f.user.id = :userId
|
||||
AND f.post.id IN :postIds
|
||||
""")
|
||||
SELECT f.post.id FROM Favorite f
|
||||
WHERE f.user.id = :userId
|
||||
AND f.post.id IN :postIds
|
||||
""")
|
||||
List<Long> findFavoritePostIds(Long userId, List<Long> postIds);
|
||||
|
||||
// ADD THIS METHOD:
|
||||
@Query("""
|
||||
SELECT f.post.id, COUNT(f.id)
|
||||
FROM Favorite f
|
||||
WHERE f.post.id IN :postIds
|
||||
GROUP BY f.post.id
|
||||
""")
|
||||
List<Object[]> countLikesByPostIds(List<Long> postIds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user