package de.gedoplan.seminar.sbt.sbtrestexercise.rest; import de.gedoplan.seminar.sbt.sbtrestexercise.domain.Person; import de.gedoplan.seminar.sbt.sbtrestexercise.repository.PersonRepository; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; import java.util.List; @RestController @RequestMapping(path = "/personen", produces = MediaType.APPLICATION_JSON_VALUE) public class PersonResource { private final PersonRepository personRepository; public PersonResource(PersonRepository personRepository) { this.personRepository = personRepository; } @GetMapping public List getPersonen() { return personRepository.findAll(); } @GetMapping(path = "{id}",produces = MediaType.APPLICATION_JSON_VALUE) public Person getTalk(@PathVariable Integer id) { return personRepository.findById(id) .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); } }