package ru.ulstu.paper.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.user.model.User;

import java.util.List;

public interface PaperRepository extends JpaRepository<Paper, Integer> {

    @Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
    List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
}
