Changeset ac19a0c


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

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

Files:
66 edited

Legend:

Unmodified
Added
Removed
  • frontend/package-lock.json

    re9b4ba9 rac19a0c  
    1313        "@testing-library/user-event": "^13.5.0",
    1414        "axios": "^1.5.0",
     15        "axios-extensions": "^3.1.6",
    1516        "bootstrap": "^5.3.0",
    1617        "file-loader": "^6.2.0",
     
    53495350      }
    53505351    },
     5352    "node_modules/axios-extensions": {
     5353      "version": "3.1.6",
     5354      "resolved": "https://registry.npmjs.org/axios-extensions/-/axios-extensions-3.1.6.tgz",
     5355      "integrity": "sha512-CmwMYxxAw4DcQDJ7/2Iv4GJj1Ao48lJEPieycgZQH6m1KcYZqf9zm2HM/CsULqheCpYxZbiGrCfZf5tVjXqoLg==",
     5356      "dependencies": {
     5357        "lru-cache": "^7.14.0",
     5358        "tslib": "^2.1.0",
     5359        "util": "^0.12.3"
     5360      },
     5361      "peerDependencies": {
     5362        "axios": "*"
     5363      }
     5364    },
     5365    "node_modules/axios-extensions/node_modules/lru-cache": {
     5366      "version": "7.18.3",
     5367      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
     5368      "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
     5369      "engines": {
     5370        "node": ">=12"
     5371      }
     5372    },
    53515373    "node_modules/axios/node_modules/form-data": {
    53525374      "version": "4.0.0",
     
    94259447      "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz",
    94269448      "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==",
    9427       "peer": true,
    94289449      "dependencies": {
    94299450        "call-bind": "^1.0.2",
     
    95649585      "engines": {
    95659586        "node": ">=6"
     9587      }
     9588    },
     9589    "node_modules/is-generator-function": {
     9590      "version": "1.0.10",
     9591      "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz",
     9592      "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==",
     9593      "dependencies": {
     9594        "has-tostringtag": "^1.0.0"
     9595      },
     9596      "engines": {
     9597        "node": ">= 0.4"
     9598      },
     9599      "funding": {
     9600        "url": "https://github.com/sponsors/ljharb"
    95669601      }
    95679602    },
     
    1680016835      }
    1680116836    },
     16837    "node_modules/util": {
     16838      "version": "0.12.5",
     16839      "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",
     16840      "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==",
     16841      "dependencies": {
     16842        "inherits": "^2.0.3",
     16843        "is-arguments": "^1.0.4",
     16844        "is-generator-function": "^1.0.7",
     16845        "is-typed-array": "^1.1.3",
     16846        "which-typed-array": "^1.1.2"
     16847      }
     16848    },
    1680216849    "node_modules/util-deprecate": {
    1680316850      "version": "1.0.2",
  • frontend/package.json

    re9b4ba9 rac19a0c  
    88    "@testing-library/user-event": "^13.5.0",
    99    "axios": "^1.5.0",
     10    "axios-extensions": "^3.1.6",
    1011    "bootstrap": "^5.3.0",
    1112    "file-loader": "^6.2.0",
  • frontend/src/App.js

    re9b4ba9 rac19a0c  
    55import 'bootstrap/dist/js/bootstrap.js';
    66import HomeCarousel from './Components/Layout/CarouselHome/Carousel';
    7 import { Card, Container } from 'react-bootstrap';
     7import {Card, Container} from 'react-bootstrap';
    88import TabComponent from './Components/Tab/Tab';
    99import Offers from './Components/Layout/Offers/Offers';
     
    2727import TransportEditPage from './Pages/TransportEditPage';
    2828import RestaurantDetailsPage from './Pages/RestaurantDetailsPage';
    29 import { BrowserRouter, Route, Routes } from 'react-router-dom';
     29import {BrowserRouter, Route, Routes} from 'react-router-dom';
    3030import LoginErrorPage from "./Pages/LoginErrorPage";
     31import {AuthProvider} from "./Components/Context/AuthContext";
     32import PrivateRoute from "./Components/Misc/PrivateRoute";
     33import ProfilesManagementPage from "./Pages/ProfilesManagementPage";
     34import UserReservationsManagement from "./Pages/UserReservationsManagement";
    3135
    3236
    3337function App() {
    3438
    35   return (
    36     <div className="App" style={{overflow: 'hidden'}}>
    37       <BrowserRouter>
    38         <Routes>
    39           <Route path='/login' element={<LoginPage/>}/>
    40           <Route path='/register' element={<RegistrationPage/>}/>
    41           <Route path='/profile' element={<ProfilePage/>}/>
    42           <Route path="/resources" exact element={<NoBusinessRegisteredError hasRegistration="false"/>} />
    43           <Route path="/resources/hotel" element={<ResourcesPage tab="/hotel"/>}/>
    44           <Route path="/resources/hotel/:hotelId" element={<HotelEditPage />}/>
    45           <Route path="/resources/restaurant" element={<ResourcesPage tab="/restaurant"/>}/>
    46           <Route path='/resources/restaurant/:restaurantId' element={<RestaurantEditPage />}/>
    47           <Route path="/resources/transport" element={<ResourcesPage tab="/transport"/>}/>
    48           <Route path="/resources/transport/:transportId" element={<TransportEditPage/>}/>
    49           <Route path="/home" element={<HomePage/> }/>
    50           <Route path="/error" element={<LoginErrorPage/> }/>
    51           <Route path='/details/transport' element={<TransportDetailsPage></TransportDetailsPage>}/>
    52           <Route path='/details/hotel' element={<HotelDetailsPage></HotelDetailsPage>}/>
    53           <Route path='/details/restaurant' element={<RestaurantDetailsPage></RestaurantDetailsPage>}/>
    54           <Route path="/search/hotel/:hotelLocation/:dateFrom/:dateTo/:numBeds" element={<SearchPage type="hotel"/> }/>
    55           <Route path="/search/transport/:from/:to/:date" element={<SearchPage type="transport"/> }/>
    56         </Routes>
    57       </BrowserRouter>
    58     </div>
    59   );
     39    return (
     40        <div className="App" style={{overflow: 'hidden'}}>
     41            <AuthProvider>
     42                <BrowserRouter>
     43                    <Routes>
     44                        <Route path='/login' element={<LoginPage/>}/>
     45                        <Route path='/register' element={<RegistrationPage/>}/>
     46                        <Route path='/profile' element={<PrivateRoute><ProfilePage/></PrivateRoute>}/>
     47                        <Route path='/profiles' element={<PrivateRoute><ProfilesManagementPage/></PrivateRoute>}/>
     48                        <Route path='/reservations' element={<PrivateRoute><UserReservationsManagement/></PrivateRoute>}/>
     49                        <Route path="/resources" exact element={<PrivateRoute><NoBusinessRegisteredError
     50                            hasRegistration="false"/></PrivateRoute>}/>
     51                        <Route path="/resources/hotel"
     52                               element={<PrivateRoute><ResourcesPage tab="/hotel"/></PrivateRoute>}/>
     53                        <Route path="/resources/hotel/:hotelId" element={<PrivateRoute><HotelEditPage/></PrivateRoute>}/>
     54                        <Route path="/resources/restaurant"
     55                               element={<PrivateRoute><ResourcesPage tab="/restaurant"/></PrivateRoute>}/>
     56                        <Route path='/resources/restaurant/:restaurantId'
     57                               element={<PrivateRoute><RestaurantEditPage/></PrivateRoute>}/>
     58                        <Route path="/resources/transport"
     59                               element={<PrivateRoute><ResourcesPage tab="/transport"/></PrivateRoute>}/>
     60                        <Route path="/resources/transport/:transportId"
     61                               element={<PrivateRoute><TransportEditPage/></PrivateRoute>}/>
     62                        <Route path="/home" element={<HomePage/>}/>
     63                        <Route path="/error" element={<LoginErrorPage/>}/>
     64                        <Route path='/details/transport' element={<TransportDetailsPage></TransportDetailsPage>}/>
     65                        <Route path='/details/hotel' element={<HotelDetailsPage></HotelDetailsPage>}/>
     66                        <Route path='/details/restaurant' element={<RestaurantDetailsPage></RestaurantDetailsPage>}/>
     67                        <Route path="/search/hotel/:hotelLocation/:dateFrom/:dateTo/:numBeds"
     68                               element={<SearchPage type="hotel"/>}/>
     69                        <Route path="/search/transport/:from/:to/:date/:numPassengers"
     70                               element={<SearchPage type="transport"/>}/>
     71                    </Routes>
     72                </BrowserRouter>
     73            </AuthProvider>
     74        </div>
     75    );
    6076}
    6177
  • frontend/src/Components/Forms/AddHotelForm.js

    re9b4ba9 rac19a0c  
    119119                  return prevState + 1;
    120120                })
     121                if(!edit)
     122                  props.closeModal()
    121123              }}
    122124            >
  • frontend/src/Components/Forms/AddRestaurantForm.js

    re9b4ba9 rac19a0c  
    8585                  return prevState + 1;
    8686                })
     87                props.closeModal()
    8788              }}
    8889            >
  • frontend/src/Components/Forms/AddRoomForm.js

    re9b4ba9 rac19a0c  
    1313    hotelRoomDescription: "",
    1414    hotelRoomName: "",
    15     numBeds: "",
     15    numOfBeds: "",
    1616    price: "",
    1717    kitchenAvailable: false,
     
    5858            type="number"
    5959            placeholder="Внесете го бројот на кревети"
    60             value={formData.numBeds}
    61             name="numBeds"
     60            value={formData.numOfBeds}
     61            name="numOfBeds"
    6262            onChange={onFormChange}
    6363            />
     
    117117              style={{ backgroundColor: "#159895" }}
    118118              size="md"
    119               onClick={() => {
    120                 console.log(formData);
     119              onClick={(e) => {
     120                e.preventDefault();
     121                props.refresh((prev) => {
     122                  return ++prev;
     123                })
    121124                createHotelRoom(formData);
     125                props.closeModal();
    122126              }}
    123127            >
  • frontend/src/Components/Forms/AddTransportForm.js

    re9b4ba9 rac19a0c  
    1111      transportName: "",
    1212      carBrand: "",
    13       carType: false,
     13      carType: "",
    1414      carManufacturedYear: 1900,
    1515      noPassengers: 0,
     
    107107                createTransport(formData, edit);
    108108                props.refresh((prev) => {
    109                   return prev + 1;
     109                  return ++prev;
    110110                })
     111                if(!edit)
     112                    props.closeModal()
    111113              }}
    112114            >
  • frontend/src/Components/Forms/EditRoomForm.js

    re9b4ba9 rac19a0c  
    2828    } = useGet(`/hotel/rooms/${props.room.hotelRoomId}/available`)
    2929
     30    console.log(`/hotel/rooms/${props.room.hotelRoomId}/available`)
     31
    3032    !isLoading && console.log(data)
    3133
     
    4244                            <tr>
    4345                                <th>#</th>
    44                                 <th>Достапно од</th>
    45                                 <th>Достапно до</th>
    46                                 <th>Број на соби</th>
     46                                <th>Oд</th>
     47                                <th>До</th>
     48                                <th>Време на тргнување</th>
     49                                <th>Време на пристигнување</th>
     50                                <th>Цена</th>
    4751                            </tr>
    4852                            </thead>
  • frontend/src/Components/Hooks/Hotel/useCreateHotel.js

    re9b4ba9 rac19a0c  
    66const useCreateHotel = () => {
    77
    8     //const history = useNavigate();
    98    const createHotel = async (hotel, edit) => {
    109                console.log({hotel})
    1110                console.log(hotel)
     11                console.log("vo createhotel")
    1212
    1313                if(!edit)
     
    1616                        .post(`/hotel/add`, hotel, {
    1717                                params: {
    18                                         userId: localStorage.getItem("userId")
     18                                        userId: JSON.parse(localStorage.getItem("user")).userId
    1919                                }
    2020                        })
  • frontend/src/Components/Hooks/Restaurant/useCreateRestaurant.js

    re9b4ba9 rac19a0c  
    1515                        .post(`/restaurant/add`, restaurant, {
    1616                                params: {
    17                                         userId: localStorage.getItem('userId')
     17                                        userId: JSON.parse(localStorage.getItem('user')).userId,
    1818                                }
    1919                        })
  • frontend/src/Components/Hooks/Transport/useCreateTransport.js

    re9b4ba9 rac19a0c  
    44
    55const useCreateTransport = () => {
    6 
     6        const userId = JSON.parse(localStorage.getItem('user')).userId
    77    const createTransport = async (transport, edit) => {
    88                        if(!edit)
    99                        {
    1010                                await axios
    11                     .post(`/transport/add`, transport)
     11                    .post(`/transport/add/` + userId, transport)
    1212                    .then((res) => {
    1313                        //history.push('/transport');
  • frontend/src/Components/Hooks/User/useLogin.js

    re9b4ba9 rac19a0c  
    44import { Navigate, useAsyncValue, useNavigate } from "react-router-dom";
    55import LoginForm from "../../Login/LoginForm.js";
     6import {useAuth} from "../../Context/AuthContext";
    67
    78const useLogin = () => {
    89
    910    const navigator = useNavigate()
     11        const Auth = useAuth();
    1012    //const history = useNavigate();
    1113    const login = async (loginData) => {
     
    2224                })
    2325                    .then((res) => {
     26                                        console.log("RES LOGIN")
     27                                        console.log(res)
     28                                        if(res.status === 200)
     29                                        {
     30                                                const user = {
     31                                                        sessionId: res.data.auth.details.sessionId,
     32                                                        userId: res.data.auth.principal.userID,
     33                                                        username: res.data.auth.principal.username,
     34                                                        role: res.data.auth.principal.role,
     35                                                        name: res.data.auth.principal.name,
     36                                                        surname: res.data.auth.principal.surname,
     37                                                }
     38                                                Auth.userLogin(user);
     39                                                console.log(user)
     40                                        }
    2441                                        const sessionId = res.data.auth.details.sessionId;
    2542                                        const userId = res.data.auth.principal.userID;
    26                                        
     43
    2744                                        localStorage.setItem("sessionId", sessionId);
    2845                                        localStorage.setItem("userId", userId);
  • frontend/src/Components/Hooks/useGet.js

    re9b4ba9 rac19a0c  
    1212        console.log("url od get " + uurl)
    1313        await axios.
    14             get(uurl).then((res) => {
     14            get(uurl, {maxRedirects: 0}).then((res) => {
    1515                setData(res.data);
    16             }).catch((err) => {
    17                 console.log(err)
     16            }).catch((error) => {
     17                console.log(error)
    1818            })
    1919            .finally(() => {
     
    2626        getData(url);
    2727    }, [dep, url, changed]);
    28    
     28
    2929    return {
    3030        data,
  • frontend/src/Components/HotelEdit/HotelEditTab.js

    re9b4ba9 rac19a0c  
    11import React from "react";
    2 import { Container, Col, Row, Image, Nav, Tab } from "react-bootstrap";
    3 import { useState } from "react";
    4 import { FaTaxi, FaHotel } from "react-icons/fa";
    5 import { MdOutlineStickyNote2 } from "react-icons/md";
     2import {Container, Col, Row, Image, Nav, Tab} from "react-bootstrap";
     3import {useState} from "react";
     4import {FaTaxi, FaHotel} from "react-icons/fa";
     5import {MdOutlineStickyNote2} from "react-icons/md";
    66import AddNew from "../Resources/AddNew";
    7 import { BiData } from "react-icons/bi"
     7import {BiData} from "react-icons/bi"
    88import RoomListing from "./RoomListing";
    99import HotelEditForm from "./HotelEditForm";
    1010import AddHotelForm from "../Forms/AddHotelForm";
    1111import EditModal from "../Resources/EditModal";
     12import AddAvailability from "../Resources/AddAvailability";
     13import useGet from "../Hooks/useGet";
     14import ReservationListing from "./ReservationListing";
    1215
    1316function HotelEditTab(props) {
    14   const [activeTab, setActiveTab] = useState("/hotel");
    15   const [modalData, setModalData] = useState("");
    16   const [show, setShow] = useState(false);
     17    const [activeTab, setActiveTab] = useState("/hotel");
     18    const [modalData, setModalData] = useState("");
     19    const [show, setShow] = useState(false);
    1720
    18   const handleClose = () => setShow(false);
    19   const handleShow = () => {
    20     //e.preventDefault();
    21     setShow(true);
     21    console.log(props)
    2222
    23   };
     23    const {
     24        data,
     25        isLoading,
     26        setData,
     27        getData,
     28        setChanged
     29    } = useGet(`/hotel/${props.displayRoom.hotelId}/reservations/active`)
    2430
    25   const showModal = (modalData) => {
    26     setModalData(modalData);
    27     handleShow();
    28   }
    29   console.log(props.displayRoom)
     31    !isLoading && console.log(data)
    3032
    31   const handleSelect = (eventKey) => {
    32     setActiveTab(eventKey);
    33   };
     33    const handleClose = () => setShow(false);
     34    const handleShow = () => {
     35        //e.preventDefault();
     36        setShow(true);
    3437
    35   return (
    36     <Container className="rounded-5">
    37       <Tab.Container
    38         activeKey={activeTab}
    39         onSelect={handleSelect}
    40         className="bg-dark rounded-5"
    41       >
    42         <Nav
    43           fill
    44           variant="tabs"
    45           className="bg-body rounded-top-5"
    46           activeKey="/hotel"
    47           id="tab_item"
    48         >
    49           <Nav.Item className="tab_item rounded-5">
    50             <Nav.Link eventKey="/hotel" className="text-left rounded-5">
     38    };
     39
     40    const showModal = (modalData) => {
     41        setModalData(modalData);
     42        handleShow();
     43    }
     44    console.log(props.displayRoom)
     45
     46    const handleSelect = (eventKey) => {
     47        setActiveTab(eventKey);
     48    };
     49
     50    return (
     51        <Container className="rounded-5">
     52            <Tab.Container
     53                activeKey={activeTab}
     54                onSelect={handleSelect}
     55                className="bg-dark rounded-5"
     56            >
     57                <Nav
     58                    fill
     59                    variant="tabs"
     60                    className="bg-body rounded-top-5"
     61                    activeKey="/hotel"
     62                    id="tab_item"
     63                >
     64                    <Nav.Item className="tab_item rounded-5">
     65                        <Nav.Link eventKey="/hotel" className="text-left rounded-5">
    5166              <span className="ikona">
    5267                <FaHotel
    53                   color="#159895"
    54                   style={{ lineHeight: "100em" }}
    55                   size={"1.5em"}
    56                   className="mx-3"
     68                    color="#159895"
     69                    style={{lineHeight: "100em"}}
     70                    size={"1.5em"}
     71                    className="mx-3"
    5772                />
    5873              </span>
    59               <span className="ikona">Соби</span>
    60             </Nav.Link>
    61           </Nav.Item>
    62           <Nav.Item className="tab_item">
    63             <Nav.Link eventKey="/restaurant">
     74                            <span className="ikona">Соби</span>
     75                        </Nav.Link>
     76                    </Nav.Item>
     77                    <Nav.Item className="tab_item">
     78                        <Nav.Link eventKey="/restaurant">
    6479              <span className="ikona">
    65                 <MdOutlineStickyNote2 color="#159895" size={"1.5em"} className="mx-3" />
     80                <MdOutlineStickyNote2 color="#159895" size={"1.5em"} className="mx-3"/>
    6681              </span>
    67               <span className="ikona">Резервации</span>
    68             </Nav.Link>
    69           </Nav.Item>
    70           <Nav.Item className="tab_item rounded-5">
    71             <Nav.Link eventKey="/transport" className="text-left rounded-5">
     82                            <span className="ikona">Резервации</span>
     83                        </Nav.Link>
     84                    </Nav.Item>
     85                    <Nav.Item className="tab_item rounded-5">
     86                        <Nav.Link eventKey="/transport" className="text-left rounded-5">
    7287              <span className="ikona">
    73                 <BiData color="#159895" size={"1.5em"} className="mx-3" />
     88                <BiData color="#159895" size={"1.5em"} className="mx-3"/>
    7489              </span>
    75               <span className="ikona">Општи податоци</span>
    76             </Nav.Link>
    77           </Nav.Item>
    78         </Nav>
     90                            <span className="ikona">Општи податоци</span>
     91                        </Nav.Link>
     92                    </Nav.Item>
     93                </Nav>
    7994
    80         <Tab.Content className="py-5 px-3 border rounded-bottom-5 bg-light">
    81           <Tab.Pane eventKey="/hotel">
    82           {props.displayRoom.hotelRooms.map((room) => {
    83               return <RoomListing key={room.hotelRoomId} data={room} showModal={showModal}/>
    84             })}
    85             <EditModal show={show} handleClose={handleClose} type="room" room={modalData}></EditModal>
    86             <AddNew Id={props.displayRoom.hotelId} refresh={props.refresh} type="room"/>
    87           </Tab.Pane>
    88           <Tab.Pane eventKey="/restaurant">
    89             <AddNew type="restaurant"/>
    90           </Tab.Pane>
    91           <Tab.Pane eventKey="/transport">
    92             <AddHotelForm refresh={props.refresh} hotel={props.displayRoom}/>
    93           </Tab.Pane>
    94         </Tab.Content>
    95       </Tab.Container>
    96     </Container>
    97   );
     95                <Tab.Content className="py-5 px-3 border rounded-bottom-5 bg-light">
     96                    <Tab.Pane eventKey="/hotel">
     97                        {props.displayRoom.hotelRooms.map((room) => {
     98                            return <RoomListing key={room.hotelRoomId} data={room} showModal={showModal}/>
     99                        })}
     100                        <EditModal show={show} handleClose={handleClose} type="room" room={modalData}></EditModal>
     101                        <AddNew Id={props.displayRoom.hotelId} refresh={props.refresh} type="room"/>
     102                    </Tab.Pane>
     103                    <Tab.Pane eventKey="/restaurant">
     104                        {!isLoading && data.map((res) => {
     105                            return (
     106                                <ReservationListing data={res}/>
     107                            )
     108                        })}
     109                        {/*<AddNew type="restaurant"/>*/}
     110                    </Tab.Pane>
     111                    <Tab.Pane eventKey="/transport">
     112                        <AddHotelForm refresh={props.refresh} hotel={props.displayRoom}/>
     113                    </Tab.Pane>
     114                </Tab.Content>
     115            </Tab.Container>
     116        </Container>
     117    );
    98118}
    99119
  • frontend/src/Components/Layout/Navbar/Navigation.js

    re9b4ba9 rac19a0c  
    77import useGet from "../../Hooks/useGet";
    88import axios from "../../../axios.js";
     9import {useAuth} from "../../Context/AuthContext";
    910//import logo from 'assets/images/logo.png';
    1011//src="https://upload.wikimedia.org/wikipedia/commons/0/08/Vergina_Sun_-_Golden_Larnax.png"
     
    1213function Navigation(props) {
    1314  const navigator = useNavigate();
    14 
    15   const { data, setData, isLoading, getData } = useGet("/username");
    16  
     15  const Auth = useAuth();
     16  const isLoggedIn = Auth.userIsAuthenticated();
    1717  return (
    1818    <>
     
    2424      >
    2525        <Container>
    26           <Navbar.Brand href="#home">
     26          <Navbar.Brand href="/home">
    2727            <span className="ikona">
    2828              <Image
     
    5050                Pricing
    5151              </Nav.Link>
    52               {!isLoading && !data && (
     52              {!isLoggedIn && (
    5353                <Button
    5454                  className="m-2"
     
    6262                </Button>
    6363              )}
    64               {!isLoading && data && (
     64              {isLoggedIn && (
    6565                <>
    6666                  <Nav.Link className="m-2" href="/profile">
    67                     {data}
     67                    {Auth.getUser().username}
    6868                  </Nav.Link>
    6969                  <Button
     
    7474                      await axios.get("/logout")
    7575                      .then((res) => {
    76                         console.log(res)
     76                        console.log(res);
     77                        Auth.userLogout();
    7778                      })
    7879                      .catch((err) => {
  • frontend/src/Components/Resources/AddNew.js

    re9b4ba9 rac19a0c  
    5656        </Modal.Header>
    5757        <Modal.Body>
    58             {props.type === "hotel" && <AddHotelForm refresh={props.refresh}/>}
    59             {props.type === "room" && <AddRoomForm refresh={props.refresh} hotelId={props.Id}/>}
    60             {props.type === "restaurant" && <AddRestaurantForm edit="false" refresh={props.refresh}/>}
    61             {props.type === "transport" && <AddTransportForm refresh={props.refresh}/>}
     58            {props.type === "hotel" && <AddHotelForm closeModal={handleClose} refresh={props.refresh}/>}
     59            {props.type === "room" && <AddRoomForm closeModal={handleClose} refresh={props.refresh} hotelId={props.Id}/>}
     60            {props.type === "restaurant" && <AddRestaurantForm edit="false" closeModal={handleClose} refresh={props.refresh}/>}
     61            {props.type === "transport" && <AddTransportForm closeModal={handleClose} refresh={props.refresh}/>}
    6262            {props.type === "menu" && <AddItemMenuForm Id={props.Id} refresh={props.refresh}/>}
    6363            {props.type === "route" && <AddTripForm transportId={props.transport.transportID} setSize={setSizeXl} refresh={props.refresh}/>}
  • frontend/src/Components/Resources/EditModal.js

    re9b4ba9 rac19a0c  
    3131        </Modal.Header>
    3232        <Modal.Body>
    33             {props.type === "hotel" && <AddHotelForm/>}
     33            {props.type === "hotel" && <AddHotelForm refresh={props.refresh}/>}
    3434            {props.type === "room" && <EditRoomForm refresh={props.refresh} room={props.room}/>}
    3535            {props.type === "restaurant" && <AddRestaurantForm edit="false" refresh={props.refresh}/>}
  • frontend/src/Components/Resources/ResourceListing.js

    re9b4ba9 rac19a0c  
    66
    77const ResourceListing = (props) => {
    8  
    9     console.log("props " + props.id)
    10  
    118
    129    const type = props.type == "hotel" ? "сместувањето" : props.type == "restaurant" ? "ресторанот" : "превозот";
    1310    const name = props.type == "hotel" ? props.data.hotelName : props.type == "restaurant" ? props.data.restaurantName : props.data.transportName
    14     const id = props.type == "hotel" ? props.data.hotelId : props.type == "restaurant" ? props.data.resturantId : props.data.transportID
    15     return(<>
     11    const id = props.type == "hotel" ? props.data.hotelId : props.type == "restaurant" ? props.data.restaurantID : props.data.transportID
     12    console.log(props.data)
     13    return(<>
    1614    <a href={`${props.type}/${id}`} style={{textDecoration: "none", color:"black"}}>
    1715        <Container className="py-3 px-1 my-4"
  • frontend/src/Components/Resources/ResourcesTab.js

    re9b4ba9 rac19a0c  
    1111function ResourcesTab(props) {
    1212  const [activeTab, setActiveTab] = useState(props.tab);
    13   // const [changed, setChanged] = useState(0);
    14   const userId = localStorage.getItem("userId");
     13  const userId = JSON.parse(localStorage.getItem("user")).userId;
    1514  const { data, setData, isLoading, getData, setChanged } = useGet(`${props.tab}/user/${userId}`);
    1615
    1716  const handleSelect = (eventKey) => {
    1817    setActiveTab(eventKey);
    19     console.log(props.refresh);
    2018    props.refresh(eventKey);
    21     console.log("refresh" + eventKey);
    2219  };
    23 
    24   !isLoading && console.log(data);
    25   console.log(props.tab);
    2620
    2721  return (
     
    7872              data.map((hotel) => {
    7973                return (
    80                   <Link key={hotel.hotelId} to={"/resources/hotel/" + hotel.hotelId}>
     74                  <Link style={{textDecoration: "none"}} key={hotel.hotelId} to={"/resources/hotel/" + hotel.hotelId}>
    8175                    <ResourceListing
    8276                      key={hotel.hotelId}
     
    9387            {props.tab == "/restaurant" && !isLoading && data != null &&
    9488              data.map((restaurant) => {
    95                 console.log("mapiranje " + restaurant)
    9689                return (
    97                   <Link key={restaurant.restaurantId} to={"/resources/restaurant/" + restaurant.restaurantID}>
    9890                    <ResourceListing
    99                       key={restaurant.restaurantId}
     91                      key={restaurant.restaurantID}
    10092                      type="restaurant"
    10193                      data={restaurant}
    102                     />
    103                   </Link>
    104                 );
     94                    />);
    10595              })}
    10696            <AddNew type="restaurant" refresh={setChanged}/>
  • frontend/src/Components/RestaurantEdit/RestaurantEditTab.js

    re9b4ba9 rac19a0c  
    100100              return <MenuListing key={menu.menuId} data={menu} showModal={showModal}/>
    101101            })}
    102             {activeTab === '/hotel' && <EditModal show={show} handleClose={handleClose} type="menu" menu={modalData}></EditModal>}
     102            {activeTab === '/hotel' && <EditModal show={show} refresh={props.refresh} handleClose={handleClose} type="menu" menu={modalData}></EditModal>}
    103103            <AddNew Id={props.displayMenu.restaurantID} refresh={props.refresh} type="menu"/>
    104104          </Tab.Pane>
  • frontend/src/Components/SearchCriterias/SearchCriteriasBar.js

    re9b4ba9 rac19a0c  
    22import { Container, Form, Button, Row, Col } from "react-bootstrap";
    33import useFormData from "../Hooks/useFormData";
     4import SearchCriteriasHotel from "./SearchCriteriasHotel";
     5import SearchCriteriasTransport from "./SearchCriteriasTransport";
    46
    5 const SearchCriterias = (props) => {
     7const SearchCriteriasBar = (props) => {
    68
    7   const { formData, onFormChange, onCheckBoxChange, setFormData} = useFormData(props.criterias)
    8   console.log("KRITERIUMI")
    9   console.log(formData)
     9    const { criterias, type } = props
    1010
    11   return (
    12     <>
    13       <Container
    14         className="p-1 pb-0 mb-5 mt-3 rounded-2"
    15         style={{ backgroundColor: "#002B5B", width: "65%"}}
    16       >
    17         <Form className="rounded-5">
    18           <Row className="gx-1">
    19             <Col>
    20               <Form.Floating className="mb-3">
    21                 <Form.Control
    22                   size="md"
    23                   type="text"
    24                   placeholder="Каде ќе патувате?:"
    25                   id="location"
    26                   name="hotelLocation"
    27                   onChange={onFormChange}
    28                   value={formData.hotelLocation}
    29                 ></Form.Control>
    30                 <label htmlFor="location">Локација:</label>
    31               </Form.Floating>
    32             </Col>
    33             <Col>
    34               <Form.Floating className="mb-3">
    35                 <Form.Control
    36                   size="md"
    37                   type="date"
    38                   placeholder="Датум на пристигнување:"
    39                   id="dateFrom"
    40                   name="dateFrom"
    41                   onChange={onFormChange}
    42                   value={formData.dateFrom}
    43                 ></Form.Control>
    44                 <label htmlFor="dateFrom">Датум на пристигнување:</label>
    45               </Form.Floating>
    46             </Col>
    47             <Col>
    48               <Form.Floating className="mb-3">
    49                 <Form.Control
    50                   size="md"
    51                   type="date"
    52                   placeholder="Датум на заминување:"
    53                   id="dateTo"
    54                   name="dateTo"
    55                   onChange={onFormChange}
    56                   value={formData.dateTo}
    57                 ></Form.Control>
    58                 <label htmlFor="dateTo">Датум на заминување:</label>
    59               </Form.Floating>
    60             </Col>
    61             <Col>
    62               <Form.Floating className="mb-3">
    63                 <Form.Control
    64                   size="md"
    65                   type="number"
    66                   placeholder="Број на гости:"
    67                   id="floatingPassengers"
    68                   name="numBeds"
    69                   onChange={onFormChange}
    70                   value={formData.numBeds}
    71                 ></Form.Control>
    72                 <label htmlFor="floatingPassengers">Број на гости:</label>
    73               </Form.Floating>
    74             </Col>
    75             <Col>
    76               <Form.Group className="my-1">
    77                 <Button
    78                   type="submit"
    79                   style={{ backgroundColor: "#159895" }}
    80                   size="lg"
    81                   className="w-100"
    82                   onClick={(e) => {
    83                     e.preventDefault();
    84                     window.location.href = `/search/hotel/${formData.hotelLocation}/${formData.dateFrom}/${formData.dateTo}/${formData.numBeds}`
    85                   }}
    86                 >
    87                   <span className="ikona mx-3">Пребарај</span>
    88                 </Button>
    89               </Form.Group>
    90             </Col>
    91           </Row>
    92         </Form>
    93       </Container>
    94     </>
    95   );
    96 };
     11    return (
     12        <>
     13            {type === 'hotel' && <SearchCriteriasHotel criterias={criterias}/>}
     14            {type === 'transport' && <SearchCriteriasTransport criterias={criterias}/>}
     15        </>
     16    )
     17}
    9718
    98 export default SearchCriterias;
     19export default SearchCriteriasBar;
  • frontend/src/Components/Tab/TabFormTransport.js

    re9b4ba9 rac19a0c  
    22import { Button, Col, Container, Form, Row } from "react-bootstrap";
    33import { HiMagnifyingGlass } from "react-icons/hi2"
     4import useFormData from "../Hooks/useFormData";
    45
    56function TabFormTransport() {
     7
     8  const { formData, onFormChange, setFormData } = useFormData({
     9    from: undefined,
     10    to: undefined,
     11    date: undefined,
     12    numPassengers: 0
     13  })
     14
    615  return (
    716    <Form>
     
    1423              placeholder="Од:"
    1524              id="floatingFrom"
     25              value={formData.from}
     26              name={'from'}
     27              onChange={onFormChange}
    1628            ></Form.Control>
    1729            <label htmlFor="floatingFrom">Од:</label>
     
    2537              placeholder="До:"
    2638              id="floatingTo"
     39              name={'to'}
     40              value={formData.to}
     41              onChange={onFormChange}
    2742            ></Form.Control>
    2843            <label htmlFor="floatingTo">До:</label>
     
    3651              placeholder="Датум:"
    3752              id="floatingDate"
     53              name={'date'}
     54              value={formData.date}
     55              onChange={onFormChange}
    3856            ></Form.Control>
    3957            <label htmlFor="floatingDate">Датум:</label>
     
    4664              type="number"
    4765              placeholder="Број на патници:"
     66              name={'numPassengers'}
    4867              id="floatingPassengers"
     68              value={formData.numPassengers}
     69              onChange={onFormChange}
    4970            ></Form.Control>
    5071            <label htmlFor="floatingPassengers">Број на патници:</label>
    5172          </Form.Floating>
    5273          <Form.Group className="my-1">
    53             <Button type="submit" style={{backgroundColor: "#159895"}} size="lg">
     74            <Button type="submit" style={{backgroundColor: "#159895"}} size="lg" onClick={(e) => {
     75              e.preventDefault();
     76              window.location.href = `/search/transport/${formData.from}/${formData.to}/${formData.date}/${formData.numPassengers}`
     77            }}>
    5478              <span className="ikona my-1"><HiMagnifyingGlass/></span>
    5579              <span className="ikona mx-3">Пребарај</span>
  • frontend/src/Components/TransportDetails/FinalPoint.js

    re9b4ba9 rac19a0c  
    1717    <>
    1818      <Row>
    19         {props.left === "true" && <Col className="d-flex flex-column justify-content-center col-auto" style={{paddingLeft: "2.6rem"}}>
     19        {props.left === "true" && <Col className="d-flex flex-column justify-content-center col-md-4" style={{paddingLeft: "2.6rem"}}>
    2020            <h5 className="m-auto">{getTimeAsString(props.time)}</h5>
    2121        </Col>  }
  • frontend/src/Components/TransportDetails/Line.js

    re9b4ba9 rac19a0c  
    22
    33const Line = (props) => {
    4     console.log(props.left)
    5     const left = props.left === "true" ? "9.08rem" : "2.6rem";
    6     console.log({borderLeft: "5px solid #159895", height: "3em", marginLeft: left, marginTop: "-1.4rem", marginBottom: "-1.4rem"})
     4    const left = props.left === "true" ? "1.8rem" : "1.85rem";
    75    return (<>
    86        <div style={{borderLeft: "5px solid #159895", height: "3em", marginLeft: left, marginTop: "-1.4rem", marginBottom: "-1.4rem"}}></div>
  • frontend/src/Components/TransportDetails/Waypoint.js

    re9b4ba9 rac19a0c  
    1717    <>
    1818      <Row className="d-flex flex-row gap-0">
    19       {props.left === "true" && <Col className="d-flex flex-column justify-content-center col-auto" style={{paddingLeft: "2.6rem"}}>
     19      {props.left === "true" && <Col className="d-flex flex-column justify-content-center col-md-4" style={{paddingLeft: "2.6rem"}}>
    2020            <h5 style={{color: props.routes === "true" ? "white" : "" }} className="m-auto">{getTimeAsString(props.time)}</h5>
    2121        </Col>}
     
    3030        </Col>}
    3131      </Row>
    32       <Row>
    33       <Line left={props.left}> </Line>
    34       </Row>
     32        <Row className="d-flex flex-row gap-0">
     33            {props.left === "true" && <Col className="d-flex flex-column justify-content-center col-md-4" style={{paddingLeft: "2.6rem"}}>
     34
     35            </Col>}
     36            <Col md="auto">
     37                <Line left={props.left}> </Line>
     38            </Col>
     39            <Col className="d-flex flex-column justify-content-center">
     40            </Col>
     41            {props.left !== "true" && <Col className="d-flex flex-column justify-content-center">
     42
     43            </Col>}
     44        </Row>
     45      {/*<Row>*/}
     46      {/*<Line left={props.left}> </Line>*/}
     47      {/*</Row>*/}
    3548    </>
    3649  );
  • frontend/src/Components/TransportEdit/TransportEditTab.js

    re9b4ba9 rac19a0c  
    1212function TransportEditTab(props) {
    1313  const [activeTab, setActiveTab] = useState("/hotel");
    14   const link = "/transport/" + props.displayRoute.transportID + "/available";
    1514  console.log(props.displayRoute)
    16   const [changed, setChanged] = useState(0)
    17   const { data, setData, isLoading, getData } = useGet(link, changed);
    1815
    1916
  • frontend/src/Components/TransportEdit/TransportListing.js

    re9b4ba9 rac19a0c  
    99
    1010    //const type = props.type == "hotel" ? "сместувањето" : props.type == "restaurant" ? "ресторанот" : "превозот";
    11     console.log(props.data)
    12     console.log(props.data.from)
    1311    return (<>
    1412        <a href="#" style={{textDecoration: "none", color: "black"}}>
     
    3432                    <Col className="d-flex flex-column justify-content-center" style={{textAlign: "left"}}>
    3533                        <h2>{props.data.from} - {props.data.to}</h2>
    36                         {/* <h6>{props.data.routeCities}</h6> */}
    3734                        <h6>{props.data.routes.map(x => x).join(", ")}</h6>
    3835                    </Col>
     
    4037                    <Col className="d-flex flex-column justify-content-center align-content-center">
    4138                        <h5>Цена:</h5>
    42                         {/* <h4>{props.data.routePrice}</h4> */}
    43                         <h4>99$</h4>
     39                         <h4>{props.data.maxPrice}$</h4>
    4440                    </Col>
    4541                </Row>
  • frontend/src/Components/useFormNested.js

    re9b4ba9 rac19a0c  
    77        console.log(e)
    88
    9         const dependantRoutes = e.target.parentElement.getAttribute('dependantRoutes').split(',')
     9        const dependantRoutes = e.target.name === 'freeSpace' ? e.target.parentElement.getAttribute('dependantRoutes').split(',') : undefined;
    1010        console.log(dependantRoutes)
    1111
  • frontend/src/Pages/HotelDetailsPage.js

    re9b4ba9 rac19a0c  
    11import React from "react";
    22import LoginForm from "../Components/Login/LoginForm";
    3 import { Container, Row, Col, Form } from "react-bootstrap";
     3import {Container, Row, Col, Form, FloatingLabel} from "react-bootstrap";
    44import Navigation from "../Components/Layout/Navbar/Navigation";
    55import Carousel from "react-bootstrap/Carousel";
     
    6969                  placeholder="Каде ќе патувате?:"
    7070                  id="location"
     71                  value={data.hotelLocation}
    7172                ></Form.Control>
    72                 <label htmlFor="location">Локација:</label>
     73                <label style={{left: "10px"}} htmlFor="location">Локација:</label>
    7374              </Form.Floating>
    7475            </Row>
     
    8081                  placeholder="Датум на пристигнување:"
    8182                  id="dateFrom"
     83                  value={from}
    8284                ></Form.Control>
    83                 <label htmlFor="dateFrom">Датум на пристигнување:</label>
     85                <label style={{left: "10px"}} htmlFor="dateFrom">Датум на пристигнување:</label>
    8486              </Form.Floating>
    8587            </Row>
     
    9193                  placeholder="Датум на заминување:"
    9294                  id="dateTo"
     95                  value={to}
    9396                ></Form.Control>
    94                 <label htmlFor="dateTo">Датум на заминување:</label>
     97                <label style={{left: "10px"}} htmlFor="dateTo">Датум на заминување:</label>
    9598              </Form.Floating>
    9699            </Row>
     
    103106                  id="floatingPassengers"
    104107                ></Form.Control>
    105                 <label htmlFor="floatingPassengers">Број на гости:</label>
     108                <label style={{left: "10px"}} htmlFor="floatingPassengers">Број на гости:</label>
    106109              </Form.Floating>
    107110            </Row>
  • frontend/src/Pages/HotelEditPage.js

    re9b4ba9 rac19a0c  
    1 import React, { useState } from "react";
    2 import { Container, Col, Row, Image } from "react-bootstrap";
     1import React, {useState} from "react";
     2import {Container, Col, Row, Image} from "react-bootstrap";
    33import Navigation from "../Components/Layout/Navbar/Navigation";
    44import ResourcesTab from "../Components/Resources/ResourcesTab";
    55import HotelEditTab from "../Components/HotelEdit/HotelEditTab";
    66import useGet from "../Components/Hooks/useGet";
    7 import { useParams } from "react-router-dom";
     7import {Navigate, useParams} from "react-router-dom";
     8import {useAuth} from "../Components/Context/AuthContext";
    89
    910
    1011const HotelEditPage = () => {
    1112
    12   const params = useParams();
    13   const link = "/hotel/list/" + params.hotelId;
    14   const [changed, setChanged] = useState(0)
    15   const { data, setData, isLoading, getData } = useGet(link, changed);
     13    const params = useParams();
     14    const link = "/hotel/list/" + params.hotelId;
     15    const [changed, setChanged] = useState(0)
     16    const {data, setData, isLoading, getData} = useGet(link, changed);
    1617
    1718
    18   console.log(data)
    19   return (
    20     <>
    21       <Navigation />
    22       {!isLoading && <Container>
    23         <Row className="mb-5">
    24           <h2 style={{ color: "#159895", textAlign: "left" }}>Мои ресурси</h2>
    25         </Row>
    26         <Row className="mb-5">
    27           <Col>
    28             <Row className="d-flex mb-3">
    29               <Col
    30                 className="d-flex justify-content-center"
    31                 style={{ maxWidth: "30%" }}
    32               >
    33                 <Image
    34                   src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
    35                   style={{
    36                     height: "5em",
    37                     borderRadius: "50%",
    38                     maxWidth: "100%",
    39                   }}
    40                   className="m-auto"
    41                 ></Image>
    42               </Col>
    43               <Col className="d-flex justify-content-center">
    44                 <Container className="pt-2" style={{ textAlign: "left" }}>
    45                   <h4>{data.hotelName}</h4>
    46                   <h5>{data.hotelLocation}</h5>
    47                 </Container>
    48               </Col>
    49             </Row>
    50           </Col>
    51         </Row>
    52         <Row>
    53             <HotelEditTab refresh={setChanged} displayRoom={data}/>
    54         </Row>
    55       </Container>}
    56     </>
    57   );
     19    console.log(data)
     20    return (
     21        <>
     22            <Navigation/>
     23            {!isLoading && <Container>
     24                <Row className="mb-5">
     25                    <h2 style={{color: "#159895", textAlign: "left"}}>Мои ресурси</h2>
     26                </Row>
     27                <Row className="mb-5">
     28                    <Col>
     29                        <Row className="d-flex mb-3">
     30                            <Col
     31                                className="d-flex justify-content-center"
     32                                style={{maxWidth: "30%"}}
     33                            >
     34                                <Image
     35                                    src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
     36                                    style={{
     37                                        height: "5em",
     38                                        borderRadius: "50%",
     39                                        maxWidth: "100%",
     40                                    }}
     41                                    className="m-auto"
     42                                ></Image>
     43                            </Col>
     44                            <Col className="d-flex justify-content-center">
     45                                <Container className="pt-2" style={{textAlign: "left"}}>
     46                                    <h4>{data.hotelName}</h4>
     47                                    <h5>{data.hotelLocation}</h5>
     48                                </Container>
     49                            </Col>
     50                        </Row>
     51                    </Col>
     52                </Row>
     53                <Row>
     54                    <HotelEditTab refresh={setChanged} displayRoom={data}/>
     55                </Row>
     56            </Container>}
     57        </>
     58    );
    5859};
    5960
  • frontend/src/Pages/LoginErrorPage.js

    re9b4ba9 rac19a0c  
    1111    const [show, setShow] = useState(false);
    1212    const [changed, setChanged] = useState(0);
    13     const {data, isLoading} = useGet("/username")
    1413    const userId = localStorage.getItem("userId")
    1514    const [registered, setRegistered] = useState(false);
  • frontend/src/Pages/LoginPage.js

    re9b4ba9 rac19a0c  
    33import { Container } from "react-bootstrap";
    44import Navigation from "../Components/Layout/Navbar/Navigation";
     5import {useAuth} from "../Components/Context/AuthContext";
     6import {Navigate} from "react-router-dom";
     7
    58
    69const LoginPage = () => {
     
    811  document.body.style.marginTop = "auto";
    912  document.body.style.marginBottom = "auto";
     13
     14  const Auth = useAuth();
     15  const isLoggedIn = Auth.userIsAuthenticated();
     16
     17    if (isLoggedIn) {
     18        return <Navigate to={'/home'}/>
     19    }
     20
    1021  return (
    1122    <>
  • frontend/src/Pages/NoBusinessRegisteredError.js

    re9b4ba9 rac19a0c  
    66import RegisterBusinessForm from "../Components/Forms/RegisterBusinessForm";
    77import useGet from "../Components/Hooks/useGet";
    8 import { useNavigate } from "react-router-dom";
     8import {Navigate, useNavigate} from "react-router-dom";
     9import {useAuth} from "../Components/Context/AuthContext";
    910
    1011const NoBusinessRegisteredError = (props) => {
    1112  const [show, setShow] = useState(false);
    1213  const [changed, setChanged] = useState(0);
    13   const {data, isLoading} = useGet("/username")
     14  const Auth = useAuth();
     15  const isLoggedIn = Auth.userIsAuthenticated();
    1416  const userId = localStorage.getItem("userId")
    1517  const [registered, setRegistered] = useState(false);
     
    4547
    4648
    47   console.log(data)
     49  if(!isLoggedIn)
     50  {
     51    return <Navigate to={'/login'}/>
     52  }
    4853
    49   !isLoading && !data && navigator("/login")
    5054  !firmaIsLoading && firma && firma.length > 0 && firma[0].approved && navigator("/resources/hotel")
    5155 
  • frontend/src/Pages/ProfilePage.js

    re9b4ba9 rac19a0c  
    88import ChangePasswordForm from "../Components/Forms/ChangePasswordForm";
    99import useGet from "../Components/Hooks/useGet";
     10import {useAuth} from "../Components/Context/AuthContext";
     11import {Navigate} from "react-router-dom";
    1012
    1113const ProfilePage = () => {
    1214
    13   const { data, setData, isLoading, getData } = useGet("/principal");
     15    const { data, setData, isLoading, getData } = useGet("/principal");
    1416
    15  
     17
     18
    1619    const profileData = {
    1720        "name": "Марко",
     
    1922        "address": "ул. Раскрсница бр. 10",
    2023        "dateOfBirth": "2002-01-01",
    21         "country": "Никогаш Северна само МАКЕДОНИЈА",
     24        "country": "Македонија",
    2225        "zip": "1000",
    2326        "city": "Скопје",
     
    2730
    2831
     32
    2933  return (
    3034    <>
    3135      <Navigation />
    32 {      !isLoading && <Container>
     36    {!isLoading && <Container>
    3337        <Row className="mb-5">
    3438          <h2 style={{ color: "#159895", textAlign: "left" }}>Мојот профил</h2>
  • frontend/src/Pages/ResourcesPage.js

    re9b4ba9 rac19a0c  
    11import React from "react";
    2 import { Container, Col, Row, Image } from "react-bootstrap";
     2import {Container, Col, Row, Image} from "react-bootstrap";
    33import Navigation from "../Components/Layout/Navbar/Navigation";
    44import ResourcesTab from "../Components/Resources/ResourcesTab";
    5 import { useState } from "react";
     5import {useState} from "react";
    66import useGet from "../Components/Hooks/useGet";
     7import {useAuth} from "../Components/Context/AuthContext";
     8import {Navigate} from "react-router-dom";
    79
    810const ResourcesPage = (props) => {
    911
    10   console.log(props.tab)
    11   const { data, setData, isLoading, getData } = useGet("/principal");
     12    const Auth = useAuth();
     13    const user = Auth.getUser();
    1214
    13 
    14   return (
    15     <>
    16       <Navigation />
    17 {!isLoading && <Container>
    18         <Row className="mb-5">
    19           <h2 style={{ color: "#159895", textAlign: "left" }}>Мои ресурси</h2>
    20         </Row>
    21         <Row className="mb-5">
    22           <Col>
    23             <Row className="d-flex mb-3">
    24               <Col
    25                 className="d-flex justify-content-center"
    26                 style={{ maxWidth: "30%" }}
    27               >
    28                 <Image
    29                   src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
    30                   style={{
    31                     height: "5em",
    32                     borderRadius: "50%",
    33                     maxWidth: "100%",
    34                   }}
    35                   className="m-auto"
    36                 ></Image>
    37               </Col>
    38               <Col className="d-flex justify-content-center">
    39                 <Container className="pt-2" style={{ textAlign: "left" }}>
    40                   <h4>{data.name + " " + data.surname}</h4>
    41                   <h5>{data.email}</h5>
    42                 </Container>
    43               </Col>
    44             </Row>
    45           </Col>
    46         </Row>
    47         <Row>
    48             <ResourcesTab tab={props.tab}></ResourcesTab>
    49         </Row>
    50       </Container>}
    51     </>
    52   );
     15    return (
     16        <>
     17            <Navigation/>
     18            {<Container>
     19                <Row className="mb-5">
     20                    <h2 style={{color: "#159895", textAlign: "left"}}>Мои ресурси</h2>
     21                </Row>
     22                <Row className="mb-5">
     23                    <Col>
     24                        <Row className="d-flex mb-3">
     25                            <Col
     26                                className="d-flex justify-content-center"
     27                                style={{maxWidth: "30%"}}
     28                            >
     29                                <Image
     30                                    src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
     31                                    style={{
     32                                        height: "5em",
     33                                        borderRadius: "50%",
     34                                        maxWidth: "100%",
     35                                    }}
     36                                    className="m-auto"
     37                                ></Image>
     38                            </Col>
     39                            <Col className="d-flex justify-content-center">
     40                                <Container className="pt-2" style={{textAlign: "left"}}>
     41                                    <h4>{user.name + " " + user.surname}</h4>
     42                                    <h5>{user.username}</h5>
     43                                </Container>
     44                            </Col>
     45                        </Row>
     46                    </Col>
     47                </Row>
     48                <Row>
     49                    <ResourcesTab tab={props.tab}></ResourcesTab>
     50                </Row>
     51            </Container>}
     52        </>
     53    );
    5354};
    5455
  • frontend/src/Pages/RestaurantEditPage.js

    re9b4ba9 rac19a0c  
    66import RestaurantEditTab from "../Components/RestaurantEdit/RestaurantEditTab";
    77import useGet from "../Components/Hooks/useGet";
    8 import { useParams, useSearchParams } from "react-router-dom";
     8import {Navigate, useParams, useSearchParams} from "react-router-dom";
     9import {useAuth} from "../Components/Context/AuthContext";
    910
    1011const RestaurantEditPage = () => {
  • frontend/src/Pages/SearchPage.js

    re9b4ba9 rac19a0c  
    1111import BecomeAHost from "../Components/BecomeAHost/BecomeAHost"
    1212import HotelLisitng from "../Components/Listings/HotelListing"
    13 import SearchCriterias from "../Components/SearchCriterias/SearchCriteriasBar";
     13import SearchCriteriasHotel from "../Components/SearchCriterias/SearchCriteriasHotel";
    1414import SortButton from "../Components/Listings/SortButton";
    1515import FilterButton from "../Components/Listings/FilterButton";
     
    1717import useGet from "../Components/Hooks/useGet";
    1818import { useParams } from "react-router-dom";
     19import SearchCriteriasBar from "../Components/SearchCriterias/SearchCriteriasBar";
    1920
    2021
     
    3637    }
    3738   
    38     let link = props.type === "transport" ? `/transport/search?from=${params.from}&to=${params.to}&date=${params.date}` : props.type === "hotel" ? `/hotel/search?hotelLocation=${params.hotelLocation}&dateFrom=${params.dateFrom}&dateTo=${params.dateTo}&numBeds=${params.numBeds}` : ""
     39    let link = props.type === "transport" ? `/transport/search?from=${params.from}&to=${params.to}&date=${params.date}&numPassengers=${params.numPassengers}` : props.type === "hotel" ? `/hotel/search?hotelLocation=${params.hotelLocation}&dateFrom=${params.dateFrom}&dateTo=${params.dateTo}&numBeds=${params.numBeds}` : ""
    3940    console.log(link)
    4041    const { data, isLoading, getData, setData } = useGet(link);
     
    4344        <>
    4445            <Navigation></Navigation>
    45             <SearchCriterias criterias={useParams()}></SearchCriterias>
     46            <SearchCriteriasBar type={props.type} criterias={useParams()}></SearchCriteriasBar>
    4647            <Container className="d-flex justify-content-end gx-5" style={{maxWidth: "60%"}}>
    4748                <Row>
  • frontend/src/Pages/TransportEditPage.js

    re9b4ba9 rac19a0c  
    1 import React, { useState } from "react";
    2 import { Container, Col, Row, Image } from "react-bootstrap";
     1import React, {useState} from "react";
     2import {Container, Col, Row, Image} from "react-bootstrap";
    33import Navigation from "../Components/Layout/Navbar/Navigation";
    44import ResourcesTab from "../Components/Resources/ResourcesTab";
     
    77import TransportEditTab from "../Components/TransportEdit/TransportEditTab";
    88import useGet from "../Components/Hooks/useGet";
    9 import { useParams } from "react-router-dom";
     9import {Navigate, useParams} from "react-router-dom";
     10import {useAuth} from "../Components/Context/AuthContext";
    1011
    1112const TransportEditPage = () => {
    12   const params = useParams();
    13   console.log("transportot ima id " + params.transportId);
    14   const link = "/transport/" + params.transportId;
    15   const [changed, setChanged] = useState(0);
    16   const { data, setData, isLoading, getData } = useGet(link, changed);
    1713
    18   !isLoading && console.log(data)
     14    const params = useParams();
    1915
    20   return (
    21     <>
    22       <Navigation />
    23       {!isLoading && (
    24         <Container>
    25           <Row className="mb-5">
    26             <h2 style={{ color: "#159895", textAlign: "left" }}>Мои ресурси</h2>
    27           </Row>
    28           <Row className="mb-5">
    29             <Col>
    30               <Row className="d-flex mb-3">
    31                 <Col
    32                   className="d-flex justify-content-center"
    33                   style={{ maxWidth: "30%" }}
    34                 >
    35                   <Image
    36                     src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
    37                     style={{
    38                       height: "5em",
    39                       borderRadius: "50%",
    40                       maxWidth: "100%",
    41                     }}
    42                     className="m-auto"
    43                   ></Image>
    44                 </Col>
    45                 <Col className="d-flex justify-content-center">
    46                   <Container className="pt-2" style={{ textAlign: "left" }}>
    47                     <h4>{data.transportName}</h4>
    48                     <h5>{data.carBrand + " " + data.carType}</h5>
    49                   </Container>
    50                 </Col>
    51               </Row>
    52             </Col>
    53           </Row>
    54           <Row>
    55             {data && <TransportEditTab displayRoute={data} refresh={setChanged}/>}
    56           </Row>
    57         </Container>
    58       )}
    59     </>
    60   );
     16    const link = "/transport/" + params.transportId;
     17
     18    const {data, setData, isLoading, getData, setChanged} = useGet(link);
     19
     20    !isLoading && console.log(data)
     21
     22    return (
     23        <>
     24            <Navigation/>
     25            {!isLoading && (
     26                <Container>
     27                    <Row className="mb-5">
     28                        <h2 style={{color: "#159895", textAlign: "left"}}>Мои ресурси</h2>
     29                    </Row>
     30                    <Row className="mb-5">
     31                        <Col>
     32                            <Row className="d-flex mb-3">
     33                                <Col
     34                                    className="d-flex justify-content-center"
     35                                    style={{maxWidth: "30%"}}
     36                                >
     37                                    <Image
     38                                        src="https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg"
     39                                        style={{
     40                                            height: "5em",
     41                                            borderRadius: "50%",
     42                                            maxWidth: "100%",
     43                                        }}
     44                                        className="m-auto"
     45                                    ></Image>
     46                                </Col>
     47                                <Col className="d-flex justify-content-center">
     48                                    <Container className="pt-2" style={{textAlign: "left"}}>
     49                                        <h4>{data.transportName}</h4>
     50                                        <h5>{data.carBrand + " " + data.carType}</h5>
     51                                    </Container>
     52                                </Col>
     53                            </Row>
     54                        </Col>
     55                    </Row>
     56                    <Row>
     57                        {data && <TransportEditTab displayRoute={data} refresh={setChanged}/>}
     58                    </Row>
     59                </Container>
     60            )}
     61        </>
     62    );
    6163};
    6264
  • frontend/src/axios.js

    re9b4ba9 rac19a0c  
    11import axios from "axios";
     2
    23
    34const instance = axios.create({
    45    baseURL: "http://localhost:8080/",
    56    withCredentials: true,
    6     maxRedirects: 1
     7    maxRedirects: 1,
     8    beforeRedirect: (options, { headers }) => {
     9        console.log(options)
     10        if (options.hostname === "example.com") {
     11            options.auth = "user:password";
     12        }}
     13
    714})
    815
    9 instance.interceptors.response.use(function (response) {
    10     // Any status code that lie within the range of 2xx cause this function to trigger
    11     // Do something with response data
    12     return response;
    13   }, function (error) {
    14     console.log(error)
    15     //  window.location.href="/login"
    16     // Any status codes that falls outside the range of 2xx cause this function to trigger
    17     // Do something with response error
    18     return Promise.reject(error);
    19   });
    20 
    2116export default instance
  • 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.