[0f3491d] | 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.http.HttpStatus;
|
---|
| 7 | import org.springframework.stereotype.Controller;
|
---|
| 8 | import org.springframework.ui.Model;
|
---|
| 9 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 10 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 11 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 12 | import org.springframework.web.servlet.ModelAndView;
|
---|
| 13 | import org.springframework.web.servlet.View;
|
---|
| 14 |
|
---|
| 15 | import javax.servlet.http.HttpServletRequest;
|
---|
| 16 | import java.text.ParseException;
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
| 19 | @Controller
|
---|
| 20 | public 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 | }
|
---|