1184 | | |
| 1184 | [[Image(prev_res-min.png)]] |
| 1185 | [[Image(review_entry.png)]] |
| 1186 | По испраќање на формуларот се испраќа POST барање кое се обработува од контролерот |
| 1187 | {{{#!java |
| 1188 | @PostMapping(path = "/review/add") |
| 1189 | public void add(@RequestParam(name = "title") String title, |
| 1190 | @RequestParam(name = "numStars") Integer numStars, |
| 1191 | @RequestParam(name = "description") String description, |
| 1192 | @RequestParam(name = "hotelId", required = false) Long hotelId, |
| 1193 | @RequestParam(name = "restaurantId", required = false) Long restaurantId, |
| 1194 | @RequestParam(name = "transportId", required = false) Long transportId, |
| 1195 | @RequestParam(name = "reservationId") Long reservationId) { |
| 1196 | reviewManager.createReview(title, numStars, description, hotelId, restaurantId, transportId, reservationId); |
| 1197 | } |
| 1198 | }}} |
| 1199 | По што се повикува соодветна функција од сервисот каде се формира објектот и се испаќа во Dao за да биде зачуван во базата |
| 1200 | {{{#!java |
| 1201 | @Override |
| 1202 | public void createReview(String title, int numStar, String description, Long hotel, Long restaurant, Long transport, Long reservationId) { |
| 1203 | Hotels h = null; |
| 1204 | Restaurant r = null; |
| 1205 | Transport t = null; |
| 1206 | if(hotel != null) |
| 1207 | { |
| 1208 | h = hotelManager.findHotelByID(hotel); |
| 1209 | hotelManager.setReservationReviewed(reservationId); |
| 1210 | } |
| 1211 | if(restaurant != null) |
| 1212 | { |
| 1213 | r = restaurantManager.findRestaurantByID(restaurant); |
| 1214 | restaurantManager.setReservationReviewed(reservationId); |
| 1215 | } |
| 1216 | if(transport != null) |
| 1217 | { |
| 1218 | t = transportManager.getTransportById(transport); |
| 1219 | transportManager.setReservationReviewed(reservationId); |
| 1220 | } |
| 1221 | Reviews review = new Reviews (title, numStar, description, h, r, t); |
| 1222 | reviewDao.createReview(review); |
| 1223 | } |
| 1224 | }}} |
| 1225 | |
| 1226 | // |
| 1227 | {{{#!java |
| 1228 | @Override |
| 1229 | @Transactional |
| 1230 | public void createReview(Reviews review) { |
| 1231 | em.persist(review); |
| 1232 | } |
| 1233 | }}} |