package com.chantha.springdemo.service;

import com.chantha.springdemo.model.Product;
import com.chantha.springdemo.repositories.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {

    @Autowired
    private final ProductRepository productRepository;

    public ProductService(ProductRepository productRepository) {
        this.productRepository=productRepository;
    }

    public void save(Product product){
        productRepository.save(product);
    }
    public List<Product> findAllProduct(){
        return (List<Product>) productRepository.findAll();
    }
    public Product findById(Long id){
        return productRepository.findById(id).orElse(new Product());
    }
    public void deleteById(Long id){
        productRepository.deleteById(id);
    }

}

