- 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/dao/impl/RestaurantDaoImpl.java
r5528b99 r07f4e8b 18 18 @Override 19 19 @Transactional 20 public void createRestaurant(Restaurant restaurant, long userId) { 21 User u = em.find(User.class, userId); 22 Restaurant r = new Restaurant(restaurant.getRestaurantName(), restaurant.getRestaurantLocation(), restaurant.getCousineType(), restaurant.getRestaurantDescription(), restaurant.getRestaurantEdbs(), u); 23 em.persist(r); 20 public void createRestaurant(Restaurant restaurant) { 21 em.persist(restaurant); 24 22 } 25 23 … … 43 41 @Transactional 44 42 @Override 45 public void removeRestaurantImage(long restaurantImageId){ 46 RestaurantImages restaurantImage = findRestaurantImageById(restaurantImageId); 47 em.remove(restaurantImage); 43 public void removeRestaurantImage(RestaurantImages image){ 44 em.remove(image); 48 45 } 49 46 … … 55 52 56 53 @Override 57 public void deleteRestaurant(long restaurantID) { 58 Restaurant r = findRestaurantByID(restaurantID); 54 public void deleteRestaurant(Restaurant r) { 59 55 em.remove(r); 60 56 } … … 67 63 @Override 68 64 @Transactional 69 public void addMenuToRestaurant(long restaurantId, Menu menu) { 70 Restaurant r = findRestaurantByID(restaurantId); 71 menu.setRestaurant(r); 65 public void addMenuToRestaurant(Menu menu) { 72 66 em.persist(menu); 73 67 } … … 84 78 85 79 @Override 86 @Transactional87 public void editRestaurant(long restaurantID, String restaurantName, String restaurantLocation, String cousineType, String restaurantDescription, String restaurantEdbs, User restaurantOwner) {88 Restaurant res = findRestaurantByID(restaurantID);89 res.setRestaurantName(restaurantName);90 res.setRestaurantLocation(restaurantLocation);91 res.setRestaurantEdbs(restaurantEdbs);92 res.setRestaurantDescription(restaurantDescription);93 res.setRestaurantOwner(restaurantOwner);94 res.setCousineType(cousineType);95 em.persist(res);96 }97 98 @Override99 80 public List<RestaurantsTable> getRestaurantTables(long restaurantID) { 100 List<RestaurantsTable> restaurantsTables = getRestaurantTables(restaurantID); 101 return restaurantsTables; 81 return em.createQuery("select rt from RestaurantsTable rt where rt.restaurant.restaurantID = :restaurantId").setParameter("restaurantId", restaurantID).getResultList(); 102 82 } 103 83 … … 109 89 @Override 110 90 @Transactional 111 public void createTable(Restaurant restaurant, int noSeats) { 112 RestaurantsTable resTable = new RestaurantsTable(restaurant, noSeats); 91 public void saveTable(RestaurantsTable resTable) { 113 92 em.persist(resTable); 114 93 } 115 94 116 @Override 117 @Transactional 118 public void editTable(Restaurant restaurant, long tableId, int noSeats) { 119 RestaurantsTable resTable = findTableById(tableId); 120 resTable.setRestaurant(restaurant); 121 resTable.setNoSeats(noSeats); 122 em.persist(resTable); 123 } 124 125 @Override 126 @Transactional 127 public void deleteTable(long tableId) { 128 RestaurantsTable rt = findTableById(tableId); 95 96 @Override 97 @Transactional 98 public void deleteTable(RestaurantsTable rt) { 129 99 em.persist(rt); 130 100 } 131 101 132 102 @Override 133 public List<Restaurant> getRestaurantsByUser(long userId) { 134 User u = em.find(User.class, userId); 103 public List<Restaurant> getRestaurantsByUser(User u) { 135 104 return em.createQuery("select r from Restaurant r where r.restaurantOwner = :u").setParameter("u", u).getResultList(); 136 }137 138 @Override139 @Transactional140 public void createTableAvailable(RestaurantsTable restaurantsTable, Date hourFrom, Date hourTo, int noSeats) {141 RestaurantsAvailible ra = new RestaurantsAvailible(restaurantsTable, hourFrom, hourTo, noSeats);142 em.persist(ra);143 105 } 144 106 … … 151 113 @Override 152 114 @Transactional 153 public void createTableAvailable(RestaurantsTable restaurantsTable, Date hourFrom, Date hourTo){ 154 RestaurantsAvailible rta = new RestaurantsAvailible(restaurantsTable, hourFrom, hourTo); 155 em.persist(rta); 156 } 157 158 @Override 159 @Transactional 160 public void editTableAvailable(long tableId, Restaurant restaurant, int noSeats) { 161 RestaurantsTable rt = findTableById(tableId); 162 rt.setRestaurant(restaurant); 163 rt.setNoSeats(noSeats); 164 em.persist(rt); 165 } 166 167 @Override 168 @Transactional 169 public void deleteTableAvailable(long tableId) { 170 RestaurantsAvailible ra = findAvailableReservationByID(tableId); 115 public void saveTableAvailable(RestaurantsAvailible ra){ 116 em.persist(ra); 117 } 118 119 @Override 120 @Transactional 121 public void deleteTableAvailable(RestaurantsAvailible ra) { 171 122 em.remove(ra); 172 123 } … … 183 134 } 184 135 185 @Override 186 @Transactional 187 public void editReservation(long restaurantsTableId, RestaurantsTable rt, Date hourFrom, Date hourTo, int noSeats, User user) { 188 RestaurantReservations r = findReservationByID(restaurantsTableId); 189 r.setTable(rt); 190 r.setTimeFrom(hourFrom); 191 r.setTimeTo(hourTo); 192 r.setNoSeats(noSeats); 193 r.setUser(user); 194 em.persist(r); 195 } 196 197 @Override 198 @Transactional 199 public void deleteReservation(long restaurantsTableId) { 200 RestaurantReservations r = findReservationByID(restaurantsTableId); 136 137 @Override 138 @Transactional 139 public void deleteReservation(RestaurantReservations r) { 201 140 em.remove(r); 202 141 } … … 259 198 260 199 } 200 201 @Override 202 public List<MenuImages> getMenuImages(long menuId) { 203 return em.createQuery("select ri from MenuImages ri where ri.menu.id = :menuId").setParameter("menuId", menuId).getResultList(); 204 } 205 206 @Override 207 public List<MenuImages> getMenuImagesByRestaurant(Restaurant resta) { 208 return em.createQuery("select mi from MenuImages mi where mi.menu.restaurant = :restaurant") 209 .setParameter("restaurant", resta) 210 .getResultList(); 211 } 212 213 @Transactional 214 @Override 215 public void addMenuImage(MenuImages menuImages) { 216 em.persist(menuImages); 217 } 218 219 @Override 220 public Menu findMenuId(Long menuId) { 221 return em.find(Menu.class, menuId); 222 } 223 224 @Override 225 @Transactional 226 public void saveReservation(RestaurantReservations restaurantReservations) { 227 em.persist(restaurantReservations); 228 } 261 229 }
Note:
See TracChangeset
for help on using the changeset viewer.