1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.webflow.samples.booking;
20
21 import java.util.List;
22
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Controller;
25 import org.springframework.ui.Model;
26 import org.springframework.web.bind.annotation.PathVariable;
27 import org.springframework.web.bind.annotation.RequestMapping;
28 import org.springframework.web.bind.annotation.RequestMethod;
29
30 @Controller
31 public class BookingsController {
32
33 private TravelService travelService;
34
35 @Autowired
36 public BookingsController(TravelService travelService) {
37 this.travelService = travelService;
38 }
39
40 @RequestMapping(value = "/{userName}/bookings", method = RequestMethod.GET)
41 public void getDashboard(@PathVariable("userName") String userName, Model model) {
42 List<Booking> booking = travelService.findBookings(userName);
43 model.addAttribute(booking);
44 }
45
46 @RequestMapping(value = "/{userName}/bookings/{id}", method = RequestMethod.DELETE)
47 public String deleteBooking(@PathVariable("id") Long id) {
48 travelService.cancelBooking(id);
49 return "redirect:/dashboard";
50 }
51 }