package li.l1t.tingo.service;

import li.l1t.tingo.exception.TeacherNotFoundException;
import li.l1t.tingo.model.Teacher;
import li.l1t.tingo.model.dto.TeacherDto;
import li.l1t.tingo.model.repo.TeacherRepository;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Service handling teachers, providing a bridge between the controller and the model.
 *
 * @author <a href="http://xxyy.github.io/">xxyy</a>
 * @since 2016-02-14
 */
@Service
public class TeacherService {
    private final DozerBeanMapper dozerBeanMapper;
    private final TeacherRepository teacherRepository;

    @Autowired
    public TeacherService(DozerBeanMapper dozerBeanMapper, TeacherRepository teacherRepository) {
        this.dozerBeanMapper = dozerBeanMapper;
        this.teacherRepository = teacherRepository;
    }

    public Iterable<Teacher> getAllTeachers() {
        return teacherRepository.findAll();
    }

    public Teacher getById(int id) {
        Teacher teacher = teacherRepository.findOne(id);
        if(teacher == null) {
            throw new TeacherNotFoundException(id);
        }
        return teacher;
    }

    public TeacherDto toDto(Teacher entity) {
        return dozerBeanMapper.map(entity, TeacherDto.class);
    }
}

@@ -211,42 +211,8 @@
 ry;%0A
-import org.dozer.DozerBeanMapper;%0A
 impo
@@ -537,329 +537,67 @@
     
-private final DozerBeanMapper dozerBeanMapper;%0A    private final TeacherRepository teacherRepository;%0A%0A    @Autowired%0A    public TeacherService(DozerBeanMapper dozerBeanMapper, TeacherRepository teacherRepository) %7B%0A        this.dozerBeanMapper = dozerBeanMapper;%0A        this.teacherRepository = teacherRepository;%0A    %7D
+@Autowired%0A    private TeacherRepository teacherRepository;
 %0A%0A  
@@ -968,60 +968,190 @@
     
-return dozerBeanMapper.map(entity, TeacherDto.class)
+TeacherDto dto = new TeacherDto();%0A        dto.setId(entity.getId());%0A        dto.setAbbreviation(entity.getAbbreviation());%0A        dto.setName(entity.getName());%0A        return dto
 ;%0A  

Fix teacher ids not being mapped