| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package pl.sudra.controller;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import pl.sudra.domain.Boat;
- import pl.sudra.service.BoatService;
- import java.util.List;
- @RestController
- @CrossOrigin(origins = "http://localhost:1410")
- public class BoatController {
- private final BoatService boatService;
- @Autowired
- public BoatController(BoatService boatService) {
- this.boatService = boatService;
- }
- @RequestMapping(
- value = "/getAllBoats",
- method = RequestMethod.GET,
- produces = MediaType.APPLICATION_JSON_VALUE)
- public List<Boat> listAddresses() {
- System.out.println("Getting Boats");
- return boatService.getBoats();
- }
- // test request
- @RequestMapping(value = "/hello", method = RequestMethod.GET)
- public String sayHello() {
- System.out.println("Greetings!");
- return "Hello";
- }
- @RequestMapping(value = "/addBoat", method = RequestMethod.POST)
- public boolean addBoat(@RequestBody Boat boat) {
- System.out.println(boat.toString());
- boatService.addBoat(boat);
- return true;
- }
- @RequestMapping(
- value = "/getBoatNameById",
- method = RequestMethod.GET,
- produces = MediaType.APPLICATION_JSON_VALUE)
- public String getBoatNameById(@RequestParam("id") Long id) {
- return this.boatService.getBoat(id).getName();
- }
- }
|