package com.itsol.quantrivanphong.access.homepage.repository;

import com.itsol.quantrivanphong.model.News;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface NewsRepository extends JpaRepository<News, Integer> {
    @Query("SELECT u from News u")
    List<News> findAllNews();
    @Query("SELECT u FROM News u where u.id=:id")
    News findNewsById(int id);

    @Query(value="select * from News c where c.catalogi_id = ? ORDER BY c.created_at DESC limit 4",nativeQuery = true)
    List<News> getLatestNews(int catalogiId);

    @Query(value="select * from News c ORDER BY c.created_at DESC limit 4",nativeQuery = true)
    List<News> getAllLatestNews();

    List<News> findByEmployeeId(int employeeId);
    List<News> findByCatalogiId(int catalogiId);
    News findByIdAndEmployeeId(int id,int employeeId);
    News findByIdAndAndCatalogiId(int id,int catalogiId);
}
