package com.izouma.jmrh.repo;

import com.izouma.jmrh.domain.Article;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDateTime;

public interface ArticleRepo extends JpaRepository<Article, Long>, JpaSpecificationExecutor<Article> {
    @Modifying
    @Transactional
    @Query(value = "update article set state =:#{#article.state} where id=:#{#article.id}", nativeQuery = true)
    int updateStateById(Article article);

    long countByCreatedAtBetween(LocalDateTime start, LocalDateTime end);
}