Hendrik Jungnitsch
2022-09-19 a0b53aec76f777d22b035ccfda713725ab0b796e
exercise01
1 Dateien geändert
23 ■■■■■ Geänderte Dateien
src/main/java/de/gedoplan/seminar/sbt/sbtrestexercise/rest/PersonResource.java 23 ●●●●● Patch | Ansicht | Raw | Blame | Historie
src/main/java/de/gedoplan/seminar/sbt/sbtrestexercise/rest/PersonResource.java
@@ -1,7 +1,19 @@
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;
@@ -9,4 +21,15 @@
        this.personRepository = personRepository;
    }
    @GetMapping
    public List<Person> 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));
    }
}