package li.l1t.tingo.rest;

import li.l1t.tingo.model.dto.TeacherDto;
import li.l1t.tingo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * REST controller providing an API for getting information about teachers and modifying it.
 *
 * @author <a href="http://xxyy.github.io/">xxyy</a>
 * @since 2016-02-14
 */
@RestController
public class TeacherController {
    private final TeacherService teacherService;

    @Autowired
    TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }


    @RequestMapping("/api/teacher/list")
    public List<TeacherDto> teacherList() {
        return StreamSupport.stream(teacherService.getAllTeachers().spliterator(), false)
                .map(teacherService::toDto)
                .collect(Collectors.toList());
    }
}

@@ -21,16 +21,107 @@
 .rest;%0A%0A
+import li.l1t.tingo.exception.JsonPropagatingException;%0Aimport li.l1t.tingo.model.Teacher;%0A
 import l
@@ -261,16 +261,77 @@
 owired;%0A
+import org.springframework.web.bind.annotation.PathVariable;%0A
 import o
@@ -1220,11 +1220,361 @@
 );%0A    %7D
+%0A%0A    @RequestMapping(%22/api/teacher/by/id/%7Bid%7D%22)%0A    public Teacher singleTeacher(@PathVariable(%22id%22) int id) %7B%0A        Teacher teacher = teacherService.getById(id);%0A        if(teacher == null) %7B%0A            throw new JsonPropagatingException(new NullPointerException(%22Unknown teacher!%22));%0A        %7D else %7B%0A            return teacher;%0A        %7D%0A    %7D
 %0A%7D%0A

Add teacher by id API