1 | package com.example.villadihovo.web.controller.ControllersForAllReservations;
|
---|
2 |
|
---|
3 | import com.example.villadihovo.dto.ReservationForRoomDto;
|
---|
4 | import com.example.villadihovo.model.offers.Rooms;
|
---|
5 | import com.example.villadihovo.model.offers.Villa;
|
---|
6 | import com.example.villadihovo.service.reservation.GuestMakeReservationService;
|
---|
7 | import com.example.villadihovo.service.offers.RoomsService;
|
---|
8 | import com.example.villadihovo.service.offers.VillaService;
|
---|
9 | import lombok.AllArgsConstructor;
|
---|
10 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
11 | import org.springframework.stereotype.Controller;
|
---|
12 | import org.springframework.ui.Model;
|
---|
13 | import org.springframework.web.bind.annotation.*;
|
---|
14 | import org.springframework.web.servlet.ModelAndView;
|
---|
15 |
|
---|
16 | import java.time.LocalDate;
|
---|
17 | import java.util.List;
|
---|
18 |
|
---|
19 | @Controller
|
---|
20 | @AllArgsConstructor
|
---|
21 | @RequestMapping("/reservations/rooms")
|
---|
22 | public class RoomReservationsController {
|
---|
23 |
|
---|
24 | @Autowired
|
---|
25 | GuestMakeReservationService guestMakeReservationService;
|
---|
26 | @Autowired
|
---|
27 | VillaService villaService;
|
---|
28 | @Autowired
|
---|
29 | RoomsService roomsService;
|
---|
30 |
|
---|
31 | @GetMapping
|
---|
32 | public String listAllRoomReservations(Model model){
|
---|
33 | List<ReservationForRoomDto> allRoomReservations = this.guestMakeReservationService.findAllRoomReservations();
|
---|
34 | model.addAttribute("roomReservations", allRoomReservations);
|
---|
35 | return "room-reservations";
|
---|
36 | }
|
---|
37 | @GetMapping("/edit-form/{id}")
|
---|
38 | public String getEditPage(@PathVariable(required = false) Integer id, Model model) {
|
---|
39 | List<Villa> villaList = villaService.listAllVillas();
|
---|
40 | ReservationForRoomDto roomDto = guestMakeReservationService.findRoomReservationByReservationId(id);
|
---|
41 | List<Rooms> availableRooms = roomsService.findAll();
|
---|
42 | model.addAttribute("villas", villaList);
|
---|
43 | model.addAttribute("roomDto", roomDto);
|
---|
44 | model.addAttribute("available_rooms", availableRooms);
|
---|
45 | return "edit-form-rooms";
|
---|
46 | }
|
---|
47 | @PostMapping(value = "/update")
|
---|
48 | public String updateReservation(@RequestParam("reservation_id") Integer reservation_id,
|
---|
49 | @RequestParam("start_date") LocalDate start_date,
|
---|
50 | @RequestParam("end_date") LocalDate end_date,
|
---|
51 | @RequestParam("adults") Integer adults,
|
---|
52 | @RequestParam("children") Integer children,
|
---|
53 | @RequestParam("number_guests") Integer number_guests,
|
---|
54 | Model model){
|
---|
55 | ReservationForRoomDto updatedRoom = guestMakeReservationService.updateRoomReservationById(reservation_id,start_date,end_date,adults,children,number_guests);
|
---|
56 | model.addAttribute("roomDto", updatedRoom);
|
---|
57 | return "redirect:/reservations/rooms";
|
---|
58 | }
|
---|
59 |
|
---|
60 | @DeleteMapping(value = "/delete/{id}")
|
---|
61 | public String deleteReservation(@PathVariable Integer id){
|
---|
62 | guestMakeReservationService.deleteReservationById(id);
|
---|
63 | return "redirect:/reservations/rooms";
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|