package parkup.controllers; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; 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.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import parkup.entities.Vraboten; import parkup.services.VrabotenService; @RestController public class VrabotenController { private final VrabotenService vrabotenService; @Autowired public VrabotenController(VrabotenService vrabotenService) { this.vrabotenService = vrabotenService; } @GetMapping({"/vraboten"}) public List getAllVraboten() { return this.vrabotenService.getVraboteni(); } @GetMapping({"/vraboten/{vrabotenId}"}) public Vraboten getVraboten(@PathVariable int vrabotenId) { Vraboten vraboten = this.vrabotenService.findById(vrabotenId); if (vraboten != null) { return vraboten; } else { throw new RuntimeException("Vraboten not found"); } } @PostMapping({"/vraboten"}) public void addVraboten(@RequestBody Vraboten vraboten) { this.vrabotenService.addVraboten(vraboten); } @PutMapping({"/vraboten/{vrabotenId}"}) public void updateVraboten(@PathVariable int vrabotenId, @RequestBody Vraboten vraboten) { this.vrabotenService.updateVraboten(vrabotenId, vraboten.getFirstName(), vraboten.getLastName(), vraboten.getMobile(), vraboten.getEmail()); } @DeleteMapping({"/vraboten/{vrabotenId}"}) public void deleteVraboten(@PathVariable int vrabotenId) { this.vrabotenService.deleteVraboten(vrabotenId); } }