package app.repositories; import app.entities.db.ban.Ban; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import java.sql.Timestamp; import java.util.List; public interface BanRepository extends PagingAndSortingRepository { @Query(value = "select b from Ban b where " + "(:ban_ids_non_exists = true or b.id in :ban_ids) and " + "(:account_ids_non_exists = true or b.account_id in :account_ids) and " + "(:begin_date_null is null or DATE_PART('EPOCH', b.timestamp) >= :begin_date) and " + "(:end_date_null is null or :end_date >= DATE_PART('EPOCH', b.timestamp)) and " + "(:active is null or b.active = :active) and " + "(:admin_ids_non_exists = true or b.banned_by_id in :admin_ids) and" + "(b.ban_reason like :reason) order by b.id desc") Page getBans(Pageable pageable, @Param(value = "ban_ids_non_exists") Boolean ban_ids_non_exists, @Param(value = "ban_ids") Iterable ban_ids, @Param(value = "account_ids_non_exists") Boolean account_ids_non_exists, @Param(value = "account_ids") Iterable account_ids, @Param(value = "begin_date") Long begin_date, @Param(value = "end_date") Long end_date, @Param(value = "active") Boolean active, @Param(value = "admin_ids_non_exists") Boolean admin_ids_non_exists, @Param(value = "admin_ids") Iterable admin_ids, @Param(value = "reason") String reason, @Param(value = "begin_date_null") Long begin_date_null, @Param(value = "end_date_null") Long end_date_null); }