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

import com.itsol.quantrivanphong.access.homepage.repository.CatalogiRepository;
import com.itsol.quantrivanphong.exception.ResourceNotFoundException;
import com.itsol.quantrivanphong.model.Catalogi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatalogiBusiness {
    @Autowired
    private CatalogiRepository catalogiRepository;

    public Catalogi findCatalogiById(int id){
        return catalogiRepository.findCatalogiById(id);
    }

    public List<Catalogi> findAllCatalogi(){
        return catalogiRepository.findAllCatalogi();
    }

    public Catalogi save(Catalogi catalogi){
        return catalogiRepository.save(catalogi);
    }
    public String deleteCatalogi(int catalogiId){
        Catalogi catalogi = catalogiRepository.findCatalogiById(catalogiId);
        if(catalogi == null){
            throw new ResourceNotFoundException("News" ,"newsId",catalogiId);
        }
        catalogiRepository.delete(catalogi);
        return "ok";

    }
}
