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

import com.itsol.quantrivanphong.access.homepage.business.CatalogiBusiness;
import com.itsol.quantrivanphong.exception.ResourceNotFoundException;
import com.itsol.quantrivanphong.model.Catalogi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

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

public class CatalogiController {
    @Autowired
    private CatalogiBusiness catalogiBusiness;

    @GetMapping("/catalogies")
    public ResponseEntity<List<Catalogi>> getAllNews(){
        return ResponseEntity.ok( catalogiBusiness.findAllCatalogi());
    }

    @GetMapping("/catalogies/{catalogiId}")
    public Catalogi getCatalogiById(@PathVariable(value = "catalogiId") int catalogiId){
        return catalogiBusiness.findById(catalogiId).orElseThrow(()-> new ResourceNotFoundException("Catalogi","catalogiId",catalogiId));
    }

}
