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/dao/impl/RestaurantDaoImpl.java

    r5528b99 r07f4e8b  
    1818    @Override
    1919    @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);
    2422    }
    2523
     
    4341    @Transactional
    4442    @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);
    4845    }
    4946
     
    5552
    5653    @Override
    57     public void deleteRestaurant(long restaurantID) {
    58         Restaurant r = findRestaurantByID(restaurantID);
     54    public void deleteRestaurant(Restaurant r) {
    5955        em.remove(r);
    6056    }
     
    6763    @Override
    6864    @Transactional
    69     public void addMenuToRestaurant(long restaurantId, Menu menu) {
    70         Restaurant r = findRestaurantByID(restaurantId);
    71         menu.setRestaurant(r);
     65    public void addMenuToRestaurant(Menu menu) {
    7266        em.persist(menu);
    7367    }
     
    8478
    8579    @Override
    86     @Transactional
    87     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     @Override
    9980    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();
    10282    }
    10383
     
    10989    @Override
    11090    @Transactional
    111     public void createTable(Restaurant restaurant, int noSeats) {
    112         RestaurantsTable resTable = new RestaurantsTable(restaurant, noSeats);
     91    public void saveTable(RestaurantsTable resTable) {
    11392        em.persist(resTable);
    11493    }
    11594
    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) {
    12999        em.persist(rt);
    130100    }
    131101
    132102    @Override
    133     public List<Restaurant> getRestaurantsByUser(long userId) {
    134         User u = em.find(User.class, userId);
     103    public List<Restaurant> getRestaurantsByUser(User u) {
    135104        return em.createQuery("select r from Restaurant r where r.restaurantOwner = :u").setParameter("u", u).getResultList();
    136     }
    137 
    138     @Override
    139     @Transactional
    140     public void createTableAvailable(RestaurantsTable restaurantsTable, Date hourFrom, Date hourTo, int noSeats) {
    141         RestaurantsAvailible ra = new RestaurantsAvailible(restaurantsTable, hourFrom, hourTo, noSeats);
    142         em.persist(ra);
    143105    }
    144106
     
    151113    @Override
    152114    @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) {
    171122        em.remove(ra);
    172123    }
     
    183134    }
    184135
    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) {
    201140        em.remove(r);
    202141    }
     
    259198
    260199    }
     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    }
    261229}
Note: See TracChangeset for help on using the changeset viewer.