Changeset ac19a0c for src/main/java/com


Ignore:
Timestamp:
01/13/24 23:19:50 (10 months ago)
Author:
darsov2 <62809499+darsov2@…>
Branches:
master
Children:
e85a562
Parents:
e9b4ba9
Message:

authContext impl, admin panel impl, search bar fixes, reservations listings impl

Location:
src/main/java/com/tourMate
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/tourMate/config/SecurityConfig.java

    re9b4ba9 rac19a0c  
    77import org.springframework.http.HttpHeaders;
    88import org.springframework.http.HttpMethod;
     9import org.springframework.http.HttpStatus;
    910import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    1011import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
     
    1415import org.springframework.security.web.SecurityFilterChain;
    1516import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
     17import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler;
    1618import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
    1719import org.springframework.web.cors.CorsConfiguration;
     
    7274                                        .anyRequest().authenticated()
    7375                                        .and()
    74                                         .formLogin().loginPage("http://localhost:3000/login")
     76                                        .formLogin()
    7577                                        .loginProcessingUrl("/api/login").usernameParameter("username").passwordParameter("password")
    7678                                        .successHandler((request, response, authentication) -> {
    7779                                            response.setStatus(HttpServletResponse.SC_OK);
     80                                            response.setCharacterEncoding("UTF-8");
    7881                                            response.setContentType("application/json");
    7982                                            response.getWriter().print("{\"message\": \"Login successful\",");
     
    8386                                        .failureHandler((request, response, exception) -> {
    8487                                            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    85                                             response.getWriter().print("Pukla veza\n" + exception.getMessage());
     88                                            response.sendRedirect("/login");
     89                                            response.getWriter().print("Neuspesna najava\n" + exception.getMessage());
    8690                                            response.getWriter().flush();
    8791                                        })
     
    9195                                        .sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
    9296                                        .and()
    93                                         .logout()
     97                                        .logout().logoutSuccessHandler((new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)))
    9498                                        .permitAll();
    9599
  • src/main/java/com/tourMate/controllers/HotelController.java

    re9b4ba9 rac19a0c  
    22
    33import com.tourMate.dto.HotelDto;
     4import com.tourMate.dto.HotelReservationDto;
     5import com.tourMate.dto.HotelReservationUserDto;
    46import com.tourMate.entities.*;
    57import com.tourMate.services.HotelManager;
     
    117119    //HOTEL ROOM CRUD
    118120    @PostMapping(path = "/hotel/rooms/add")
    119     public void addRoom(@RequestBody HotelRoom room, @RequestParam(name = "hotelId") long hotelId) {
     121    public void addRoom(@RequestBody HotelRoom room,
     122                        @RequestParam(name = "hotelId") long hotelId) {
    120123        Hotels h = hotelManager.findHotelByID(hotelId);
    121         hotelManager.createRoom(h, room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice());
     124        hotelManager.createRoom(h, room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice(), room.getNumOfBeds());
    122125    }
    123126
     
    162165        //HOTEL AVAILABILITY CRUD
    163166    @PostMapping(path = "/hotel/rooms/available/{id}/add")
    164     public void addRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable, @PathVariable long id)
     167    public void addRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable,
     168                                 @PathVariable long id)
    165169    {
    166170        HotelRoom hotelRoom = hotelManager.findRoomById(id);
     
    191195    public List<HotelRoomAvailable> getRoomAvailability(@PathVariable Long id)
    192196    {
    193         return hotelManager.getRoomsAvailibility();
     197        return hotelManager.getRoomsAvailableById(id);
    194198    }
    195199
    196200    @GetMapping(path = "/hotel/search")
    197     public List<HotelDto> searchAvailibleRooms(@RequestParam(name = "hotelLocation") String hotelLocation, @RequestParam(name = "dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
    198                                                @RequestParam(name = "dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo, @RequestParam(name = "numBeds") int numBeds)
     201    public List<HotelDto> searchAvailibleRooms(@RequestParam(name = "hotelLocation") String hotelLocation,
     202                                               @RequestParam(name = "dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
     203                                               @RequestParam(name = "dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo,
     204                                               @RequestParam(name = "numBeds") int numBeds)
    199205    {
    200206        System.out.println(hotelLocation);
     
    216222    }
    217223
     224    @GetMapping(path = "/hotel/{id}/reservations/active")
     225    public List<HotelReservationDto> getActiveReservationsForHotel(@PathVariable Long id)
     226    {
     227        return hotelManager.findVaidReseravtionsByHotel(id);
     228    }
     229
     230    @GetMapping(path = "/hotel/reservations/user/{id}")
     231    public List<HotelReservationUserDto> getActiveReservationsForUser(@PathVariable Long id)
     232    {
     233        return hotelManager.findValidHotelReservationsByUser(id);
     234    }
    218235}
  • src/main/java/com/tourMate/controllers/TransportController.java

    re9b4ba9 rac19a0c  
    2323
    2424    // TRANSPORT CRUD //
    25     @PostMapping(path = "/transport/add")
    26     public void add(@RequestBody Transport transport) {
    27         transportManager.createTransport(transport.getTransportName(), transport.getCarBrand(), transport.getCarType(), transport.getCarManufacturedYear(), transport.getNoPassengers(), transport.getNoBags(), transport.getEMBG(), new User(), transport.getCarPlate());
     25    @PostMapping(path = "/transport/add/{userId}")
     26    public void add(@RequestBody Transport transport,
     27                    @PathVariable Long userId) {
     28        transportManager.createTransport(transport.getTransportName(), transport.getCarBrand(), transport.getCarType(), transport.getCarManufacturedYear(), transport.getNoPassengers(), transport.getNoBags(), transport.getEMBG(), userId, transport.getCarPlate());
    2829
    2930    }
     
    4849    public TransportDto getTransport(@PathVariable(name = "id") long transportId)
    4950    {
    50         System.out.println("TUKA SUUUUUM");
    5151        return transportManager.findTransportById(transportId);
    5252    }
     
    9292    @PostMapping(path = "/transport/available/add")
    9393    public void add(@RequestBody TransportAvailible transportAvailable, @RequestParam(name = "transportId") long transportId) {
    94         System.out.println("OREEEEEL");
    95         System.out.println("DVA ORLA");
    9694        Transport t = transportManager.getTransportById(transportId);
    9795        List<TransportRoute> routes = transportAvailable.getRoutes().stream().toList();
     
    135133
    136134    @GetMapping(path = "/transport/search")
    137     public List<TransportListingDto> searchAvailableTransport(@RequestParam(name = "from") String from, @RequestParam(name = "to") String to,
    138                                                               @RequestParam(name = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date){
    139         return transportManager.getTransportsAvailableByFilters(from, to, date);
     135    public List<TransportListingDto> searchAvailableTransport(@RequestParam(name = "from") String from,
     136                                                              @RequestParam(name = "to") String to,
     137                                                              @RequestParam(name = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
     138                                                              @RequestParam(name = "numPassengers") int numPassengers){
     139        return transportManager.getTransportsAvailableByFilters(from, to, date, numPassengers);
    140140    }
    141141}
  • src/main/java/com/tourMate/controllers/UsersController.java

    re9b4ba9 rac19a0c  
    1111import org.springframework.web.bind.annotation.*;
    1212
    13 import java.util.ArrayList;
    1413import java.util.List;
    1514
     
    3938    {
    4039        return businessManager.getUnapprovedBusinessesOfUser(userId);
     40    }
     41
     42    @GetMapping(path = "/business/unapproved")
     43    public List<Business> getAllUnapprovedBusinesses()
     44    {
     45        return businessManager.getUnapprovedBusinesses();
     46    }
     47
     48    @GetMapping(path = "/users/unapproved")
     49    public List<User> getAllUnapprovedUsers()
     50    {
     51        return usersManager.getUnapprovedUsers();
     52    }
     53
     54    @GetMapping(path = "/users/approve/{userId}")
     55    public ResponseEntity<?> approveUserProfile(@PathVariable Long userId)
     56    {
     57        usersManager.approveUserProfile(userId);
     58        return new ResponseEntity<>(HttpStatus.OK);
     59
     60
     61    }
     62
     63    @GetMapping(path = "/business/approve/{businessId}")
     64    public ResponseEntity<?> approveBusiness(@PathVariable Long businessId)
     65    {
     66        businessManager.approveBusiness(businessId);
     67        return new ResponseEntity<>(HttpStatus.OK);
    4168    }
    4269
  • src/main/java/com/tourMate/dao/BusinessDao.java

    re9b4ba9 rac19a0c  
    1111    @Transactional
    1212    void createBusiness(Business business, long userId);
    13     public List<Business> getUnapprovedBusinessesOfUser(long userId);
    14     public void deleteBusiness(long businessId);
    15     public List<Business> getCreatedBusinesses();
    16     public Business findBusinessById (long businessId);
     13    List<Business> getUnapprovedBusinessesOfUser(long userId);
     14    void deleteBusiness(long businessId);
     15    List<Business> getCreatedBusinesses();
     16    Business findBusinessById (long businessId);
    1717
    1818    @Transactional
    1919    void editBusiness(long businessId, String name, String phone, String address, String edbs, User user, boolean approved);
    20     public boolean hasBusiness(long userId);
     20    boolean hasBusiness(long userId);
    2121
     22    List<Business> getUnapprovedBusinesses();
     23
     24    void approveBusiness(Business business);
    2225}
  • src/main/java/com/tourMate/dao/HotelDao.java

    re9b4ba9 rac19a0c  
    2323    public List<HotelRoomImages> getRoomImages(HotelRoom hotelRoom);
    2424
    25     public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price);
     25    public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds);
    2626    public void editRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String HotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price);
    2727    public void deleteRoom(long hotelRoomId);
  • src/main/java/com/tourMate/dao/TransportDao.java

    re9b4ba9 rac19a0c  
    1212public interface TransportDao {
    1313
    14     public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate);
     14    public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, Long userId, String carPlate);
    1515
    1616    public void deleteTransport(long transportId);
     
    4747    public List<TransportAvailible> getTransportsAvailable();
    4848
    49     public List<TransportRoute> getTransportsAvailableByFilters (String from,String to,Date date);
     49    public List<TransportRoute> getTransportsAvailableByFilters (String from, String to, Date date, int numPassengers);
    5050
    5151    public void createTransportRoute(TransportAvailible parentRoute, String from, String to, double price, Date departure, Date arrival, int freeSpace, int order);
  • src/main/java/com/tourMate/dao/UsersDao.java

    re9b4ba9 rac19a0c  
    2323
    2424    UserDetails findUserByUsername(String username);
     25
     26    List<User> getUnapprovedUsers();
     27
     28    void approveUserProfile(User u);
    2529}
  • src/main/java/com/tourMate/dao/impl/BusinessDaoImpl.java

    re9b4ba9 rac19a0c  
    4646    }
    4747
     48    @Override
     49    public List<Business> getUnapprovedBusinesses() {
     50        return em.createQuery("select b from Business b where not b.approved").getResultList();
     51    }
     52
     53    @Override
     54    @Transactional
     55    public void approveBusiness(Business b) {
     56        b.setApproved(true);
     57        em.persist(b);
     58    }
     59
    4860
    4961    @Override
  • src/main/java/com/tourMate/dao/impl/HotelDaoImpl.java

    re9b4ba9 rac19a0c  
    2828    public List<Hotels> getHotels() {
    2929        List<Hotels> hoteli = em.createQuery("select h from Hotels h order by h.hotelId").getResultList();
    30         System.out.println("OREEEEEEL");
    3130        return hoteli;
    3231        //return em.createQuery("select h from Hotels h order by h.hotelId").getResultList();
     
    119118    @Transactional
    120119    @Override
    121     public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
    122         HotelRoom hotelRoom = new HotelRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price);
     120    public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) {
     121        HotelRoom hotelRoom = new HotelRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price, numOfBeds);
    123122        em.persist(hotelRoom);
    124123    }
     
    188187    public List<HotelRoomAvailable> getRoomsAvailibilityByDateAndLocation(String hotelLocation, Date dateFrom, Date dateTo, int numberOfBeds) {
    189188        return em.createQuery("select hr from HotelRoomAvailable hr where hr.dateFrom <= :dateFrom and hr.dateTo >= :dateTo " +
    190                 "and hr.hotelRoom.hotel.hotelLocation LIKE :hotelLocation and hr.numberOfBeds >= :numBeds")
     189                "and hr.hotelRoom.hotel.hotelLocation LIKE :hotelLocation and hr.hotelRoom.numOfBeds >= :numBeds")
    191190                .setParameter("hotelLocation", hotelLocation)
    192191                .setParameter("dateFrom", dateFrom)
     
    236235    public List<HotelRoomReservations> findReservationByHotel(Hotels hotel) {
    237236        List<HotelRoom> hotelRooms = getRoomsOfHotel(hotel.getHotelId());
    238         return em.createQuery("select hr from HotelRoomReservations hr where hr.hotelRoom in :hotelRooms").setParameter("hotelRooms", hotelRooms).getResultList();
     237        return em.createQuery("select hr from HotelRoomReservations hr where hr.hotelRoom.hotel = :hotel").setParameter("hotel", hotel).getResultList();
    239238    }
    240239
  • src/main/java/com/tourMate/dao/impl/TransportDaoImpl.java

    re9b4ba9 rac19a0c  
    2222    @Override
    2323    @Transactional
    24     public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate) {
    25         User u = em.find(User.class, 1);
     24    public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, Long userId, String carPlate) {
     25        User u = em.find(User.class, userId);
    2626        Transport t=new Transport(transportName,carBrand,carType,carManufacturedYear,noPassengers,noBags,EMBG,u,carPlate);
    2727        em.persist(t);
     
    6262                        y.getFreeSpace(),
    6363                        y.getTime(),
    64                         y.getRoutes()
    65                 )).toList()
     64                        y.getRoutes(),
     65                        y.getRoutes().stream()
     66                                .mapToDouble(TransportRoute::getPrice)
     67                                .max().orElse(0)
     68                )).toList(),
     69                x.getAvailableRoutes().stream()
     70                        .flatMapToDouble(y -> y.getRoutes()
     71                                .stream()
     72                                .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0)
    6673        )).toList();
    6774    }
     
    7885                x.getFreeSpace(),
    7986                x.getTime(),
    80                 x.getRoutes()
     87                x.getRoutes(),
     88                x.getRoutes().stream()
     89                        .mapToDouble(TransportRoute::getPrice)
     90                        .max().orElse(0)
    8191        )).toList();
    8292    }
     
    103113                        y.getFreeSpace(),
    104114                        y.getTime(),
    105                         y.getRoutes()
    106                 )).toList());
     115                        y.getRoutes(),
     116                        y.getRoutes().stream()
     117                                .mapToDouble(TransportRoute::getPrice)
     118                                .max().orElse(0)
     119                )).toList(),
     120                x.getAvailableRoutes().stream()
     121                        .flatMapToDouble(y -> y.getRoutes()
     122                                                        .stream()
     123                                                        .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0));
    107124    }
    108125
     
    151168
    152169    @Override
    153     public List<TransportRoute> getTransportsAvailableByFilters(String fromL, String toL, Date date) {
     170    public List<TransportRoute> getTransportsAvailableByFilters(String fromL, String toL, Date date, int numPassengers) {
    154171        System.out.println(fromL + " " + toL);
    155         return em.createQuery("select h from TransportRoute h where h.from = :froml and h.to = :tol").setParameter("froml", fromL).
    156                 setParameter("tol", toL).getResultList();
     172        return em.createQuery("select h from TransportRoute h where h.from = :froml and h.to = :tol and h.freeSpace >= :nump")
     173                .setParameter("froml", fromL)
     174                .setParameter("tol", toL)
     175                .setParameter("nump", numPassengers)
     176                .getResultList();
    157177    }
    158178
  • src/main/java/com/tourMate/dao/impl/UsersDaoImpl.java

    re9b4ba9 rac19a0c  
    7474    }
    7575
     76    @Override
     77    public List<User> getUnapprovedUsers() {
     78        return em.createQuery("select u from User u where not u.enabled").getResultList();
     79    }
     80
     81    @Override
     82    @Transactional
     83    public void approveUserProfile(User u) {
     84        u.setEnabled(true);
     85        em.persist(u);
     86    }
    7687
    7788
  • src/main/java/com/tourMate/dto/RouteListingDto.java

    re9b4ba9 rac19a0c  
    1818    private Date time;
    1919    private Collection<String> routes;
     20    private Double maxPrice;
    2021
    21     public RouteListingDto(long transportAvailibleId, String from, String to, Date date, int freeSpace, Date time, Collection<TransportRoute> routes) {
     22    public RouteListingDto(long transportAvailibleId, String from, String to, Date date, int freeSpace, Date time, Collection<TransportRoute> routes, Double maxPrice) {
    2223        this.transportAvailibleId = transportAvailibleId;
    2324        this.from = from;
     
    2728        this.time = time;
    2829        this.routes = routes.stream().map(x -> x.getFrom()).distinct().skip(1).toList();
     30        this.maxPrice = maxPrice;
    2931    }
    3032
     
    8486        this.routes = routes;
    8587    }
     88
     89    public Double getMaxPrice() {
     90        return maxPrice;
     91    }
    8692}
  • src/main/java/com/tourMate/dto/TransportDto.java

    re9b4ba9 rac19a0c  
    1616    private User owner;
    1717    private String carPlate;
     18    private Double maxPrice;
    1819    private Collection<RouteListingDto> availableRoutes;
    1920
    20     public TransportDto(long transportID, String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate, Collection<RouteListingDto> availableRoutes) {
     21    public TransportDto(long transportID, String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate, Collection<RouteListingDto> availableRoutes, Double maxPrice) {
    2122        this.transportID = transportID;
    2223        this.transportName = transportName;
     
    3031        this.carPlate = carPlate;
    3132        this.availableRoutes = availableRoutes;
     33        this.maxPrice = maxPrice;
    3234    }
    3335
  • src/main/java/com/tourMate/entities/Business.java

    re9b4ba9 rac19a0c  
    8888    }
    8989
    90     @OneToOne(fetch = FetchType.LAZY)
     90    @OneToOne(fetch = FetchType.EAGER)
    9191    @JoinColumn(name = "owner_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_biznis_kon_korisnik"))
    9292    public User getUser() {
     
    107107        this.approved = approved;
    108108    }
     109
    109110}
  • src/main/java/com/tourMate/entities/HotelRoom.java

    re9b4ba9 rac19a0c  
    1616    private String hotelRoomName;
    1717    private double price;
     18    private int numOfBeds;
    1819    private Boolean kitchenAvailable;
    1920    private Boolean airConditioning;
    2021    private Boolean balcony;
    2122
    22     public HotelRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String hotelRoomName, double price, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony) {
     23    public HotelRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String hotelRoomName, double price, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, int numOfBeds) {
    2324        this.hotelRoomId = hotelRoomId;
    2425        this.hotel = hotel;
     
    2930        this.airConditioning = airConditioning;
    3031        this.balcony = balcony;
     32        this.numOfBeds = numOfBeds;
    3133    }
    3234
    3335    public HotelRoom(Hotels hotel, String hotelRoomDescription, String type,
    34                      Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
     36                     Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) {
    3537        this.hotel = hotel;
    3638        this.hotelRoomDescription = hotelRoomDescription;
     
    4042        this.balcony = balcony;
    4143        this.price = price;
     44        this.numOfBeds = numOfBeds;
    4245    }
    4346
    4447    public HotelRoom(String hotelRoomDescription, String type,
    45                      Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
     48                     Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) {
    4649        this.hotel = hotel;
    4750        this.hotelRoomDescription = hotelRoomDescription;
     
    5154        this.balcony = balcony;
    5255        this.price = price;
     56        this.numOfBeds = numOfBeds;
    5357    }
    5458
     
    6872    }
    6973
    70     @ManyToOne(fetch = FetchType.LAZY)
     74    @ManyToOne(fetch = FetchType.EAGER)
    7175    @JoinColumn(name = "hotel_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_room_kon_hotel"))
    7276    public Hotels getHotel() {
     
    134138        this.balcony = balcony;
    135139    }
     140
     141    @Column(name = "hotel_room_num_beds", unique = false)
     142    public int getNumOfBeds() {
     143        return numOfBeds;
     144    }
     145
     146    public void setNumOfBeds(int numOfBeds) {
     147        this.numOfBeds = numOfBeds;
     148    }
    136149}
  • src/main/java/com/tourMate/entities/HotelRoomReservations.java

    re9b4ba9 rac19a0c  
    4141    }
    4242
    43     @ManyToOne(fetch = FetchType.LAZY)
     43    @ManyToOne(fetch = FetchType.EAGER)
    4444    @JoinColumn(name = "room_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_roomres_kon_room"))
    4545    public HotelRoom getHotelRoom() {
     
    5757    }
    5858
    59     @OneToOne(fetch = FetchType.LAZY)
     59    @OneToOne(fetch = FetchType.EAGER)
    6060    @JoinColumn(name = "user_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_roomres_kon_user"))
    6161    public User getUser() {
  • src/main/java/com/tourMate/entities/Reviews.java

    re9b4ba9 rac19a0c  
    7171
    7272    @ManyToOne(fetch = FetchType.LAZY)
    73     @JoinColumn(name = "hotel_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_hotel"))
     73    @JoinColumn(name = "hotel_id", unique = false, nullable = true, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_hotel"))
    7474    public Hotels getHotel () {
    7575        return hotel;
     
    8181
    8282    @ManyToOne(fetch = FetchType.LAZY)
    83     @JoinColumn(name = "restaurant_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_restorani"))
     83    @JoinColumn(name = "restaurant_id", unique = false, nullable = true, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_restorani"))
    8484    public Restaurant getRestaurant () {
    8585        return restaurant;
     
    9191
    9292    @ManyToOne(fetch = FetchType.LAZY)
    93     @JoinColumn(name = "transport_id", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_transport"))
     93    @JoinColumn(name = "transport_id", unique = false, nullable = true, foreignKey = @ForeignKey(name = "fk_ref_od_review_kon_transport"))
    9494    public Transport getTransport () {
    9595        return transport;
  • src/main/java/com/tourMate/entities/User.java

    re9b4ba9 rac19a0c  
    5252    private Role role;
    5353    @Column(name = "locked", unique = false, nullable = false)
    54     boolean locked;
     54    boolean locked = false;
    5555
    5656    @Column(name = "enabled", unique = false, nullable = false)
     
    162162    @Override
    163163    public boolean isAccountNonLocked() {
    164         return true;
     164        return locked;
    165165    }
    166166
  • src/main/java/com/tourMate/services/BusinessManager.java

    re9b4ba9 rac19a0c  
    99    public List<Business> getUnapprovedBusinessesOfUser(long userId);
    1010    public void deleteBusiness(long businessId);
    11     public List<Business> getCreatedBusinesses();
     11    public List<Business> getUnapprovedBusinesses();
     12    public void approveBusiness(Long businessId);
    1213    public Business findBusinessById (long businessId);
    1314    public void editBusiness(long businessId, String name, String phone, String address, String edbs, User user, boolean approved);
  • src/main/java/com/tourMate/services/HotelManager.java

    re9b4ba9 rac19a0c  
    22
    33import com.tourMate.dto.HotelDto;
     4import com.tourMate.dto.HotelReservationDto;
     5import com.tourMate.dto.HotelReservationUserDto;
    46import com.tourMate.entities.*;
    57
     
    2325    public HotelRoom findRoomById (long hotelRoomId);
    2426    public List<HotelRoomImages> getRoomImages(HotelRoom hotelRoom);
    25     public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price);
     27    public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds);
    2628    public void editRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price);
    2729    public void deleteRoom(long hotelRoomId);
    28     public List<HotelRoomAvailable> getRoomsAvailable(Long id);
    2930    public void createRoomAvailible(HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds);
    3031    public void editRoomAvailible(long hotelRoomAvailableId, HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds);
     
    3334    public HotelRoomAvailable findAvailibleRoomById(long hotelRoomAvailableId);
    3435    public List<HotelRoomAvailable> getRoomsAvailibility();
     36    public List<HotelRoomAvailable> getRoomsAvailableById(Long id);
    3537    public List<HotelRoomAvailable> getRoomsAvailibilityByHotel(Hotels hotel);
    3638    public List<HotelDto> getRoomsAvailibilityByDateAndLocation(String hotelLocation, Date dateFrom, Date dateTo, int numberOfBeds);
     
    3840    public void editReservation(long hotelRoomReservedId, User user, HotelRoom hotelRoom, Date dateFrom, Date dateTo, Integer numberOfBeds);
    3941    public void deleteReservation(long hotelRoomReservedId);
     42    public List<HotelReservationDto> findVaidReseravtionsByHotel(Long hotelId);
     43    public List<HotelReservationUserDto> findValidHotelReservationsByUser(Long userId);
    4044    public HotelRoomReservations findReservationById(long hotelRoomReservedId);
    4145    public List<HotelRoomReservations> findReservationByUser(User user);
  • src/main/java/com/tourMate/services/TransportManager.java

    re9b4ba9 rac19a0c  
    1212public interface TransportManager {
    1313
    14     public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate);
     14    public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, Long userId, String carPlate);
    1515
    1616    public void deleteTransport(long transportId);
     
    3333    public Transport getTransportById(long transportId);
    3434
    35     public List<TransportListingDto> getTransportsAvailableByFilters (String from, String to, Date date);
     35    public List<TransportListingDto> getTransportsAvailableByFilters (String from, String to, Date date, int numPassengers);
    3636
    3737    public List<TransportReservation> getTransportsReservationsByUserID(long userID);
  • src/main/java/com/tourMate/services/UsersManager.java

    re9b4ba9 rac19a0c  
    1616
    1717    public void editUser(long userID, String name, String surname, String email, Date birthDate, String address, String contact);
     18    public List<User> getUnapprovedUsers();
     19    public void approveUserProfile(long userId);
    1820}
  • src/main/java/com/tourMate/services/impl/BusinessManagerImpl.java

    re9b4ba9 rac19a0c  
    3434
    3535    @Override
    36     public boolean hasBusiness(long userId){
    37         return businessDao.hasBusiness(userId);
     36    public List<Business> getUnapprovedBusinesses() {
     37        return businessDao.getUnapprovedBusinesses();
    3838    }
    3939
    4040    @Override
    41     public List<Business> getCreatedBusinesses() {
    42         return businessDao.getCreatedBusinesses();
     41    public void approveBusiness(Long businessId) {
     42        Business b = findBusinessById(businessId);
     43        businessDao.approveBusiness(b);
     44    }
     45
     46    @Override
     47    public boolean hasBusiness(long userId){
     48        return businessDao.hasBusiness(userId);
    4349    }
    4450
  • src/main/java/com/tourMate/services/impl/HotelManagerImpl.java

    re9b4ba9 rac19a0c  
    44import com.tourMate.dao.UsersDao;
    55import com.tourMate.dto.HotelDto;
     6import com.tourMate.dto.HotelReservationDto;
     7import com.tourMate.dto.HotelReservationUserDto;
    68import com.tourMate.entities.*;
    79import com.tourMate.services.HotelManager;
     
    1012
    1113import java.time.Duration;
    12 import java.util.Collection;
    1314import java.util.Date;
    1415import java.util.List;
     
    104105
    105106    @Override
    106     public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price) {
    107         hotelDao.createRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price);
     107    public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) {
     108        hotelDao.createRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price, numOfBeds);
    108109    }
    109110
     
    118119    }
    119120
    120     @Override
    121     public List<HotelRoomAvailable> getRoomsAvailable(Long id) {
     121
     122    @Override
     123    public List<HotelRoomAvailable> getRoomsAvailableById(Long id) {
    122124        return hotelDao.getRoomsAvailable(id);
    123125    }
     
    203205
    204206    @Override
     207    public List<HotelReservationDto> findVaidReseravtionsByHotel(Long hotelId) {
     208        Hotels hotel = findHotelByID(hotelId);
     209        List<HotelRoomReservations> reservations = hotelDao.findReservationByHotel(hotel);
     210        return reservations.stream()
     211//                .filter(x -> x.getDateFrom().after(new Date()))
     212                .map(x -> new HotelReservationDto(
     213                        x.getUser(),
     214                        x.getHotelRoom(),
     215                        x.getDateFrom(),
     216                        x.getDateTo(),
     217                        x.getNumberOfBeds()
     218                )).toList();
     219    }
     220
     221    @Override
     222    public List<HotelReservationUserDto> findValidHotelReservationsByUser(Long userId) {
     223        User u = usersDao.findUserByID(userId);
     224        List<HotelRoomReservations> reservations = hotelDao.findReservationByUser(u);
     225        return reservations.stream().map(x -> new HotelReservationUserDto(
     226                x.getUser(),
     227                x.getHotelRoom(),
     228                x.getDateFrom(),
     229                x.getDateTo(),
     230                x.getNumberOfBeds(),
     231                x.getHotelRoom().getHotel().getHotelName(),
     232                x.getHotelRoom().getHotel().getHotelLocation(),
     233                ""
     234        )).toList();
     235    }
     236
     237    @Override
    205238    public HotelRoomReservations findReservationById(long hotelRoomReservedId) {
    206239        return hotelDao.findReservationById(hotelRoomReservedId);
  • src/main/java/com/tourMate/services/impl/TransportManagerImpl.java

    re9b4ba9 rac19a0c  
    2424
    2525    @Override
    26     public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, User owner, String carPlate) {
    27         transportDao.createTransport(transportName, carBrand, carType, carManufacturedYear, noPassengers, noBags, EMBG, owner, carPlate);
     26    public void createTransport(String transportName, String carBrand, String carType, int carManufacturedYear, int noPassengers, int noBags, long EMBG, Long userId, String carPlate) {
     27        transportDao.createTransport(transportName, carBrand, carType, carManufacturedYear, noPassengers, noBags, EMBG, userId, carPlate);
    2828    }
    2929
     
    8383
    8484    @Override
    85     public List<TransportListingDto> getTransportsAvailableByFilters(String from, String to, Date date) {
    86         List<TransportRoute> transportAvailable = transportDao.getTransportsAvailableByFilters(from, to, date);
     85    public List<TransportListingDto> getTransportsAvailableByFilters(String from, String to, Date date, int numPassengers) {
     86        List<TransportRoute> transportAvailable = transportDao.getTransportsAvailableByFilters(from, to, date, numPassengers);
    8787        Map<TransportAvailible, List<TransportRoute>> transportsByTransporter = transportAvailable.stream().collect(Collectors.groupingBy(x -> x.getParentRoute()));
    8888        List<TransportListingDto> transportList = transportsByTransporter.keySet().stream().toList().stream()
  • src/main/java/com/tourMate/services/impl/UsersManagerImpl.java

    re9b4ba9 rac19a0c  
    4545
    4646    @Override
     47    public List<User> getUnapprovedUsers() {
     48        return usersDao.getUnapprovedUsers();
     49    }
     50
     51    @Override
     52    public void approveUserProfile(long userId) {
     53        User u = findUserByID(userId);
     54        usersDao.approveUserProfile(u);
     55    }
     56
     57    @Override
    4758    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    4859        return usersDao.findUserByUsername(username);
Note: See TracChangeset for help on using the changeset viewer.