package com.remy.goods.service.impl;

import com.remy.goods.dao.GoodsDAO;
import com.remy.goods.entity.Goods;
import com.remy.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDAO goodsDAO;

    @Override
    public List<Goods> findAll() {
        return goodsDAO.findAll();
    }

    @Override
    public Goods findBySerialNo(String serialNo) {
        Goods goods = goodsDAO.findGoodsBySerialNo(serialNo);
        if (null == goods) {
            throw new EntityNotFoundException();
        }

        return goods;
    }

    @Override
    public Goods save(Goods goods) {
        return goodsDAO.save(goods);
    }
}
