package es.uv.saic.service;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.uv.saic.domain.Calendari;
import es.uv.saic.domain.CalendariRepository;

@Service
public class CalendariService {
	
	@Autowired
	private CalendariRepository cr;
	
	public List<Calendari> getAll() {
		return this.cr.findAll();
	}
	
	public Calendari findById(Integer id) {
		Optional<Calendari> c = this.cr.findById(id);
		if(!c.isEmpty()) {
			return c.get();
		}
		return null;
	}
	
	public List<Calendari> getNextEvents(){
		return this.cr.getNextEvents();
	}
	
	public Calendari save(Calendari c) {
		return this.cr.saveAndFlush(c);
	}
	
	public void delete(Calendari c) {
		this.cr.delete(c);
	}

}
