review-api/src/main/java/com/guams/review/model/PostRepository.java
2025-01-23 21:54:29 +01:00

40 lines
1.5 KiB
Java

package com.guams.review.model;
import com.guams.review.model.dao.Post;
import com.guams.review.model.dao.PostWithAuthor;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
public interface PostRepository extends CrudRepository<Post, Long> {
@Query("select id, description, illustration, title, body, category, publication_date " +
"from post join publication on post.id=publication.post_fk where publication.author_fk=:authorId")
List<Post> findPostsOfAuthor(UUID authorId);
@Query(value = "SELECT " +
" a.id AS author_id, " +
" a.name AS author_name, " +
" a.profile_picture AS author_profile_picture, " +
" a.role AS role, " +
" p.id AS post_id, " +
" p.description AS post_description, " +
" p.illustration AS post_illustration, " +
" p.title AS post_title, " +
" p.body AS post_body, " +
" p.category AS post_category, " +
" p.publication_date AS post_publication_date, " +
" p.is_updated AS post_is_updated " +
"FROM post p " +
" JOIN publication pub ON p.id = pub.post_fk " +
" JOIN author a ON pub.author_fk = a.id;")
List<PostWithAuthor> findPostsWithAuthors();
List<Post> findAll();
}