filter papers
parent
4c0ccbe285
commit
2a76acc7ad
@ -0,0 +1,24 @@
|
||||
package ru.ulstu.paper.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class PaperFilterDto {
|
||||
private final Integer authorId;
|
||||
private final Integer year;
|
||||
|
||||
@JsonCreator
|
||||
public PaperFilterDto(@JsonProperty("authorId") Integer authorId,
|
||||
@JsonProperty("year") Integer year) {
|
||||
this.authorId = authorId;
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Integer getAuthorId() {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue