| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.server.ResponseStatusException; |
| | | |
| | | import de.gedoplan.seminar.jpa.exercise.domain.Highway; |
| | | import de.gedoplan.seminar.jpa.exercise.domain.Junction; |
| | | import de.gedoplan.seminar.jpa.exercise.repository.HighwayRepository; |
| | | import de.gedoplan.seminar.jpa.exercise.repository.JunctionRepository; |
| | | |
| | | @RestController |
| | |
| | | |
| | | @Autowired |
| | | JunctionRepository junctionRepository; |
| | | |
| | | @Autowired |
| | | HighwayRepository highwayRepository; |
| | | |
| | | /** |
| | | * Exercise JPA_BASICS_02: Insert test data. |
| | |
| | | return junction.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); |
| | | } |
| | | |
| | | @Transactional |
| | | @PutMapping("/{junctionId}/assignToHighway/{highwayId}") |
| | | public void assignToHighway(@PathVariable Integer junctionId, @PathVariable Integer highwayId) { |
| | | |
| | | Highway highwayRef = highwayRepository.getReferenceById(highwayId); |
| | | Junction junction = junctionRepository.findById(junctionId).orElseThrow(); |
| | | junction.setHighway(highwayRef); |
| | | } |
| | | } |