1 | package com.example.villadihovo.web.controller.ControllersForAllReservations;
|
---|
2 |
|
---|
3 | import com.example.villadihovo.model.offers.Rooms;
|
---|
4 | import com.example.villadihovo.model.users.UserTable;
|
---|
5 | import com.example.villadihovo.service.reservation.ReservationService;
|
---|
6 | import com.example.villadihovo.service.offers.RoomsService;
|
---|
7 | import jakarta.servlet.http.HttpServletRequest;
|
---|
8 | import lombok.AllArgsConstructor;
|
---|
9 | import org.springframework.stereotype.Controller;
|
---|
10 | import org.springframework.ui.Model;
|
---|
11 | import org.springframework.web.bind.annotation.*;
|
---|
12 |
|
---|
13 | import java.time.LocalDate;
|
---|
14 | import java.util.List;
|
---|
15 | import java.util.Optional;
|
---|
16 |
|
---|
17 | @Controller
|
---|
18 | @AllArgsConstructor
|
---|
19 | @RequestMapping("/rooms/available")
|
---|
20 | public class AvailableRoomsController {
|
---|
21 |
|
---|
22 | private RoomsService roomsService;
|
---|
23 | private ReservationService reservationService;
|
---|
24 |
|
---|
25 | @GetMapping
|
---|
26 | public String listAllAvailableRooms(Model model){
|
---|
27 | List<Rooms> availableRooms = this.roomsService.getAvailableRooms();
|
---|
28 | model.addAttribute("availableRooms", availableRooms);
|
---|
29 | return "available-rooms";
|
---|
30 | }
|
---|
31 |
|
---|
32 | @PostMapping("/reserve")
|
---|
33 | public String getReservePage(@RequestParam LocalDate start_date,
|
---|
34 | @RequestParam LocalDate end_date,
|
---|
35 | @RequestParam Integer room_id,
|
---|
36 | Model model){
|
---|
37 | Optional<Rooms> chosenRoom = roomsService.findRoomById(room_id);
|
---|
38 | Rooms rooms = chosenRoom.get();
|
---|
39 | model.addAttribute("start_date", start_date);
|
---|
40 | model.addAttribute("end_date", end_date);
|
---|
41 | model.addAttribute("roomChosen", rooms);
|
---|
42 | return "reservation-form-rooms";
|
---|
43 | }
|
---|
44 | @PostMapping("/reserve/room")
|
---|
45 | public String reserveRoomUsingPost(@RequestParam LocalDate start_date,
|
---|
46 | @RequestParam LocalDate end_date,
|
---|
47 | @RequestParam Integer number_guests,
|
---|
48 | @RequestParam Integer adults,
|
---|
49 | @RequestParam Integer children,
|
---|
50 | @RequestParam Integer room_id,
|
---|
51 | @RequestParam String payment_method,
|
---|
52 | @RequestParam String card_number,
|
---|
53 | @RequestParam Integer price,
|
---|
54 | HttpServletRequest request){
|
---|
55 | UserTable userTable = (UserTable) request.getSession().getAttribute("user");
|
---|
56 | reservationService.addReservation(start_date, end_date, number_guests, adults, children, payment_method, card_number, room_id, userTable, price);
|
---|
57 | return "payment-confirmed";
|
---|
58 | }
|
---|
59 | }
|
---|