source: src/main/java/com/example/villadihovo/web/controller/ControllersForAllReservations/AvailableRoomsController.java

Last change on this file was f7c05a1, checked in by Elena Shulevska <elena.shulevska@…>, 15 months ago

initial commit of the source code on origin

  • Property mode set to 100644
File size: 2.7 KB
Line 
1package com.example.villadihovo.web.controller.ControllersForAllReservations;
2
3import com.example.villadihovo.model.offers.Rooms;
4import com.example.villadihovo.model.users.UserTable;
5import com.example.villadihovo.service.reservation.ReservationService;
6import com.example.villadihovo.service.offers.RoomsService;
7import jakarta.servlet.http.HttpServletRequest;
8import lombok.AllArgsConstructor;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.*;
12
13import java.time.LocalDate;
14import java.util.List;
15import java.util.Optional;
16
17@Controller
18@AllArgsConstructor
19@RequestMapping("/rooms/available")
20public 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}
Note: See TracBrowser for help on using the repository browser.