source: src/main/java/com/example/salonbella/controller/reservation/ReservationAdminController.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: 4.0 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.http.HttpStatus;
7import org.springframework.stereotype.Controller;
8import org.springframework.ui.Model;
9import org.springframework.web.bind.annotation.GetMapping;
10import org.springframework.web.bind.annotation.PostMapping;
11import org.springframework.web.bind.annotation.RequestParam;
12import org.springframework.web.servlet.ModelAndView;
13import org.springframework.web.servlet.View;
14
15import javax.servlet.http.HttpServletRequest;
16import java.text.ParseException;
17import java.util.List;
18
19@Controller
20public class ReservationAdminController {
21
22 private final ReservationService reservationService;
23
24 @Autowired
25 public ReservationAdminController(ReservationService reservationService) {
26 this.reservationService = reservationService;
27 }
28
29
30 @GetMapping("/admin-scheduled-reservations")
31 public String getScheduledReservations() {
32 return "admin-reservations";
33 }
34
35 @GetMapping("/admin-block-reservation")
36 public String getBlockReservationPage() {
37 return "admin-block-reservation";
38 }
39
40 @GetMapping("/admin-schedule-reservation")
41 public String getReservationPage() {
42 return "admin-schedule-reservation";
43 }
44
45 @GetMapping("/admin-get-blocked-reservations")
46 public String getBlockedReservations(Model model) {
47 List<ReservationResponse> list = reservationService.getBlockedReservations();
48 model.addAttribute("reservations", list);
49 return "admin-blocked-reservations";
50 }
51
52 @PostMapping("/admin-get-scheduled-reservations")
53 public String getScheduledReservations(@RequestParam("date") String date, @RequestParam("type") String type, Model model) {
54 List<ReservationResponse> reservations = reservationService.getScheduledReservations(date, type);
55 model.addAttribute("reservations", reservations);
56 model.addAttribute("date", date);
57 model.addAttribute("type", type);
58 return "admin-scheduled-reservations";
59 }
60
61 @PostMapping("/admin-cancel-reservation")
62 public ModelAndView cancelReservation(@RequestParam("id") String id, @RequestParam("date") String date,
63 @RequestParam("type") String type, HttpServletRequest request) {
64 reservationService.cancelReservationAdmin(Long.parseLong(id));
65 request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
66 request.setAttribute("date", date);
67 request.setAttribute("type", type);
68 return new ModelAndView("redirect:/admin-get-scheduled-reservations");
69 }
70
71
72 @PostMapping("/admin-block-reservation")
73 public String blockReservation(@RequestParam("date") String date, @RequestParam("type") String type, @RequestParam("time") String time) {
74 reservationService.blockReservation(date, time, type);
75 return "redirect:/adminDashboard";
76 }
77
78 @PostMapping("/admin-unblock-reservation")
79 public String unblockReservation(@RequestParam("id") String id) {
80 reservationService.unblockReservation(Long.parseLong(id));
81 return "redirect:/admin-get-blocked-reservations";
82 }
83
84 @PostMapping("/admin-get-free-reservations")
85 public String getFreeReservations(@RequestParam("date") String date, @RequestParam("type") String type, Model model) throws ParseException {
86 model.addAttribute("free_reservations", reservationService.getFreeReservations(date, type));
87 model.addAttribute("date", date);
88 model.addAttribute("tip", type);
89 return "admin-schedule-reservation";
90 }
91
92 @PostMapping("/admin-make-reservation")
93 public String makeReservation(@RequestParam("date") String date, @RequestParam("type") String type, @RequestParam("time") String time) {
94 reservationService.makeReservation(date, time, type);
95 return "redirect:/adminDashboard";
96 }
97
98}
Note: See TracBrowser for help on using the repository browser.