package se.kits.gakusei.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import se.kits.gakusei.content.model.Course;
import se.kits.gakusei.content.repository.CourseRepository;

@RestController
public class CourseController {

    @Autowired
    CourseRepository courseRepository;

    @RequestMapping(
            value = "api/courses",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    public ResponseEntity<Iterable<Course>> getAllCourses(){
        return null;
    }

    @RequestMapping(
            value = "api/courses/{courseID}",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    public ResponseEntity<Course> getCourseByID(@PathVariable(value = "courseID") Long courseID){
        return null;
    }

    @RequestMapping(
            value = "api/courses/{courseName}",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    public ResponseEntity<Course> getCourseByName(@PathVariable(value = "courseName") String courseName){
        return null;
    }

    @RequestMapping(
            value = "api/courses/{courseCode}",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    public ResponseEntity<Course> getCourseByCode(@PathVariable(value = "courseCode") String courseCode){
        return null;
    }

}

@@ -93,16 +93,60 @@
 owired;%0A
+import org.springframework.http.HttpStatus;%0A
 import o
@@ -1835,34 +1835,267 @@
 e)%7B%0A        
-return null;
+Course course = courseRepository.findByCourseCode(courseCode);%0A%0A        if(course != null)%7B%0A            return new ResponseEntity%3C%3E(course, HttpStatus.OK);%0A        %7D else %7B%0A            return new ResponseEntity%3C%3E(HttpStatus.NOT_FOUND);%0A        %7D
 %0A    %7D%0A%0A%7D%0A

Implement getCourseByCode