source: src/main/java/com/example/villadihovo/web/controller/ControllersForAllReservations/RoomReservationsController.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: 3.0 KB
Line 
1package com.example.villadihovo.web.controller.ControllersForAllReservations;
2
3import com.example.villadihovo.dto.ReservationForRoomDto;
4import com.example.villadihovo.model.offers.Rooms;
5import com.example.villadihovo.model.offers.Villa;
6import com.example.villadihovo.service.reservation.GuestMakeReservationService;
7import com.example.villadihovo.service.offers.RoomsService;
8import com.example.villadihovo.service.offers.VillaService;
9import lombok.AllArgsConstructor;
10import org.springframework.beans.factory.annotation.Autowired;
11import org.springframework.stereotype.Controller;
12import org.springframework.ui.Model;
13import org.springframework.web.bind.annotation.*;
14import org.springframework.web.servlet.ModelAndView;
15
16import java.time.LocalDate;
17import java.util.List;
18
19@Controller
20@AllArgsConstructor
21@RequestMapping("/reservations/rooms")
22public 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}
Note: See TracBrowser for help on using the repository browser.