source: src/main/java/com/tourMate/dao/impl/HotelDaoImpl.java@ 5528b99

Last change on this file since 5528b99 was 5528b99, checked in by darsov2 <62809499+darsov2@…>, 12 months ago

revert

  • Property mode set to 100644
File size: 9.9 KB
Line 
1package com.tourMate.dao.impl;
2
3import com.tourMate.dao.HotelDao;
4import com.tourMate.entities.*;
5import jakarta.persistence.EntityManager;
6import jakarta.persistence.PersistenceContext;
7import jakarta.transaction.Transactional;
8import org.springframework.stereotype.Service;
9
10import java.util.Date;
11import java.util.List;
12
13@Service
14public class HotelDaoImpl implements HotelDao {
15
16 @PersistenceContext
17 EntityManager em;
18
19 @Override
20 @Transactional
21 public void createHotel(Hotels hotel, long userId) {
22 User u = em.find(User.class, userId);
23 Hotels h = new Hotels(hotel.getHotelName(), hotel.getHotelDescripiton(), hotel.getHotelLocation(), hotel.getHotelEDBS(), hotel.getParking(), hotel.getPetFriendly(), hotel.getInternetAvailable(), u);
24 em.persist(h);
25 }
26
27 @Override
28 public List<Hotels> getHotels() {
29 List<Hotels> hoteli = em.createQuery("select h from Hotels h order by h.hotelId").getResultList();
30 System.out.println("OREEEEEEL");
31 return hoteli;
32 //return em.createQuery("select h from Hotels h order by h.hotelId").getResultList();
33 }
34
35 @Override
36 public List<Hotels> getHotelsForUser(long userId) {
37 User u = em.find(User.class, userId);
38 return em.createQuery("select h from Hotels h where h.owner = :u").setParameter("u", u).getResultList();
39 }
40
41 @Override
42 public List<Hotels> getHotelsByLocation(String hotelLocation) {
43 return em.createQuery("select h from Hotels h where h.hotelLocation = hotelLocation").getResultList();
44 }
45
46 @Transactional
47 @Override
48 public void editHotel(long hotelId, String hotelName, String hotelDescripiton, String hotelLocation, String hotelEDBS, Boolean parking, Boolean petFriendly, Boolean internetAvailable) {
49 Hotels hotel = findHotelByID(hotelId);
50 hotel.setHotelName(hotelName);
51 hotel.setHotelDescripiton(hotelDescripiton);
52 hotel.setHotelLocation(hotelLocation);
53 hotel.setHotelEDBS(hotelEDBS);
54 hotel.setParking(parking);
55 hotel.setPetFriendly(petFriendly);
56 hotel.setInternetAvailable(internetAvailable);
57 em.persist(hotel);
58 }
59
60 @Transactional
61 @Override
62 public void deleteHotel(long hotelId) {
63 Hotels h = findHotelByID(hotelId);
64 em.remove(h);
65 }
66
67 @Override
68 public Hotels findHotelByID(long hotelId) {
69 return em.find(Hotels.class, hotelId);
70 }
71
72 @Override
73 public List<HotelsImages> getHotelImages(Hotels hotel) {
74 return em.createQuery("select hi from HotelsImages hi where hi.hotel = :hotel").setParameter("hotel", hotel).getResultList();
75 }
76
77 @Override
78 @Transactional
79 public void addHotelImage(HotelsImages image) {
80 em.persist(image);
81 }
82
83 @Transactional
84 @Override
85 public void addRoomImage(HotelRoomImages x) {
86 em.persist(x);
87 }
88
89 @Override
90 @Transactional
91 public HotelsImages findHotelImageById(long hotelImageId) {
92 return em.find(HotelsImages.class, hotelImageId);
93 }
94
95 @Override
96 @Transactional
97 public void deleteHotelImage(long hotelImageId) {
98 HotelsImages hotelsImages = findHotelImageById(hotelImageId);
99 em.remove(hotelsImages);
100 }
101
102 @Override
103 public List<HotelRoom> getRoomsOfHotel(long hotelId) {
104 Hotels h = findHotelByID(hotelId);
105 return em.createQuery("SELECT hr from HotelRoom hr where hr.hotel = :hotel").setParameter("hotel", h).getResultList();
106 }
107
108 @Override
109 public List<HotelRoomAvailable> getRoomsAvailable(Long id) {
110 return em.createQuery("SELECT hra from HotelRoomAvailable hra WHERE hra.hotelRoom.id = :hotelRoomId").setParameter("hotelRoomId", id).getResultList();
111 }
112
113 @Override
114 public HotelRoom findRoomById(long hotelRoomId) {
115 return em.find(HotelRoom.class, hotelRoomId);
116 }
117
118 @Override
119 public List<HotelRoomImages> getRoomImages(HotelRoom hotelRoom) {
120 return em.createQuery("select i from HotelRoomImages i where i.room = :hotelRoom").setParameter("hotelRoom", hotelRoom).getResultList();
121 }
122
123 @Transactional
124 @Override
125 public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
126 HotelRoom hotelRoom = new HotelRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price);
127 em.persist(hotelRoom);
128 }
129
130 @Transactional
131 @Override
132 public void editRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
133 HotelRoom hr = findRoomById(hotelRoomId);
134 hr.setHotel(hotel);
135 hr.setHotelRoomDescription(hotelRoomDescription);
136 hr.setHotelRoomName(hotelRoomName);
137 hr.setKitchenAvailable(kitchenAvailable);
138 hr.setAirConditioning(airConditioning);
139 hr.setBalcony(balcony);
140 hr.setPrice(price);
141 em.persist(hr);
142 }
143
144 @Transactional
145 @Override
146 public void deleteRoom(long hotelRoomId) {
147 HotelRoom hr = findRoomById(hotelRoomId);
148 em.remove(hr);
149 }
150
151 @Transactional
152 @Override
153 public void createRoomAvailible(HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds) {
154 HotelRoomAvailable hra = new HotelRoomAvailable(hotelRoom, dateFrom, dateTo, numberOfBeds);
155 em.persist(hra);
156 }
157
158 @Transactional
159 @Override
160 public void editRoomAvailible(long hotelRoomAvailableId, HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds) {
161 HotelRoomAvailable hr = findAvailibleRoomById(hotelRoomAvailableId);
162 hr.setHotelRoom(hotelRoom);
163 hr.setDateFrom(dateFrom);
164 hr.setDateTo(dateTo);
165 hr.setNumberOfBeds(numberOfBeds);
166 em.persist(hr);
167 }
168
169 @Transactional
170 @Override
171 public void deleteRoomAvailible(long hotelRoomAvailableId) {
172 HotelRoomAvailable hra = findAvailibleRoomById(hotelRoomAvailableId);
173 em.remove(hra);
174 }
175
176 @Override
177 public HotelRoomAvailable findAvailibleRoomById(long hotelRoomAvailableId) {
178 return em.find(HotelRoomAvailable.class, hotelRoomAvailableId);
179 }
180
181 @Override
182 public List<HotelRoomAvailable> getRoomsAvailibility() {
183 return em.createQuery("select hra from HotelRoomAvailable hra").getResultList();
184 }
185
186 @Override
187 public List<HotelRoomAvailable> getRoomsAvailibilityByHotel(Hotels hotel) {
188 return em.createQuery("select hr from HotelRoomAvailable hr where hr.hotelRoom.hotel = :hotel").setParameter("hotel", hotel).getResultList();
189 }
190
191 @Override
192 public List<HotelRoomAvailable> getRoomsAvailibilityByDateAndLocation(String hotelLocation, Date dateFrom, Date dateTo, int numberOfBeds) {
193 return em.createQuery("select hr from HotelRoomAvailable hr where hr.dateFrom <= :dateFrom and hr.dateTo >= :dateTo " +
194<<<<<<< HEAD
195 "and hr.hotelRoom.hotel.hotelLocation LIKE :hotelLocation and hr.hotelRoom.numOfBeds >= :numBeds")
196=======
197 "and hr.hotelRoom.hotel.hotelLocation LIKE :hotelLocation and hr.numberOfBeds >= :numBeds")
198>>>>>>> parent of ac19a0c (authContext impl, admin panel impl, search bar fixes, reservations listings impl)
199 .setParameter("hotelLocation", hotelLocation)
200 .setParameter("dateFrom", dateFrom)
201 .setParameter("dateTo", dateTo)
202 .setParameter("numBeds", numberOfBeds)
203 .getResultList();
204 }
205
206 @Override
207 @Transactional
208 public void createReservation(User user, HotelRoom hotelRoom, Date dateFrom, Date dateTo, Integer numberOfBeds) {
209 HotelRoomReservations r = new HotelRoomReservations(user, hotelRoom, dateFrom, dateTo, numberOfBeds);
210 em.persist(r);
211 }
212
213 @Override
214 @Transactional
215 public void editReservation(long hotelRoomReservedId, User user, HotelRoom hotelRoom, Date dateFrom, Date dateTo, Integer numberOfBeds) {
216 HotelRoomReservations hr = findReservationById(hotelRoomReservedId);
217 hr.setUser(user);
218 hr.setHotelRoom(hotelRoom);
219 hr.setDateFrom(dateFrom);
220 hr.setDateTo(dateTo);
221 hr.setNumberOfBeds(numberOfBeds);
222 em.persist(hr);
223
224 }
225
226 @Transactional
227 @Override
228 public void deleteReservation(long hotelRoomReservedId) {
229 HotelRoomReservations r = findReservationById(hotelRoomReservedId);
230 em.remove(hotelRoomReservedId);
231 }
232
233 @Override
234 public HotelRoomReservations findReservationById(long hotelRoomReservedId) {
235 return em.find(HotelRoomReservations.class, hotelRoomReservedId);
236 }
237
238 @Override
239 public List<HotelRoomReservations> findReservationByUser(User user) {
240 return em.createQuery("select hr from HotelRoomReservations hr where hr.user = :user and hr.dateTo >= now()")
241 .setParameter("user", user).getResultList();
242 }
243
244 @Override
245 public List<HotelRoomReservations> findReservationByHotel(Hotels hotel) {
246 List<HotelRoom> hotelRooms = getRoomsOfHotel(hotel.getHotelId());
247 return em.createQuery("select hr from HotelRoomReservations hr where hr.hotelRoom in :hotelRooms").setParameter("hotelRooms", hotelRooms).getResultList();
248 }
249
250 @Override
251 public List<HotelRoomReservations> getReservations() {
252 return em.createQuery("select hr from HotelRoomReservations hr order by hr.user.name").getResultList();
253 }
254
255 @Override
256 public List<Reviews> findReviewsByHotel(Hotels hotel) {
257 return em.createQuery("select r from Reviews r where r.hotel = :hotel")
258 .setParameter("hotel", hotel)
259 .getResultList();
260 }
261
262 @Override
263 public List<HotelRoomReservations> findPastReservationByUser(User u) {
264 return em.createQuery("select hr from HotelRoomReservations hr where hr.user = :user and hr.dateTo <= now()")
265 .setParameter("user", u).getResultList();
266 }
267}
Note: See TracBrowser for help on using the repository browser.