- Timestamp:
- 01/24/24 17:42:28 (10 months ago)
- Branches:
- master
- Children:
- 0f5aa27
- Parents:
- 5528b99
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/tourMate/services/impl/RestaurantManagerImpl.java
r5528b99 r07f4e8b 3 3 import com.tourMate.dao.RestaurantDao; 4 4 import com.tourMate.dto.RestaurantDto; 5 import com.tourMate.dto.RestaurantReservationDto; 5 6 import com.tourMate.dto.RestaurantReservationUserDto; 6 7 import com.tourMate.services.RestaurantManager; … … 22 23 @Autowired 23 24 UsersManager usersManager; 25 24 26 @Override 25 27 public void createRestaurant(Restaurant restaurant, long userId) { 26 restaurantDao.createRestaurant(restaurant, userId); 27 } 28 29 28 User u = usersManager.findUserByID(userId); 29 Restaurant r = new Restaurant(restaurant.getRestaurantName(), restaurant.getRestaurantLocation(), restaurant.getCousineType(), restaurant.getRestaurantDescription(), restaurant.getRestaurantEdbs(), u); 30 restaurantDao.createRestaurant(r); 31 } 32 33 @Override 34 public void deleteRestaurant(Long restaurantID) { 35 Restaurant r = findRestaurantByID(restaurantID); 36 restaurantDao.deleteRestaurant(r); 37 } 38 39 @Override 40 public void addMenuToRestaurant(long restaurantId, Menu menu) { 41 Restaurant r = findRestaurantByID(restaurantId); 42 menu.setRestaurant(r); 43 restaurantDao.addMenuToRestaurant(menu); 44 } 45 46 @Override 47 public List<Restaurant> getRestaurantsByUser(long userId) { 48 User u = usersManager.findUserByID(userId); 49 return restaurantDao.getRestaurantsByUser(u); 50 } 30 51 31 52 @Override 32 53 public void deleteRestaurant(long restaurantID) { 33 restaurantDao.deleteRestaurant(restaurantID); 34 } 35 36 @Override 37 public void addMenuToRestaurant(long restaurantId, Menu menu) { 38 restaurantDao.addMenuToRestaurant(restaurantId, menu); 39 } 40 41 @Override 42 public List<Restaurant> getRestaurantsByUser(long userId) { 43 return restaurantDao.getRestaurantsByUser(userId); 44 } 45 46 @Override 47 public void deleteHotel(long restaurantID) { 48 restaurantDao.deleteRestaurant(restaurantID); 54 Restaurant r = findRestaurantByID(restaurantID); 55 restaurantDao.deleteRestaurant(r); 49 56 } 50 57 … … 67 74 @Override 68 75 public void removeRestaurantImage(long restaurantImageId) { 69 restaurantDao.removeRestaurantImage(restaurantImageId); 76 RestaurantImages restaurantImage = findRestaurantImageById(restaurantImageId); 77 restaurantDao.removeRestaurantImage(restaurantImage); 70 78 } 71 79 … … 81 89 82 90 @Override 83 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date hourFrom, Date hourTo, int noSeats) {91 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date hourFrom, Date hourTo, int noSeats) { 84 92 List<RestaurantsAvailible> restaurantsAvailibles = restaurantDao.getTablesByDateAndLocation(restaurantLocation, hourFrom, hourTo, noSeats); 85 93 Map<Restaurant, List<RestaurantsAvailible>> tablesByRestaurants = restaurantsAvailibles.stream().collect(Collectors.groupingBy(x -> x.getRestaurantTable().getRestaurant())); … … 96 104 getReviewsForRestaurant(x.getRestaurantID()), 97 105 getReviewsForRestaurant(x.getRestaurantID()).stream().mapToDouble(Reviews::getNumStar).average().orElse(0), 98 getRestaurantImages(x.getRestaurantID()) 106 getRestaurantImages(x.getRestaurantID()), 107 getMenuImagesByRestaurant(x.getRestaurantID()) 99 108 )).toList(); 100 109 return restaurantsList; … … 103 112 @Override 104 113 public void editRestaurant(long restaurantID, String restaurantName, String restaurantLocation, String cousineType, String restaurantDescription, String restaurantEdbs, User restaurantOwner) { 105 restaurantDao.editRestaurant(restaurantID, restaurantName, restaurantLocation, cousineType, restaurantDescription, restaurantEdbs, restaurantOwner); 114 Restaurant res = findRestaurantByID(restaurantID); 115 res.setRestaurantName(restaurantName); 116 res.setRestaurantLocation(restaurantLocation); 117 res.setRestaurantEdbs(restaurantEdbs); 118 res.setRestaurantDescription(restaurantDescription); 119 res.setRestaurantOwner(restaurantOwner); 120 res.setCousineType(cousineType); 121 restaurantDao.createRestaurant(res); 122 } 123 124 @Override 125 public void editReservation(long restaurantsTableId, RestaurantsTable rt, Date hourFrom, Date hourTo, int noSeats, User user){ 126 RestaurantReservations r = findReservationByID(restaurantsTableId); 127 r.setTable(rt); 128 r.setTimeFrom(hourFrom); 129 r.setTimeTo(hourTo); 130 r.setNoSeats(noSeats); 131 r.setUser(user); 132 restaurantDao.saveReservation(r); 106 133 } 107 134 … … 119 146 public void createTable(Long restaurantId, int noSeats) { 120 147 Restaurant r = restaurantDao.findRestaurantByID(restaurantId); 121 restaurantDao.createTable(r, noSeats); 148 RestaurantsTable restaurantsTable = new RestaurantsTable(r, noSeats); 149 restaurantDao.saveTable(restaurantsTable); 122 150 } 123 151 124 152 @Override 125 153 public void editTable(Restaurant restaurant, long tableId, int noSeats) { 126 restaurantDao.editTable(restaurant, tableId, noSeats); 154 RestaurantsTable resTable = findTableById(tableId); 155 resTable.setRestaurant(restaurant); 156 resTable.setNoSeats(noSeats); 157 restaurantDao.saveTable(resTable); 127 158 } 128 159 129 160 @Override 130 161 public void deleteTable(long tableId) { 131 restaurantDao.deleteTable(tableId); 132 } 133 134 @Override 135 public void createTableAvailable(Long rt, Date hourFrom, Date hourTo) { 162 RestaurantsTable rt = findTableById(tableId); 163 restaurantDao.deleteTable(rt); 164 } 165 166 @Override 167 public void createTableAvailable(Long rt, Date hourFrom, Date hourTo, int numTables) { 136 168 RestaurantsTable rtabl = findTableById(rt); 137 restaurantDao.createTableAvailable(rtabl, hourFrom, hourTo);138 }139 140 @Override 141 public List<RestaurantsAvailible> getTablesAvailabilityById(Long id)142 {169 RestaurantsAvailible ra = new RestaurantsAvailible(rtabl, hourFrom, hourTo, numTables); 170 restaurantDao.saveTableAvailable(ra); 171 } 172 173 @Override 174 public List<RestaurantsAvailible> getTablesAvailabilityById(Long id) { 143 175 return restaurantDao.getTablesAvailabilityById(id); 144 176 } … … 146 178 @Override 147 179 public void editTableAvailable(long tableId, Restaurant restaurant, int noSeats) { 148 restaurantDao.editTableAvailable(tableId, restaurant, noSeats); 180 RestaurantsTable rt = findTableById(tableId); 181 rt.setRestaurant(restaurant); 182 rt.setNoSeats(noSeats); 183 restaurantDao.saveTable(rt); 149 184 } 150 185 151 186 @Override 152 187 public void deleteTableAvailable(long tableId) { 153 restaurantDao.deleteTableAvailable(tableId); 154 } 155 156 @Override 157 public List<RestaurantsTable> getTablesAvailability() { 158 return null; 159 } 160 161 @Override 162 public void createReservation(Restaurant restaurant, int noSeats) { 163 188 RestaurantsAvailible ra = findAvailableReservationByID(tableId); 189 restaurantDao.deleteTableAvailable(ra); 190 } 191 192 @Override 193 public RestaurantsAvailible findAvailableReservationByID(long tableId){ 194 return restaurantDao.findAvailableReservationByID(tableId); 164 195 } 165 196 … … 170 201 } 171 202 172 @Override173 public void editReservation(long tableId, Restaurant restaurant, int noSeats) {174 //restaurantDao.editReservation(tableId, restaurant, noSeats);175 }176 203 177 204 @Override 178 205 public void deleteReservation(long tableId) { 179 restaurantDao.deleteReservation(tableId); 206 RestaurantReservations r = findReservationByID(tableId); 207 RestaurantsAvailible ra = new RestaurantsAvailible(r.getTable(), r.getTimeFrom(), r.getTimeTo(), r.getNoSeats()); 208 restaurantDao.saveTableAvailable(ra); 209 restaurantDao.deleteReservation(r); 180 210 } 181 211 182 212 @Override 183 213 public RestaurantReservations findReservationByID(long tableId) { 184 //return restaurantDao.findReservationByID(tableId); 185 return null; 186 } 187 188 @Override 189 public List<RestaurantReservations> findAvailableReservationByID() { 190 return null; 191 } 192 193 @Override 194 public List<RestaurantReservations> findAvailableReservationByID(long reservationId) { 195 return null; 196 // return restaurantDao.findAvailableReservationByID(reservationId); 214 return restaurantDao.findReservationByID(tableId); 215 //return null; 197 216 } 198 217 … … 203 222 204 223 @Override 205 public List<RestaurantReservations> findReservationByRestaurant(Restaurant restaurant) { 206 return restaurantDao.findReservationByRestaurant(restaurant); 224 public List<RestaurantReservationDto> findReservationByRestaurant(Long restaurant) { 225 Restaurant r = findRestaurantByID(restaurant); 226 List<RestaurantReservations> res = restaurantDao.findReservationByRestaurant(r); 227 return res.stream().map(x -> new RestaurantReservationDto( 228 x.getUser(), 229 x.getTable(), 230 x.getTimeFrom(), 231 x.getTimeTo() 232 )).collect(Collectors.toList()); 207 233 } 208 234 … … 251 277 } 252 278 253 public void editTableAvailability(RestaurantsAvailible restaurantsAvailible, RestaurantsTable table, Date dateFrom, Date dateTo) 254 { 279 public void editTableAvailability(RestaurantsAvailible restaurantsAvailible, RestaurantsTable table, Date dateFrom, Date dateTo) { 255 280 restaurantsAvailible.setNumTables(restaurantsAvailible.getNumTables() - 1); 256 restaurantDao.createTableAvailable(table, restaurantsAvailible.getHourFrom(), dateFrom, 1); 257 restaurantDao.createTableAvailable(table, dateTo, restaurantsAvailible.getHourTo(), 1); 281 RestaurantsAvailible ra1 = new RestaurantsAvailible(table, restaurantsAvailible.getHourFrom(), dateFrom, 1); 282 RestaurantsAvailible ra2 = new RestaurantsAvailible(table, dateTo, restaurantsAvailible.getHourTo(), 1); 283 284 restaurantDao.saveTableAvailable(ra1); 285 restaurantDao.saveTableAvailable(ra2); 258 286 } 259 287 … … 263 291 List<RestaurantReservations> reservations = restaurantDao.findReservationByUser(u); 264 292 return reservations.stream().map(x -> new RestaurantReservationUserDto( 293 x.getReservationId(), 265 294 x.getUser(), 266 295 x.getTable(), … … 281 310 List<RestaurantReservations> reservations = restaurantDao.findPastReservationsByUser(u); 282 311 return reservations.stream().map(x -> new RestaurantReservationUserDto( 312 x.getReservationId(), 283 313 x.getUser(), 284 314 x.getTable(), … … 293 323 )).toList(); 294 324 } 325 326 @Override 327 public List<MenuImages> getMenuImages(Long id) { 328 return restaurantDao.getMenuImages(id); 329 } 330 331 @Override 332 public void addMenuImage(Long menuId, List<String> url) { 333 Menu r = restaurantDao.findMenuId(menuId); 334 url.stream().map(file -> new MenuImages(r, file)).forEach(x -> restaurantDao.addMenuImage(x)); 335 } 336 337 @Override 338 public Menu findMenuById(Long menuId) { 339 return restaurantDao.findMenuId(menuId); 340 } 341 342 @Override 343 public void setReservationReviewed(Long reservationId) { 344 RestaurantReservations restaurantReservations = findReservationByID(reservationId); 345 restaurantReservations.setReviewed(true); 346 restaurantDao.saveReservation(restaurantReservations); 347 } 348 349 @Override 350 public List<MenuImages> getMenuImagesByRestaurant(long restaurantId) { 351 Restaurant r = findRestaurantByID(restaurantId); 352 return restaurantDao.getMenuImagesByRestaurant(r); 353 } 295 354 }
Note:
See TracChangeset
for help on using the changeset viewer.