1 | package com.tourMate.controllers;
|
---|
2 |
|
---|
3 | import com.tourMate.dto.HotelDto;
|
---|
4 | import com.tourMate.dto.HotelReservationDto;
|
---|
5 | import com.tourMate.dto.HotelReservationUserDto;
|
---|
6 | import com.tourMate.entities.*;
|
---|
7 | import com.tourMate.services.HotelManager;
|
---|
8 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
9 | import org.springframework.format.annotation.DateTimeFormat;
|
---|
10 | import org.springframework.http.HttpStatus;
|
---|
11 | import org.springframework.http.ResponseEntity;
|
---|
12 | import org.springframework.web.bind.annotation.*;
|
---|
13 |
|
---|
14 | import java.util.Date;
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
18 | @RestController
|
---|
19 | public class HotelController {
|
---|
20 |
|
---|
21 | @Autowired
|
---|
22 | HotelManager hotelManager;
|
---|
23 |
|
---|
24 | //HOTEL CRUD
|
---|
25 | @PostMapping(path = "/hotel/add")
|
---|
26 | public void add(@RequestBody Hotels hotel, @RequestParam(name = "userId") long userId) {
|
---|
27 | hotelManager.createHotel(hotel, userId);
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | @GetMapping(path = "/hotel")
|
---|
32 | public ResponseEntity<List<com.tourMate.entities.Hotels>> showHotels() {
|
---|
33 | try {
|
---|
34 | List<Hotels> hoteli = hotelManager.getHotels();
|
---|
35 | return ResponseEntity.ok(hoteli);
|
---|
36 | } catch (Exception e) {
|
---|
37 | // Handle the exception, log it, and return an error response
|
---|
38 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | @GetMapping(path = "/hotel/user/{id}")
|
---|
43 | public ResponseEntity<List<Hotels>> getHotelsForUser (@PathVariable(name = "id") long userId)
|
---|
44 | {
|
---|
45 | try {
|
---|
46 |
|
---|
47 | List<Hotels> hoteli = hotelManager.getHotelsForUser(userId);
|
---|
48 | return ResponseEntity.ok(hoteli);
|
---|
49 | } catch (Exception e) {
|
---|
50 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | @GetMapping(path = "/hotel/{id}/list")
|
---|
55 | public ResponseEntity<Hotels> getHotelById (@PathVariable(name = "id") long hotelId)
|
---|
56 | {
|
---|
57 | try {
|
---|
58 |
|
---|
59 | return ResponseEntity.ok(hotelManager.findHotelByID(hotelId));
|
---|
60 | } catch (Exception e) {
|
---|
61 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | @PostMapping(path = "/hotel/edit")
|
---|
67 | public void edit(@RequestBody Hotels hotel)
|
---|
68 | {
|
---|
69 | hotelManager.editHotel(hotel.getHotelId(), hotel.getHotelName(), hotel.getHotelDescripiton(), hotel.getHotelLocation(), hotel.getHotelEDBS(), hotel.getParking(), hotel.getPetFriendly(), hotel.getInternetAvailable());
|
---|
70 | }
|
---|
71 |
|
---|
72 | @GetMapping(path = "/hotel/delete")
|
---|
73 | public ResponseEntity remove(@RequestParam(name = "hotelId") long hotelId) {
|
---|
74 | try
|
---|
75 | {
|
---|
76 | hotelManager.deleteHotel(hotelId);
|
---|
77 | return new ResponseEntity(HttpStatus.OK);
|
---|
78 | }
|
---|
79 | catch (Exception exception)
|
---|
80 | {
|
---|
81 | return new ResponseEntity(HttpStatus.NOT_FOUND);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 | @GetMapping(path = "/hotel/images/delete")
|
---|
88 | public ResponseEntity removeHotelImage(@RequestParam(name = "hotelId") long hotelId) {
|
---|
89 | try {
|
---|
90 | hotelManager.deleteHotelImage(hotelId);
|
---|
91 | return new ResponseEntity(HttpStatus.OK);
|
---|
92 | }
|
---|
93 | catch (Exception exception) {
|
---|
94 | return new ResponseEntity(HttpStatus.NOT_FOUND);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | @GetMapping(path = "/hotel/{id}/room")
|
---|
99 | public List<HotelRoom> getHotelRooms(@PathVariable(value = "id") long hotelId)
|
---|
100 | {
|
---|
101 | System.out.println("ovde so id: " + hotelId);
|
---|
102 | return hotelManager.getRoomsOfHotel(hotelId);
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | //HOTEL ROOM CRUD
|
---|
107 | @PostMapping(path = "/hotel/rooms/add")
|
---|
108 | public void addRoom(@RequestBody HotelRoom room,
|
---|
109 | @RequestParam(name = "hotelId") long hotelId) {
|
---|
110 | Hotels h = hotelManager.findHotelByID(hotelId);
|
---|
111 | hotelManager.createRoom(h, room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice(), room.getNumOfBeds());
|
---|
112 | }
|
---|
113 |
|
---|
114 | @PostMapping(path = "/hotel/rooms/edit")
|
---|
115 | public void editRoom(@RequestBody HotelRoom room) {
|
---|
116 | hotelManager.editRoom(room.getHotelRoomId(), room.getHotel(), room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice());
|
---|
117 | }
|
---|
118 |
|
---|
119 | @GetMapping(path = "/hotel/rooms/delete")
|
---|
120 | public ResponseEntity removeRoom(@RequestParam(name = "hotelRoomId") long hotelRoomId) {
|
---|
121 | try
|
---|
122 | {
|
---|
123 | hotelManager.deleteRoom(hotelRoomId);
|
---|
124 | return new ResponseEntity(HttpStatus.OK);
|
---|
125 | }
|
---|
126 | catch (Exception exception)
|
---|
127 | {
|
---|
128 | return new ResponseEntity(HttpStatus.NOT_FOUND);
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | //HOTEL RESERVATION CRUD
|
---|
133 |
|
---|
134 | @PostMapping(path = "/hotel/rooms/reservation/edit")
|
---|
135 | public void editRoomReservation(@RequestBody HotelRoomReservations reservation) {
|
---|
136 | hotelManager.editReservation(reservation.getHotelRoomReservedId(), reservation.getUser(), reservation.getHotelRoom(), reservation.getDateFrom(), reservation.getDateTo(), reservation.getNumberOfBeds());
|
---|
137 | }
|
---|
138 |
|
---|
139 | @GetMapping(path = "/hotel/rooms/reservation/delete")
|
---|
140 | public ResponseEntity removeReservation(@RequestParam(name = "hotelRoomReservationId") long hotelRoomReservationId) {
|
---|
141 | try
|
---|
142 | {
|
---|
143 | hotelManager.deleteReservation(hotelRoomReservationId);
|
---|
144 | return new ResponseEntity(HttpStatus.OK);
|
---|
145 | }
|
---|
146 | catch (Exception exception)
|
---|
147 | {
|
---|
148 | return new ResponseEntity(HttpStatus.NOT_FOUND);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | //HOTEL AVAILABILITY CRUD
|
---|
153 | @PostMapping(path = "/hotel/rooms/available/{id}/add")
|
---|
154 | public void addRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable,
|
---|
155 | @PathVariable long id)
|
---|
156 | {
|
---|
157 | HotelRoom hotelRoom = hotelManager.findRoomById(id);
|
---|
158 | hotelManager.createRoomAvailible(hotelRoom, hotelRoomAvailable.getDateFrom(), hotelRoomAvailable.getDateTo(), hotelRoomAvailable.getNumberOfBeds());
|
---|
159 | }
|
---|
160 |
|
---|
161 | @PostMapping(path = "/hotel/rooms/available/edit")
|
---|
162 | public void editRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable)
|
---|
163 | {
|
---|
164 | hotelManager.editRoomAvailible(hotelRoomAvailable.getHotelRoomAvailableId(), hotelRoomAvailable.getHotelRoom(), hotelRoomAvailable.getDateFrom(), hotelRoomAvailable.getDateTo(), hotelRoomAvailable.getNumberOfBeds());
|
---|
165 | }
|
---|
166 |
|
---|
167 | @GetMapping(path = "/hotel/rooms/available/remove")
|
---|
168 | public ResponseEntity removeRoomAvailible(@RequestParam(name = "hotelRoomAvailibleId") long hotelRoomAvailibleId)
|
---|
169 | {
|
---|
170 | try
|
---|
171 | {
|
---|
172 | hotelManager.deleteRoomAvailible(hotelRoomAvailibleId);
|
---|
173 | return new ResponseEntity(HttpStatus.OK);
|
---|
174 | }
|
---|
175 | catch (Exception ex)
|
---|
176 | {
|
---|
177 | return new ResponseEntity(HttpStatus.NOT_FOUND);
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | @GetMapping(path = "hotel/rooms/{id}/available")
|
---|
182 | public List<HotelRoomAvailable> getRoomAvailability(@PathVariable Long id)
|
---|
183 | {
|
---|
184 | return hotelManager.getRoomsAvailableById(id);
|
---|
185 | }
|
---|
186 |
|
---|
187 | @GetMapping(path = "/hotel/search")
|
---|
188 | public List<HotelDto> searchAvailibleRooms(@RequestParam(name = "hotelLocation") String hotelLocation,
|
---|
189 | @RequestParam(name = "dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
|
---|
190 | @RequestParam(name = "dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo,
|
---|
191 | @RequestParam(name = "numBeds") int numBeds,
|
---|
192 | @RequestParam(name = "flexible") Boolean flexible)
|
---|
193 | {
|
---|
194 | System.out.println(flexible);
|
---|
195 | System.out.println(dateFrom + " " + dateTo);
|
---|
196 | return hotelManager.getRoomsAvailibilityByDateAndLocation(hotelLocation, dateFrom, dateTo, numBeds, flexible);
|
---|
197 | }
|
---|
198 |
|
---|
199 | @PostMapping(path = "/hotel/reserve")
|
---|
200 | public void reserveHotelRoom(@RequestParam(name = "hotelRoomId")Long hotelRoomId,
|
---|
201 | @RequestParam(name = "userId") Long userId,
|
---|
202 | @RequestParam(name = "hotelRoomAvailableId") Long hotelRoomAvailableId,
|
---|
203 | @RequestParam(name = "numberOfBeds") Integer numberOfBeds,
|
---|
204 | @RequestParam(name = "from") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date from,
|
---|
205 | @RequestParam(name = "to") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date to){
|
---|
206 |
|
---|
207 |
|
---|
208 |
|
---|
209 | hotelManager.createReservation(userId, hotelRoomId, hotelRoomAvailableId, from, to, numberOfBeds);
|
---|
210 | }
|
---|
211 |
|
---|
212 | @GetMapping(path = "/hotel/{id}/reservations/active")
|
---|
213 | public List<HotelReservationDto> getActiveReservationsForHotel(@PathVariable Long id)
|
---|
214 | {
|
---|
215 | return hotelManager.findVaidReseravtionsByHotel(id);
|
---|
216 | }
|
---|
217 |
|
---|
218 | @GetMapping(path = "/hotel/reservations/user/{id}")
|
---|
219 | public List<HotelReservationUserDto> getActiveReservationsForUser(@PathVariable Long id)
|
---|
220 | {
|
---|
221 | return hotelManager.findValidHotelReservationsByUser(id);
|
---|
222 | }
|
---|
223 |
|
---|
224 | @GetMapping(path = "/hotel/reservations/user/{id}/past")
|
---|
225 | public List<HotelReservationUserDto> getPastReservationsForUser(@PathVariable Long id)
|
---|
226 | {
|
---|
227 | return hotelManager.findPastHotelReservationsByUser(id);
|
---|
228 | }
|
---|
229 |
|
---|
230 | @GetMapping(path = "/hotel/{id}/images")
|
---|
231 | public List<HotelsImages> getImagesForHotel(@PathVariable Long id)
|
---|
232 | {
|
---|
233 | return hotelManager.getHotelImages(id);
|
---|
234 | }
|
---|
235 |
|
---|
236 | @GetMapping(path = "/room/{id}/images")
|
---|
237 | public List<HotelRoomImages> getImagesForHotelRoom(@PathVariable Long id)
|
---|
238 | {
|
---|
239 | return hotelManager.getRoomImages(id);
|
---|
240 | }
|
---|
241 |
|
---|
242 | @PostMapping("/hotel/{id}/cancel")
|
---|
243 | public void cancelHotelReservation(@PathVariable Long id){
|
---|
244 | hotelManager.deleteReservation(id);
|
---|
245 | }
|
---|
246 |
|
---|
247 | }
|
---|