source: src/main/java/com/example/salonbella/controller/reservation/ReservationUserController.java@ 4d7e387

Last change on this file since 4d7e387 was 4d7e387, checked in by makyjovanovsky <mjovanovski04@…>, 18 months ago

commit 1

  • Property mode set to 100644
File size: 2.2 KB
Line 
1package com.example.salonbella.controller.reservation;
2
3import com.example.salonbella.service.reservation.ReservationResponse;
4import com.example.salonbella.service.reservation.ReservationService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.stereotype.Controller;
7import org.springframework.ui.Model;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12import java.text.ParseException;
13import java.util.List;
14
15@Controller
16public 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}
Note: See TracBrowser for help on using the repository browser.