package com.platform2easy.genesis.domain.service;

import com.platform2easy.genesis.domain.model.Commoditiy;
import com.platform2easy.genesis.domain.repository.CommodityRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@AllArgsConstructor
public class CommodityService {

    private final CommodityRepository repository;

    @Transactional
    public Commoditiy salvar(Commoditiy commoditiy) {

        repository.save(commoditiy);
        return commoditiy;
    }

    public List<Commoditiy> listarTodos() {
        return repository.findAll();
    }

    public Commoditiy buscarPorId(Long id) {
        return repository.findById(id).orElseThrow();
    }

    public void deletarPorId(Long id) {
        repository.deleteById(id);
    }

}
