package ciai.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import ciai.exception.ProfessorNotEditedException; import ciai.exception.ProfessorNotFoundException; import ciai.model.Account; import ciai.model.Professor; import ciai.repository.ProfessorRepository; @Service public class ProfessorService { @Autowired ProfessorRepository profRep; public Professor getProfessor(Long id) throws ProfessorNotFoundException { Professor p = profRep.findOne(id); if (p == null) throw new ProfessorNotFoundException(); return p; } public void editProfessor(Long id, String name, String photo, String email) throws ProfessorNotFoundException, ProfessorNotEditedException { Professor prof = getProfessor(id); if (prof != null) { if (name != null && name.length() > 0) prof.setName(name); if (photo != null && photo.length() > 0) prof.setPhoto(photo); if (email != null && email.length() > 0) prof.setEmail(email); } if (profRep.save(prof) == null) throw new ProfessorNotEditedException(); } public Professor getProfessorByAccount(Account ac) { return profRep.getProfessorByAccount(ac.getId()); } public Iterable getAll() { return profRep.findAll(); } }