1 | package com.example.salonbella.controller.reservation;
|
---|
2 |
|
---|
3 | import com.example.salonbella.service.reservation.ReservationResponse;
|
---|
4 | import com.example.salonbella.service.reservation.ReservationService;
|
---|
5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
6 | import org.springframework.stereotype.Controller;
|
---|
7 | import org.springframework.ui.Model;
|
---|
8 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
10 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
11 |
|
---|
12 | import java.text.ParseException;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Controller
|
---|
16 | public class ReservationUserController {
|
---|
17 |
|
---|
18 | private final ReservationService reservationService;
|
---|
19 |
|
---|
20 | @Autowired
|
---|
21 | public ReservationUserController(ReservationService reservationService) {
|
---|
22 | this.reservationService = reservationService;
|
---|
23 | }
|
---|
24 |
|
---|
25 | @GetMapping("/schedule-reservation")
|
---|
26 | public String getUserPage() {
|
---|
27 | return "user-schedule-reservation";
|
---|
28 | }
|
---|
29 |
|
---|
30 | @GetMapping("/my-reservations")
|
---|
31 | public String getReservationsUser(Model model) {
|
---|
32 | List<ReservationResponse> reservations = reservationService.getUserReservations();
|
---|
33 | model.addAttribute("reservations", reservations);
|
---|
34 | return "user-my-reservations";
|
---|
35 | }
|
---|
36 |
|
---|
37 | @PostMapping("/get-free-reservations")
|
---|
38 | public String getFreeReservations(@RequestParam("date") String date, @RequestParam("type") String type, Model model) throws ParseException {
|
---|
39 | model.addAttribute("free_reservations", reservationService.getFreeReservations(date, type));
|
---|
40 | model.addAttribute("date", date);
|
---|
41 | model.addAttribute("tip", type);
|
---|
42 | return "user-schedule-reservation";
|
---|
43 | }
|
---|
44 |
|
---|
45 | @PostMapping("/make-reservation")
|
---|
46 | public String makeReservation(@RequestParam("date") String date, @RequestParam("type") String type, @RequestParam("time") String time) {
|
---|
47 | reservationService.makeReservation(date, time, type);
|
---|
48 | return "redirect:/userDashboard";
|
---|
49 | }
|
---|
50 |
|
---|
51 | @PostMapping("/cancel-reservation")
|
---|
52 | public String cancelReservation(@RequestParam("id") String id) {
|
---|
53 | reservationService.cancelReservation(Long.parseLong(id));
|
---|
54 | return "redirect:/my-reservations";
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | } |
---|