Ignore:
Timestamp:
01/24/24 17:42:28 (10 months ago)
Author:
darsov2 <62809499+darsov2@…>
Branches:
master
Children:
0f5aa27
Parents:
5528b99
Message:

prefinal fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/tourMate/services/impl/RestaurantManagerImpl.java

    r5528b99 r07f4e8b  
    33import com.tourMate.dao.RestaurantDao;
    44import com.tourMate.dto.RestaurantDto;
     5import com.tourMate.dto.RestaurantReservationDto;
    56import com.tourMate.dto.RestaurantReservationUserDto;
    67import com.tourMate.services.RestaurantManager;
     
    2223    @Autowired
    2324    UsersManager usersManager;
     25
    2426    @Override
    2527    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    }
    3051
    3152    @Override
    3253    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);
    4956    }
    5057
     
    6774    @Override
    6875    public void removeRestaurantImage(long restaurantImageId) {
    69         restaurantDao.removeRestaurantImage(restaurantImageId);
     76        RestaurantImages restaurantImage = findRestaurantImageById(restaurantImageId);
     77        restaurantDao.removeRestaurantImage(restaurantImage);
    7078    }
    7179
     
    8189
    8290    @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) {
    8492        List<RestaurantsAvailible> restaurantsAvailibles = restaurantDao.getTablesByDateAndLocation(restaurantLocation, hourFrom, hourTo, noSeats);
    8593        Map<Restaurant, List<RestaurantsAvailible>> tablesByRestaurants = restaurantsAvailibles.stream().collect(Collectors.groupingBy(x -> x.getRestaurantTable().getRestaurant()));
     
    96104                        getReviewsForRestaurant(x.getRestaurantID()),
    97105                        getReviewsForRestaurant(x.getRestaurantID()).stream().mapToDouble(Reviews::getNumStar).average().orElse(0),
    98                         getRestaurantImages(x.getRestaurantID())
     106                        getRestaurantImages(x.getRestaurantID()),
     107                        getMenuImagesByRestaurant(x.getRestaurantID())
    99108                )).toList();
    100109        return restaurantsList;
     
    103112    @Override
    104113    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);
    106133    }
    107134
     
    119146    public void createTable(Long restaurantId, int noSeats) {
    120147        Restaurant r = restaurantDao.findRestaurantByID(restaurantId);
    121         restaurantDao.createTable(r, noSeats);
     148        RestaurantsTable restaurantsTable = new RestaurantsTable(r, noSeats);
     149        restaurantDao.saveTable(restaurantsTable);
    122150    }
    123151
    124152    @Override
    125153    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);
    127158    }
    128159
    129160    @Override
    130161    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) {
    136168        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) {
    143175        return restaurantDao.getTablesAvailabilityById(id);
    144176    }
     
    146178    @Override
    147179    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);
    149184    }
    150185
    151186    @Override
    152187    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);
    164195    }
    165196
     
    170201    }
    171202
    172     @Override
    173     public void editReservation(long tableId, Restaurant restaurant, int noSeats) {
    174         //restaurantDao.editReservation(tableId, restaurant, noSeats);
    175     }
    176203
    177204    @Override
    178205    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);
    180210    }
    181211
    182212    @Override
    183213    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;
    197216    }
    198217
     
    203222
    204223    @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());
    207233    }
    208234
     
    251277    }
    252278
    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) {
    255280        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);
    258286    }
    259287
     
    263291        List<RestaurantReservations> reservations = restaurantDao.findReservationByUser(u);
    264292        return reservations.stream().map(x -> new RestaurantReservationUserDto(
     293                x.getReservationId(),
    265294                x.getUser(),
    266295                x.getTable(),
     
    281310        List<RestaurantReservations> reservations = restaurantDao.findPastReservationsByUser(u);
    282311        return reservations.stream().map(x -> new RestaurantReservationUserDto(
     312                x.getReservationId(),
    283313                x.getUser(),
    284314                x.getTable(),
     
    293323        )).toList();
    294324    }
     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    }
    295354}
Note: See TracChangeset for help on using the changeset viewer.