package nl.orangeflamingo.controller;

import nl.orangeflamingo.SongRepository;
import nl.orangeflamingo.domain.Song;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SongController {

    @Autowired
    private SongRepository songRepository;

    @RequestMapping("/song")
    public Song greeting(@RequestParam(value = "title", defaultValue = "Roxanne") String title) {
        Song song = new Song();
        song.setArtist("The Police");
        song.setTitle(title);
        return song;
    }

    @RequestMapping("/songs")
    public List<Song> allSongs() {
        return songRepository.findAll();
    }
}

@@ -28,24 +28,74 @@
 ontroller;%0A%0A
+import com.fasterxml.jackson.annotation.JsonView;%0A
 import nl.or
@@ -160,32 +160,70 @@
 in.Song;%0Aimport 
+nl.orangeflamingo.domain.View;%0Aimport 
 org.springframew
@@ -264,132 +264,8 @@
 ired
-;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestParam
 ;%0Aim
@@ -309,30 +309,17 @@
 otation.
-RestController
+*
 ;%0A%0Aimpor
@@ -480,138 +480,118 @@
     
-public Song greeting(@RequestParam(value = %22title%22, defaultValue = %22Roxanne%22) String title) %7B%0A        Song song = new Song
+@JsonView(View.Summary.class)%0A    public List%3CSong%3E allSongs() %7B%0A        return songRepository.findAll
 ();%0A    
     
@@ -590,203 +590,268 @@
     
+%7D%0A%0A
     
-song.setArtist(%22The Police
+@RequestMapping(%22song/%7Bid%7D
 %22)
-;
 %0A    
-    song.setTitle(title);%0A        return song;%0A    %7D%0A%0A    @RequestMapping(%22/songs%22)%0A    public List%3CSong%3E allSongs() %7B%0A        return songRepository.findAll(
+@ResponseBody%0A    @JsonView(View.Detail.class)%0A    public Song getSongById(@PathVariable long id) %7B%0A        return songRepository.findById(id).orElseThrow(() -%3E new IllegalArgumentException(%22Song not found for id %22 + id)
 );%0A 

Improve songcontroller