package edu.prlab.tyler.iotgateway.cloud.services;

import org.springframework.data.repository.CrudRepository;

import java.util.Optional;

public abstract class CrudService<T, ID> {
    private CrudRepository<T, ID> repository;

    public CrudService(CrudRepository<T, ID> repository) {
        this.repository = repository;
    }

    public Optional<T> add(T pojo) {
        System.out.println("save" + pojo.toString());
        return Optional.of(repository.save(pojo));
        }

public Optional<T> read(ID id) {
        return repository.findById(id);
        }

public Iterable<T> readll() {
        return repository.findAll();
        }
        }
