package de.gedoplan.seminar.jpa.exercise.rest; import java.util.List; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import de.gedoplan.seminar.jpa.exercise.domain.TrafficJam; import de.gedoplan.seminar.jpa.exercise.repository.TrafficJamRepository; @RequestMapping(path = "/trafficjams", produces = MediaType.APPLICATION_JSON_VALUE) @RestController public class TrafficJamResource { @Autowired Logger logger; @Autowired TrafficJamRepository trafficJamRepository; @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) public void insert(@RequestBody TrafficJam trafficJam) { this.logger.debug("----- insert -----"); this.trafficJamRepository.save(trafficJam); this.logger.debug("Inserted: " + trafficJam); } @GetMapping public List findAll() { this.logger.debug("----- findAll -----"); List trafficJams = trafficJamRepository.findAll(); this.logger.debug("Gefunden: " + trafficJams); return trafficJams; } }