Changeset 0f5aa27
- Timestamp:
- 02/04/24 16:57:49 (10 months ago)
- Branches:
- master
- Children:
- efaa053
- Parents:
- 07f4e8b
- Files:
-
- 29 added
- 4 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/App.js
r07f4e8b r0f5aa27 33 33 import ProfilesManagementPage from "./Pages/ProfilesManagementPage"; 34 34 import UserReservationsManagement from "./Pages/UserReservationsManagement"; 35 import LoginCallback from "./Components/LoginCallback"; 36 import ConnectedAccountsPage from "./Pages/ConnectedAccountsPage"; 35 37 36 38 … … 71 73 <Route path="/search/restaurant/:restaurantLocation/:date/:hourFrom/:hourTo/:numPeople" 72 74 element={<SearchPage type="restaurant"/>}/> 75 <Route path="/login-callback" element={<LoginCallback/>}></Route> 76 <Route path="/connected" element={<PrivateRoute><ConnectedAccountsPage/></PrivateRoute>}></Route> 73 77 </Routes> 74 78 </BrowserRouter> -
frontend/src/Components/Forms/AddItemMenuForm.js
r07f4e8b r0f5aa27 4 4 import useFormData from "../Hooks/useFormData"; 5 5 import useCreateMenu from "../Hooks/Restaurant/useCreateMenu" 6 import useCreate from "../Hooks/useCreate"; 6 7 7 8 const AddItemMenuForm = (props) => { … … 9 10 10 11 const edit = props.menu 12 console.log(props.menu) 11 13 const dummy = { 12 14 name: "", … … 23 25 edit ? props.menu : dummy 24 26 ); 27 const { createEntity } = useCreate(); 25 28 26 29 return ( … … 72 75 onClick={(e) => { 73 76 e.preventDefault(); 74 createMenu(props.Id, formData) 75 props.refresh((prevState) => { 76 return prevState + 1; 77 }) 77 if(!edit) { 78 createMenu(props.Id, formData, props.refresh) 79 } 80 else { 81 createEntity(`/menu/${props.menu.menuId}/edit`, formData, props.refresh) 82 } 83 78 84 }} 79 85 > -
frontend/src/Components/Forms/AddTripForm.js
r07f4e8b r0f5aa27 272 272 273 273 for (let i = 0; i < Object.values(routesForm).length; i++) { 274 console.log(findDependantRoutes(wayPointNames, routesForm, i))275 274 setDependencies(prevState => [...prevState, findDependantRoutes(wayPointNames, routesForm, i)]) 276 275 } 277 console.log('VO STATEOOOO')278 console.log(dependencies)279 276 routesSetFormData(routesForm) 280 277 setRoutes(routesVar) -
frontend/src/Components/Hooks/Restaurant/useCreateMenu.js
r07f4e8b r0f5aa27 7 7 const navigator = useNavigate(); 8 8 9 const createMenu = async (id, menu ) => {9 const createMenu = async (id, menu, dep) => { 10 10 console.log(menu) 11 11 console.log(id) … … 18 18 //navigator("/resources/restaurant/" + id) 19 19 //history.push('/restaurant'); 20 dep(prev => ++prev) 20 21 }) 21 22 .catch((err) => { -
frontend/src/Components/Hooks/User/useCreateUser.js
r07f4e8b r0f5aa27 10 10 .post(`/register`, user) 11 11 .then((res) => { 12 navigator("/login")12 window.location.href = "http://localhost:8080/login" 13 13 }) 14 14 .catch((err) => { -
frontend/src/Components/Hooks/User/useLogin.js
r07f4e8b r0f5aa27 1 import React from "react"; 2 1 import { useState } from "react"; 3 2 import axios from "../../../axios.js"; 4 import { Navigate, useAsyncValue, useNavigate } from "react-router-dom"; 5 import LoginForm from "../../Login/LoginForm.js"; 6 import {useAuth} from "../../Context/AuthContext"; 3 import {useAuth} from "../../Context/AuthContext"; // Assuming you have axios configured 7 4 8 5 const useLogin = () => { 6 const [loading, setLoading] = useState(false); 7 const [error, setError] = useState(null); 8 const Auth = useAuth(); 9 9 10 const navigator = useNavigate() 11 const Auth = useAuth(); 12 //const history = useNavigate(); 13 const login = async (loginData) => { 14 console.log({loginData}) 15 console.log(loginData) 16 await axios 17 .post(`/api/login`, { 18 username: loginData.email, 19 password: loginData.password 20 }, { 21 headers: { 22 "Content-Type": "application/x-www-form-urlencoded" 23 } 24 }) 25 .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 } 41 const sessionId = res.data.auth.details.sessionId; 42 const userId = res.data.auth.principal.userID; 10 const handleLoginCallback = async () => { 11 setLoading(true); 43 12 44 localStorage.setItem("sessionId", sessionId); 45 localStorage.setItem("userId", userId); 46 if(sessionId === null) 47 { 48 } 49 navigator("/home") 50 }) 51 .catch((err) => { 52 console.log(err); 53 }) 54 .finally(() => { 55 }); 56 } 13 try { 14 const response = await axios.get("http://localhost:8080/principal"); 15 16 // Extract the needed attributes from the response 17 const { id, role, username } = response.data; 18 19 Auth.userLogin({userId: id, username: username, role: role}) 20 21 } catch (err) { 22 setError(err.message); 23 } finally { 24 setLoading(false); 25 } 26 }; 57 27 58 28 return { 59 login 29 loading, 30 error, 31 handleLoginCallback, 60 32 }; 61 62 } 33 }; 63 34 64 35 export default useLogin; -
frontend/src/Components/Hooks/useCreate.js
r07f4e8b r0f5aa27 15 15 .then((res) => { 16 16 //history.push('/hotel'); 17 console.log(res)18 console.log("gotovo")19 17 getData(prev => ++prev) 20 18 getData2(prev => ++prev) -
frontend/src/Components/Layout/Navbar/Navigation.js
r07f4e8b r0f5aa27 63 63 style={{ backgroundColor: "#159895" }} 64 64 onClick={() => { 65 navigator("/login");65 window.location.href = ("http://localhost:8080/login"); 66 66 }} 67 67 > -
frontend/src/Components/Listings/HotelListing.js
r07f4e8b r0f5aa27 1 import {Col, Container, Image, Row, Button } from "react-bootstrap";1 import {Col, Container, Image, Row, Button, Badge} from "react-bootstrap"; 2 2 import {BsFillPersonFill} from "react-icons/bs"; 3 3 import {MdOutlineLocalOffer} from "react-icons/md"; … … 5 5 6 6 function HotelListing(props) { 7 8 const getMarketingMessage = (num) => { 9 switch (num){ 10 case 1: 11 return "Достапно само денес" 12 case 2: 13 return "Последна соба" 14 case 3: 15 return "Специјална цена" 16 } 17 } 18 7 19 console.log(props) 20 const randomInt = Math.floor(Math.random() * (3)) + 1; 8 21 return ( 9 22 <> … … 15 28 boxShadow: "0 3px 5px lightblue", 16 29 maxWidth: "60%", 30 backgroundColor: props.data.promoted ? "#e1f7fa" : "" 17 31 }} 18 32 > … … 31 45 <Col> 32 46 <Row> 33 <h3>{props.data.hotelName}</h3> 47 <h3>{props.data.hotelName} 48 {props.data.marketed && randomInt !== 3 && <h6><Badge bg="warning">{getMarketingMessage(randomInt)}</Badge></h6>} 49 {props.data.promoted && <h6><Badge bg="primary">Најпопуларно</Badge></h6>} 50 </h3> 34 51 </Row> 35 52 <Row> … … 90 107 > 91 108 <Row> 92 <h4>{props.data.totalPrice}$</h4> 109 <h4>{props.data.marketed && randomInt === 3 && <h6><Badge bg="warning">{getMarketingMessage(randomInt)}</Badge></h6>} 110 {props.data.totalPrice}$</h4> 93 111 </Row> 94 112 <Row className="w-100"> -
frontend/src/Components/Login/LoginForm.js
r07f4e8b r0f5aa27 5 5 import useLogin from "../Hooks/User/useLogin"; 6 6 import { Link } from "react-router-dom"; 7 import useCreate from "../Hooks/useCreate"; 8 import {useAuth} from "../Context/AuthContext"; 7 9 8 const LoginForm = ( ) => {10 const LoginForm = (props) => { 9 11 const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData( 10 12 { 11 email: "",13 username: "", 12 14 password: "", 13 15 } 14 16 ); 15 17 16 const { login } = useLogin(); 18 const { createEntity } = useCreate(); 19 const Auth = useAuth(); 17 20 18 21 return ( … … 27 30 type="email" 28 31 placeholder="Enter email" 29 name=" email"32 name="username" 30 33 onChange={onFormChange} 31 34 value={formData.email} 32 35 /> 33 <Form.Text className="text-muted">34 Вашите податоци никогаш нема да бидат споделени.35 </Form.Text>36 36 </Form.Group> 37 37 … … 46 46 /> 47 47 </Form.Group> 48 <Form.Group className="mb-3" controlId="formBasicCheckbox">49 <Form.Check type="checkbox" label="Check me out" />50 </Form.Group>51 <Link to={"/register"} style={{textDecoration: "none"}}>52 <Form.Text className="text-muted" style={{color: "#159895!important"}} >53 Регистритрај се54 </Form.Text>55 </Link>48 {/*<Form.Group className="mb-3" controlId="formBasicCheckbox">*/} 49 {/* <Form.Check type="checkbox" label="Check me out" />*/} 50 {/*</Form.Group>*/} 51 {/*<Link to={"/register"} style={{textDecoration: "none"}}>*/} 52 {/* <Form.Text className="text-muted" style={{color: "#159895!important"}} >*/} 53 {/* Регистритрај се*/} 54 {/* </Form.Text>*/} 55 {/*</Link>*/} 56 56 <Form.Group className="my-1"> 57 57 <Button … … 62 62 e.preventDefault(); 63 63 console.log(formData); 64 login(formData)64 createEntity(`/users/${Auth.getUser().userId}/connect`, formData, props.refresh) 65 65 }} 66 66 > … … 68 68 <AiFillLock /> 69 69 </span> 70 <span className="ikona mx-3"> Најави се</span>70 <span className="ikona mx-3">Поврзи</span> 71 71 </Button> 72 72 </Form.Group> -
frontend/src/Components/Misc/PrivateRoute.js
r07f4e8b r0f5aa27 5 5 function PrivateRoute({ children }) { 6 6 const { userIsAuthenticated } = useAuth() 7 return userIsAuthenticated() ? children : <Navigate to="/login" /> 7 if(userIsAuthenticated()) 8 { 9 return children; 10 } 11 else 12 { 13 window.location.href = "http://localhost:8080/login"; 14 } 15 return userIsAuthenticated() ? children : <Navigate to="http://localhost:8080/login" /> 8 16 } 9 17 -
frontend/src/Components/ProfilePage/DataForm.js
r07f4e8b r0f5aa27 11 11 12 12 const handleClose = () => setShow(false); 13 const handleShow = (e) => { 13 const handleShow = (e) => { 14 14 e.preventDefault(); 15 15 setShow(true); … … 29 29 <Form.Group as={Col} controlId="name"> 30 30 <Form.Label>Име</Form.Label> 31 <Form.Control type="text" value={props.data["name"]} /> 31 <Form.Control type="text" value={props.data["name"]} 32 name={"name"}/> 32 33 </Form.Group> 33 34 … … 38 39 placeholder="" 39 40 value={props.data["surname"]} 41 name={"surname"} 40 42 /> 41 43 </Form.Group> … … 45 47 <Form.Group as={Col} controlId="name"> 46 48 <Form.Label>Датум на раѓање</Form.Label> 47 <Form.Control type="date" value={props.data["dateOfBirth"]} /> 49 <Form.Control type="date" value={props.data["dateOfBirth"]} 50 name={"dateOfBirth"}/> 48 51 </Form.Group> 49 52 … … 54 57 placeholder="" 55 58 value={props.data["country"]} 59 name={"country"} 56 60 /> 57 61 </Form.Group> … … 60 64 <Form.Group className="mb-3" controlId="address"> 61 65 <Form.Label>Адреса</Form.Label> 62 <Form.Control type="text" value={props.data["address"]} /> 66 <Form.Control type="text" value={props.data["address"]} 67 name={"address"}/> 63 68 </Form.Group> 64 69 … … 66 71 <Form.Group as={Col} controlId="city"> 67 72 <Form.Label>Град</Form.Label> 68 <Form.Control type="text" value={props.data["city"]} /> 73 <Form.Control type="text" value={props.data["city"]} 74 name={"city"}/> 69 75 </Form.Group> 70 76 … … 75 81 placeholder="" 76 82 value={props.data["zip"]} 83 name={"zip"} 77 84 /> 78 85 </Form.Group> … … 82 89 <Form.Group as={Col} controlId="email"> 83 90 <Form.Label>Email</Form.Label> 84 <Form.Control type="email" value={props.data["email"]} /> 91 <Form.Control type="email" value={props.data["email"]} 92 name={"email"}/> 85 93 </Form.Group> 86 94 … … 91 99 placeholder="" 92 100 value={props.data["mobile"]} 101 name={"mobile"} 93 102 /> 94 103 </Form.Group> -
frontend/src/Components/RestaurantDetails/MenuItem.js
r07f4e8b r0f5aa27 6 6 7 7 const data = props.data; 8 console.log("dva orla")9 8 console.log(props) 10 9 return (<> -
frontend/src/Pages/NoBusinessRegisteredError.js
r07f4e8b r0f5aa27 14 14 const Auth = useAuth(); 15 15 const isLoggedIn = Auth.userIsAuthenticated(); 16 const userId = localStorage.getItem("userId")16 const userId = Auth.getUser().userId 17 17 const [registered, setRegistered] = useState(false); 18 18 let checked = false; … … 26 26 27 27 const { data: firma, isLoading: firmaIsLoading, getData: getFirmi} = useGet("/business/" + userId + "/unapproved", changed) 28 28 const { data, isLoading, getData} = useGet("/" + userId + "/hasBusiness") 29 29 30 30 31 useEffect(() => { … … 52 53 } 53 54 54 ! firmaIsLoading && firma && firma.length > 0 && firma[0].approved&& navigator("/resources/hotel")55 !isLoading && data && navigator("/resources/hotel") 55 56 56 57 -
pom.xml
r07f4e8b r0f5aa27 19 19 </properties> 20 20 <dependencies> 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter-oauth2-client</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-mail</artifactId> 28 </dependency> 21 29 <dependency> 22 30 <groupId>org.springframework.boot</groupId> -
src/main/java/com/tourMate/TourMateApplication.java
r07f4e8b r0f5aa27 3 3 import org.springframework.boot.SpringApplication; 4 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.mail.javamail.JavaMailSender; 7 import org.springframework.mail.javamail.JavaMailSenderImpl; 8 import org.springframework.scheduling.annotation.EnableScheduling; 9 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 import org.springframework.security.crypto.password.PasswordEncoder; 5 11 import org.springframework.transaction.annotation.EnableTransactionManagement; 12 13 import java.util.Properties; 6 14 7 15 @SpringBootApplication 8 16 @EnableTransactionManagement 17 @EnableScheduling 9 18 public class TourMateApplication { 10 19 … … 13 22 } 14 23 24 @Bean 25 public PasswordEncoder passwordEncoder() { 26 return new BCryptPasswordEncoder(); 27 } 28 29 @Bean 30 public JavaMailSender getJavaMailSender() { 31 JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); 32 mailSender.setHost("smtp.gmail.com"); 33 mailSender.setPort(587); 34 35 mailSender.setUsername("trip2mk@gmail.com"); 36 mailSender.setPassword("xarb ggqg mvmr zciw"); 37 38 Properties props = mailSender.getJavaMailProperties(); 39 props.put("mail.transport.protocol", "smtp"); 40 props.put("mail.smtp.auth", "true"); 41 props.put("mail.smtp.starttls.enable", "true"); 42 props.put("mail.debug", "true"); 43 44 return mailSender; 45 } 46 15 47 } -
src/main/java/com/tourMate/config/SecurityConfig.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.config; 2 2 3 import com.fasterxml.jackson.databind.ObjectMapper; 4 import jakarta.servlet.http.HttpServletResponse; 3 import com.tourMate.config.oauth2.CustomOAuth2FailureHandler; 4 import com.tourMate.config.oauth2.CustomOAuth2SuccessHandler; 5 import com.tourMate.config.oauth2.CustomOAuth2UserDetailService; 6 import org.springframework.beans.factory.annotation.Autowired; 5 7 import org.springframework.context.annotation.Bean; 6 8 import org.springframework.context.annotation.Configuration; … … 10 12 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11 13 import org.springframework.security.config.http.SessionCreationPolicy; 12 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;13 import org.springframework.security.crypto.password.PasswordEncoder;14 14 import org.springframework.security.web.SecurityFilterChain; 15 15 import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler; … … 26 26 27 27 private final UserSecurity userSecurity; 28 @Autowired 29 private CustomOAuth2UserDetailService customOAuth2UserDetailService; 30 @Autowired 31 private CustomOAuth2FailureHandler oAuth2FailureHandler; 32 @Autowired 33 private CustomOAuth2SuccessHandler oAuth2SuccessHandler; 28 34 29 35 public SecurityConfig(UserSecurity userSecurity) { … … 56 62 return bean; 57 63 } 58 @Bean59 public PasswordEncoder passwordEncoder() {60 return new BCryptPasswordEncoder();61 }62 64 63 65 @Bean … … 76 78 .requestMatchers(new AntPathRequestMatcher("/upload")).permitAll() 77 79 .requestMatchers(new AntPathRequestMatcher("/business/approve/*")).hasAnyAuthority("SUPERADMIN") 80 .requestMatchers(new AntPathRequestMatcher("/users/unlock/*")).hasAnyAuthority("SUPERADMIN") 81 .requestMatchers(new AntPathRequestMatcher("/users/approve/*")).hasAnyAuthority("SUPERADMIN") 82 .requestMatchers(new AntPathRequestMatcher("/business/unapproved")).hasAnyAuthority("SUPERADMIN") 78 83 .requestMatchers(new AntPathRequestMatcher("/business/add/*")).authenticated() 79 84 .requestMatchers(new AntPathRequestMatcher("/*/user/{userId}")).access(userSecurity) 80 .anyRequest().permitAll() 81 // .anyRequest().authenticated() 85 // .anyRequest().permitAll() 86 .anyRequest().authenticated() 87 .and() 88 .oauth2Login() 89 .loginPage("/login") 90 .permitAll() 91 .userInfoEndpoint(x -> x.userService(customOAuth2UserDetailService)) 92 // .userService(customOAuth2UserDetailService) 93 .successHandler(oAuth2SuccessHandler) 94 .failureHandler(oAuth2FailureHandler) 82 95 .and() 83 96 .formLogin() 84 .loginProcessingUrl("/api/login").usernameParameter("username").passwordParameter("password") 85 .successHandler((request, response, authentication) -> { 86 response.setStatus(HttpServletResponse.SC_OK); 87 response.setCharacterEncoding("UTF-8"); 88 response.setContentType("application/json"); 89 response.getWriter().print("{\"message\": \"Login successful\","); 90 response.getWriter().print("\"auth\":" + new ObjectMapper().writeValueAsString(authentication) + "}"); 91 response.getWriter().flush(); 92 }) 93 .failureHandler((request, response, exception) -> { 94 response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 95 response.sendRedirect("/login"); 96 response.getWriter().print("Neuspesna najava\n" + exception.getMessage()); 97 response.getWriter().flush(); 98 }) 97 .loginPage("/login") 98 .successHandler(oAuth2SuccessHandler) 99 .permitAll() 99 100 .permitAll() 100 101 .and() -
src/main/java/com/tourMate/config/UserSecurity.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.config; 2 2 3 import com.tourMate.config.oauth2.CustomOAuth2UserDetailService; 4 import com.tourMate.config.oauth2.OAuth2UserDetailsCustom; 3 5 import com.tourMate.entities.Hotels; 4 6 import com.tourMate.entities.User; … … 25 27 public boolean hasUserId(Authentication authentication, Long userId) { 26 28 System.out.println(userId); 27 User user = (User) authentication.getPrincipal(); 28 System.out.println(user.getUserID()); 29 System.out.println(authentication.getPrincipal()); 30 return userId == user.getUserID(); 29 Long id; 30 if(authentication.getPrincipal() instanceof OAuth2UserDetailsCustom oAuth2UserDetailsCustom) 31 { 32 id = oAuth2UserDetailsCustom.getId(); 33 } 34 else 35 { 36 User user = (User) authentication.getPrincipal(); 37 id = user.getUserID(); 38 } 39 return userId == id; 31 40 } 32 41 -
src/main/java/com/tourMate/controllers/HotelController.java
r07f4e8b r0f5aa27 35 35 return ResponseEntity.ok(hoteli); 36 36 } catch (Exception e) { 37 // Handle the exception, log it, and return an error response38 37 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); 39 38 } … … 41 40 42 41 @GetMapping(path = "/hotel/user/{id}") 43 public ResponseEntity<List<Hotels>> getHotelsForUser (@PathVariable(name = "id") long userId) 44 { 45 try { 46 42 public ResponseEntity<List<Hotels>> getHotelsForUser(@PathVariable(name = "id") long userId) { 43 try { 47 44 List<Hotels> hoteli = hotelManager.getHotelsForUser(userId); 48 45 return ResponseEntity.ok(hoteli); … … 53 50 54 51 @GetMapping(path = "/hotel/{id}/list") 55 public ResponseEntity<Hotels> getHotelById (@PathVariable(name = "id") long hotelId) 56 { 57 try { 58 52 public ResponseEntity<Hotels> getHotelById(@PathVariable(name = "id") long hotelId) { 53 try { 59 54 return ResponseEntity.ok(hotelManager.findHotelByID(hotelId)); 60 55 } catch (Exception e) { … … 65 60 66 61 @PostMapping(path = "/hotel/edit") 67 public void edit(@RequestBody Hotels hotel) 68 { 62 public void edit(@RequestBody Hotels hotel) { 69 63 hotelManager.editHotel(hotel.getHotelId(), hotel.getHotelName(), hotel.getHotelDescripiton(), hotel.getHotelLocation(), hotel.getHotelEDBS(), hotel.getParking(), hotel.getPetFriendly(), hotel.getInternetAvailable()); 70 64 } … … 72 66 @GetMapping(path = "/hotel/delete") 73 67 public ResponseEntity remove(@RequestParam(name = "hotelId") long hotelId) { 74 try 75 { 68 try { 76 69 hotelManager.deleteHotel(hotelId); 77 70 return new ResponseEntity(HttpStatus.OK); 78 } 79 catch (Exception exception) 80 { 81 return new ResponseEntity(HttpStatus.NOT_FOUND); 82 } 83 } 84 71 } catch (Exception exception) { 72 return new ResponseEntity(HttpStatus.NOT_FOUND); 73 } 74 } 85 75 86 76 … … 90 80 hotelManager.deleteHotelImage(hotelId); 91 81 return new ResponseEntity(HttpStatus.OK); 92 } 93 catch (Exception exception) { 82 } catch (Exception exception) { 94 83 return new ResponseEntity(HttpStatus.NOT_FOUND); 95 84 } … … 97 86 98 87 @GetMapping(path = "/hotel/{id}/room") 99 public List<HotelRoom> getHotelRooms(@PathVariable(value = "id") long hotelId) 100 { 88 public List<HotelRoom> getHotelRooms(@PathVariable(value = "id") long hotelId) { 101 89 System.out.println("ovde so id: " + hotelId); 102 90 return hotelManager.getRoomsOfHotel(hotelId); … … 108 96 public void addRoom(@RequestBody HotelRoom room, 109 97 @RequestParam(name = "hotelId") long hotelId) { 110 Hotels h = hotelManager.findHotelByID(hotelId); 111 hotelManager.createRoom(h, room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice(), room.getNumOfBeds()); 98 hotelManager.createRoom(hotelId, room.getHotelRoomDescription(), room.getHotelRoomName(), room.getKitchenAvailable(), room.getAirConditioning(), room.getBalcony(), room.getPrice(), room.getNumOfBeds()); 112 99 } 113 100 … … 119 106 @GetMapping(path = "/hotel/rooms/delete") 120 107 public ResponseEntity removeRoom(@RequestParam(name = "hotelRoomId") long hotelRoomId) { 121 try 122 { 108 try { 123 109 hotelManager.deleteRoom(hotelRoomId); 124 110 return new ResponseEntity(HttpStatus.OK); 125 } 126 catch (Exception exception) 127 { 111 } catch (Exception exception) { 128 112 return new ResponseEntity(HttpStatus.NOT_FOUND); 129 113 } … … 139 123 @GetMapping(path = "/hotel/rooms/reservation/delete") 140 124 public ResponseEntity removeReservation(@RequestParam(name = "hotelRoomReservationId") long hotelRoomReservationId) { 141 try 142 { 125 try { 143 126 hotelManager.deleteReservation(hotelRoomReservationId); 144 127 return new ResponseEntity(HttpStatus.OK); 145 } 146 catch (Exception exception) 147 { 148 return new ResponseEntity(HttpStatus.NOT_FOUND); 149 } 150 } 151 152 //HOTEL AVAILABILITY CRUD 128 } catch (Exception exception) { 129 return new ResponseEntity(HttpStatus.NOT_FOUND); 130 } 131 } 132 133 //HOTEL AVAILABILITY CRUD 153 134 @PostMapping(path = "/hotel/rooms/available/{id}/add") 154 135 public void addRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable, 155 @PathVariable long id) 156 { 157 HotelRoom hotelRoom = hotelManager.findRoomById(id); 158 hotelManager.createRoomAvailible(hotelRoom, hotelRoomAvailable.getDateFrom(), hotelRoomAvailable.getDateTo(), hotelRoomAvailable.getNumberOfBeds()); 136 @PathVariable long id) { 137 138 hotelManager.createRoomAvailible(id, hotelRoomAvailable.getDateFrom(), hotelRoomAvailable.getDateTo(), hotelRoomAvailable.getNumberOfBeds()); 159 139 } 160 140 161 141 @PostMapping(path = "/hotel/rooms/available/edit") 162 public void editRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable) 163 { 142 public void editRoomAvailible(@RequestBody HotelRoomAvailable hotelRoomAvailable) { 164 143 hotelManager.editRoomAvailible(hotelRoomAvailable.getHotelRoomAvailableId(), hotelRoomAvailable.getHotelRoom(), hotelRoomAvailable.getDateFrom(), hotelRoomAvailable.getDateTo(), hotelRoomAvailable.getNumberOfBeds()); 165 144 } 166 145 167 146 @GetMapping(path = "/hotel/rooms/available/remove") 168 public ResponseEntity removeRoomAvailible(@RequestParam(name = "hotelRoomAvailibleId") long hotelRoomAvailibleId) 169 { 170 try 171 { 147 public ResponseEntity removeRoomAvailible(@RequestParam(name = "hotelRoomAvailibleId") long hotelRoomAvailibleId) { 148 try { 172 149 hotelManager.deleteRoomAvailible(hotelRoomAvailibleId); 173 150 return new ResponseEntity(HttpStatus.OK); 174 } 175 catch (Exception ex) 176 { 151 } catch (Exception ex) { 177 152 return new ResponseEntity(HttpStatus.NOT_FOUND); 178 153 } … … 180 155 181 156 @GetMapping(path = "hotel/rooms/{id}/available") 182 public List<HotelRoomAvailable> getRoomAvailability(@PathVariable Long id) 183 { 157 public List<HotelRoomAvailable> getRoomAvailability(@PathVariable Long id) { 184 158 return hotelManager.getRoomsAvailableById(id); 185 159 } … … 190 164 @RequestParam(name = "dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo, 191 165 @RequestParam(name = "numBeds") int numBeds, 192 @RequestParam(name = "flexible") Boolean flexible) 193 { 194 System.out.println(flexible); 195 System.out.println(dateFrom + " " + dateTo); 166 @RequestParam(name = "flexible") Boolean flexible) { 196 167 return hotelManager.getRoomsAvailibilityByDateAndLocation(hotelLocation, dateFrom, dateTo, numBeds, flexible); 197 168 } 198 169 199 170 @PostMapping(path = "/hotel/reserve") 200 public void reserveHotelRoom(@RequestParam(name = "hotelRoomId") Long hotelRoomId,171 public void reserveHotelRoom(@RequestParam(name = "hotelRoomId") Long hotelRoomId, 201 172 @RequestParam(name = "userId") Long userId, 202 173 @RequestParam(name = "hotelRoomAvailableId") Long hotelRoomAvailableId, 203 174 @RequestParam(name = "numberOfBeds") Integer numberOfBeds, 204 175 @RequestParam(name = "from") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date from, 205 @RequestParam(name = "to") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date to){ 206 176 @RequestParam(name = "to") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date to) { 207 177 208 178 … … 211 181 212 182 @GetMapping(path = "/hotel/{id}/reservations/active") 213 public List<HotelReservationDto> getActiveReservationsForHotel(@PathVariable Long id) 214 { 183 public List<HotelReservationDto> getActiveReservationsForHotel(@PathVariable Long id) { 215 184 return hotelManager.findVaidReseravtionsByHotel(id); 216 185 } 217 186 218 187 @GetMapping(path = "/hotel/reservations/user/{id}") 219 public List<HotelReservationUserDto> getActiveReservationsForUser(@PathVariable Long id) 220 { 188 public List<HotelReservationUserDto> getActiveReservationsForUser(@PathVariable Long id) { 221 189 return hotelManager.findValidHotelReservationsByUser(id); 222 190 } 223 191 224 192 @GetMapping(path = "/hotel/reservations/user/{id}/past") 225 public List<HotelReservationUserDto> getPastReservationsForUser(@PathVariable Long id) 226 { 193 public List<HotelReservationUserDto> getPastReservationsForUser(@PathVariable Long id) { 227 194 return hotelManager.findPastHotelReservationsByUser(id); 228 195 } 229 196 230 197 @GetMapping(path = "/hotel/{id}/images") 231 public List<HotelsImages> getImagesForHotel(@PathVariable Long id) 232 { 198 public List<HotelsImages> getImagesForHotel(@PathVariable Long id) { 233 199 return hotelManager.getHotelImages(id); 234 200 } 235 201 236 202 @GetMapping(path = "/room/{id}/images") 237 public List<HotelRoomImages> getImagesForHotelRoom(@PathVariable Long id) 238 { 203 public List<HotelRoomImages> getImagesForHotelRoom(@PathVariable Long id) { 239 204 return hotelManager.getRoomImages(id); 240 205 } 241 206 242 207 @PostMapping("/hotel/{id}/cancel") 243 public void cancelHotelReservation(@PathVariable Long id) {208 public void cancelHotelReservation(@PathVariable Long id) { 244 209 hotelManager.deleteReservation(id); 245 210 } -
src/main/java/com/tourMate/controllers/RestaurantController.java
r07f4e8b r0f5aa27 6 6 import com.tourMate.dto.RestaurantReservationUserDto; 7 7 import com.tourMate.entities.*; 8 import com.tourMate.services.MenuManager; 8 9 import com.tourMate.services.RestaurantManager; 9 10 import org.springframework.beans.factory.annotation.Autowired; … … 23 24 @Autowired 24 25 RestaurantManager restaurantManager; 26 @Autowired 27 MenuManager menuManager; 25 28 26 29 @PostMapping(path = "/restaurant/add") … … 34 37 public void addMenu(@PathVariable(name = "id") long restaurantId, @RequestBody Menu menu) { 35 38 restaurantManager.addMenuToRestaurant(restaurantId, menu); 39 } 40 41 @PostMapping(path = "/menu/{id}/edit") 42 public void editMenu(@PathVariable Long id, 43 @RequestParam String name, 44 @RequestParam String ingredients, 45 @RequestParam double price) 46 { 47 menuManager.editMenu(id, name, ingredients, price); 36 48 } 37 49 … … 149 161 @RequestParam(name = "hourTo") String hourTo, 150 162 @RequestParam(name = "numPeople") int noSeats) { 151 Date dateFrom = date; 152 Date dateTo = Date.from(date.toInstant()); 153 String[] splittedFrom = hourFrom.split(":"); 154 String[] splittedTo = hourTo.split(":"); 155 dateFrom.setHours(Integer.parseInt(splittedFrom[0])); 156 dateFrom.setMinutes(Integer.parseInt(splittedFrom[1])); 157 dateTo.setHours(Integer.parseInt(splittedTo[0])); 158 dateTo.setMinutes(Integer.parseInt(splittedTo[1])); 159 return restaurantManager.getTablesByDateAndLocation(restaurantLocation, dateFrom, dateTo, noSeats); 163 164 return restaurantManager.getTablesByDateAndLocation(restaurantLocation, date, hourFrom, hourTo, noSeats); 160 165 } 161 166 -
src/main/java/com/tourMate/controllers/ReviewController.java
r07f4e8b r0f5aa27 28 28 public void edit(@RequestBody Reviews review) 29 29 { 30 // editReview(long id, String title, String description, int numStar, Hotels hotel, Restaurants restaurant, Transport transport)31 30 reviewManager.editReview(review.getReviewId(), review.getTitle(), review.getDescription(), review.getNumStar(), review.getHotel(), review.getRestaurant(), review.getTransport()); 32 31 } -
src/main/java/com/tourMate/controllers/TransportController.java
r07f4e8b r0f5aa27 84 84 @PostMapping(path = "/transport/available/add") 85 85 public void add(@RequestBody TransportAvailible transportAvailable, @RequestParam(name = "transportId") long transportId) { 86 Transport t = transportManager.getTransportById(transportId); 87 List<TransportRoute> routes = transportAvailable.getRoutes().stream().toList(); 88 routes.get(0).setDeparture(transportAvailable.getDate()); 89 transportAvailable.setTime(routes.get(routes.size() - 1).getArrival()); 90 routes.forEach(x -> x.setParentRoute(transportAvailable)); 91 transportAvailable.setTransport(t); 92 transportManager.createTransportAvailable(transportAvailable.getTransport(), transportAvailable.getFrom(), transportAvailable.getTo(), transportAvailable.getDate(), transportAvailable.getFreeSpace(), transportAvailable.getTime(), routes); 86 87 transportManager.createTransportAvailable(transportAvailable, transportAvailable.getTransport(), transportAvailable.getFrom(), transportAvailable.getTo(), transportAvailable.getDate(), transportAvailable.getFreeSpace(), transportAvailable.getTime(), transportId, transportAvailable.getRoutes()); 93 88 } 94 89 -
src/main/java/com/tourMate/controllers/UsersController.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.controllers; 2 2 3 import com.tourMate.dto.PrincipalInfo; 3 4 import com.tourMate.entities.Business; 4 5 import com.tourMate.entities.User; 6 import com.tourMate.config.oauth2.OAuth2UserDetailsCustom; 5 7 import com.tourMate.services.BusinessManager; 6 8 import com.tourMate.services.UsersManager; … … 9 11 import org.springframework.http.ResponseEntity; 10 12 import org.springframework.security.core.Authentication; 13 import org.springframework.security.core.parameters.P; 11 14 import org.springframework.web.bind.annotation.*; 12 15 … … 57 60 usersManager.approveUserProfile(userId); 58 61 return new ResponseEntity<>(HttpStatus.OK); 59 60 61 62 } 62 63 … … 70 71 @PostMapping(path = "/register") 71 72 public List<User> add(@RequestBody User user) { 72 System.out.println(user.getName() + user.getSurname());73 73 usersManager.createUser(user.getName(), user.getSurname(), user.getEmail(), user.getBirthDate(), user.getAddress(), user.getContact()); 74 74 return usersManager.getCreatedUsers(); … … 88 88 @GetMapping(value = "/principal") 89 89 @ResponseBody 90 public User currentUser(Authentication authentication) { 91 return (User) authentication.getPrincipal(); 90 public PrincipalInfo currentUser(Authentication authentication) { 91 Long id; 92 if(authentication.getPrincipal() instanceof OAuth2UserDetailsCustom) 93 { 94 OAuth2UserDetailsCustom oAuth2UserDetailsCustom = (OAuth2UserDetailsCustom) authentication.getPrincipal(); 95 id = oAuth2UserDetailsCustom.getId(); 96 } 97 else 98 { 99 User user = (User) authentication.getPrincipal(); 100 id = user.getUserID(); 101 } 102 return usersManager.getPrincipalInfo(id); 92 103 } 93 104 @PostMapping(path = "/user/edit") 94 public List<User>edit(@RequestBody User user)105 public void edit(@RequestBody User user) 95 106 { 96 System.out.println(user.getName() + " " + user.getSurname() + "id e " + user.getUserID());97 // long userID, String name, String surname, String email, Date birthDate, String address, String contact98 107 usersManager.editUser(user.getUserID(), user.getName(), user.getSurname(), user.getEmail(), user.getBirthDate(), user.getAddress(), user.getContact()); 99 return usersManager.getCreatedUsers();100 108 } 101 109 102 110 @GetMapping(path = "/user/delete") 103 public ResponseEntity remove(@RequestParam(name = "userId") long userId) {111 public ResponseEntity<?> remove(@RequestParam(name = "userId") long userId) { 104 112 try 105 113 { 106 114 usersManager.deleteUser(userId); 107 return new ResponseEntity (HttpStatus.OK);115 return new ResponseEntity<>(HttpStatus.OK); 108 116 } 109 117 catch (Exception exception) 110 118 { 111 return new ResponseEntity (HttpStatus.NOT_FOUND);119 return new ResponseEntity<>(HttpStatus.NOT_FOUND); 112 120 } 113 121 } 114 122 115 123 @GetMapping("/users/unlock/{id}") 116 public ResponseEntity unlock(@PathVariable Long id)124 public ResponseEntity<?> unlock(@PathVariable Long id) 117 125 { 118 126 usersManager.unlock(id); 119 return new ResponseEntity(HttpStatus.OK); 127 return new ResponseEntity<>(HttpStatus.OK); 128 } 129 130 @PostMapping("/users/{id}/connect") 131 public ResponseEntity<?> connectAccount(@PathVariable Long id, 132 @RequestParam String username, 133 @RequestParam String password) 134 { 135 usersManager.connectAccount(id, username, password); 136 return new ResponseEntity<>(HttpStatus.OK); 137 } 138 139 @GetMapping("/users/{id}/connected") 140 public List<User> getConnectedAccounts(@PathVariable Long id) 141 { 142 return usersManager.findConnectedAccountsByUser(id); 120 143 } 121 144 } -
src/main/java/com/tourMate/controllers/UtilsController.java
r07f4e8b r0f5aa27 2 2 3 3 import org.springframework.http.ResponseEntity; 4 import org.springframework.stereotype.Controller; 4 5 import org.springframework.web.bind.annotation.GetMapping; 5 6 import org.springframework.web.bind.annotation.RestController; … … 10 11 import java.net.http.HttpResponse; 11 12 12 @ RestController13 @Controller 13 14 public class UtilsController { 14 @GetMapping("/loo") 15 public ResponseEntity<?> testFnc(RedirectAttributes attributes) { 16 String redirectUrl = "https://example.com"; // Replace with your desired redirect URL 17 18 // Using UriComponentsBuilder to handle URL encoding 19 return ResponseEntity 20 .status(302) // 302 Found status code for redirect 21 .location(UriComponentsBuilder.fromUriString(redirectUrl).build().toUri()) 22 .build(); 15 @GetMapping("/login") 16 public String getLoginPage() 17 { 18 return "login"; 23 19 } 24 20 } -
src/main/java/com/tourMate/dao/HotelDao.java
r07f4e8b r0f5aa27 97 97 98 98 List<HotelRoomReservations> findPastReservationByUser(User u); 99 100 List<HotelRoomReservations> getReservationsInPeriod(String hotelLocation, Date dateFrom, Date dateTo); 99 101 // public void createHotel(Hotels hotel, long userId); 100 102 // public void editHotel(long hotelId, String hotelName, String hotelDescripiton, String hotelLocation, String hotelEDBS, Boolean parking, Boolean petFriendly, Boolean internetAvailable); -
src/main/java/com/tourMate/dao/TransportDao.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.dao; 2 2 3 import com.tourMate.dto.RouteListingDto;4 import com.tourMate.dto.TransportDto;5 3 import com.tourMate.entities.*; 6 4 import jakarta.transaction.Transactional; … … 19 17 List<Transport> getTransports(); 20 18 21 List<Transport Dto> getTransportsByUser(User u);19 List<Transport> getTransportsByUser(User u); 22 20 23 List< RouteListingDto> getRoutesForTransport(Transport t);21 List<TransportAvailible> getRoutesForTransport(Transport t); 24 22 25 Transport DtofindTransportById(long transportId);23 Transport findTransportById(long transportId); 26 24 27 25 Transport getTransportById(long transportId); -
src/main/java/com/tourMate/dao/UsersDao.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.dao; 2 2 3 import com.tourMate.entities.Providers; 3 4 import com.tourMate.entities.Role; 4 5 import com.tourMate.entities.User; 6 import jakarta.transaction.Transactional; 5 7 import org.springframework.security.core.userdetails.UserDetails; 6 8 … … 29 31 30 32 Role findById(Long id); 31 void updateUser(User s); 33 User updateUser(User s); 34 User findByUsernameAndProvider(String username, String providers); 35 36 @Transactional 37 User mergeUser(User user); 38 39 List<User> getAdmins(); 40 41 List<User> findConnectedAccountsByUser(User u); 32 42 } -
src/main/java/com/tourMate/dao/impl/BusinessDaoImpl.java
r07f4e8b r0f5aa27 4 4 import com.tourMate.entities.Business; 5 5 import com.tourMate.entities.User; 6 import com.tourMate.events.OnBusinessApprovedEvent; 6 7 import jakarta.persistence.EntityManager; 7 8 import jakarta.persistence.PersistenceContext; 8 9 import jakarta.transaction.Transactional; 10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.context.ApplicationEventPublisher; 9 12 import org.springframework.stereotype.Service; 10 13 … … 16 19 @PersistenceContext 17 20 EntityManager em; 21 @Autowired 22 ApplicationEventPublisher eventPublisher; 18 23 19 24 @Transactional … … 37 42 public boolean hasBusiness(User u) 38 43 { 39 return Integer.parseInt(em.createQuery("SELECT COUNT(b) FROM Business b WHERE b.user = :user").setParameter("user", u).getSingleResult().toString()) > 0; 44 return Integer.parseInt(em.createQuery("SELECT COUNT(b) FROM Business b WHERE b.user = :user or b.user in :users") 45 .setParameter("user", u) 46 .setParameter("users", u.getConnectedAccounts()) 47 .getSingleResult().toString()) > 0; 40 48 } 41 49 … … 49 57 public void approveBusiness(Business b) { 50 58 em.persist(b); 59 eventPublisher.publishEvent(new OnBusinessApprovedEvent(b.getUser())); 51 60 } 52 61 -
src/main/java/com/tourMate/dao/impl/HotelDaoImpl.java
r07f4e8b r0f5aa27 3 3 import com.tourMate.dao.HotelDao; 4 4 import com.tourMate.entities.*; 5 import com.tourMate.events.OnHotelReservationEvent; 6 import com.tourMate.events.OnRegistrationSuccessEvent; 5 7 import jakarta.persistence.EntityManager; 6 8 import jakarta.persistence.PersistenceContext; 7 9 import jakarta.transaction.Transactional; 10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.context.ApplicationEventPublisher; 8 12 import org.springframework.stereotype.Service; 9 13 … … 17 21 @PersistenceContext 18 22 EntityManager em; 23 @Autowired 24 ApplicationEventPublisher eventPublisher; 19 25 20 26 @Override … … 31 37 @Override 32 38 public List<Hotels> getHotelsForUser(User u) { 33 return em.createQuery("select h from Hotels h where h.owner = :u").setParameter("u", u).getResultList(); 34 } 35 36 @Override 37 public List<Hotels> getHotelsByLocation(String hotelLocation) { 38 return em.createQuery("select h from Hotels h where h.hotelLocation = hotelLocation").getResultList(); 39 } 40 39 return em.createQuery("select h from Hotels h where h.owner = :u or h.owner in :users") 40 .setParameter("u", u) 41 .setParameter("users", u.getConnectedAccounts()) 42 .getResultList(); 43 } 41 44 @Transactional 42 45 @Override … … 211 214 } 212 215 213 214 215 216 216 } 217 217 … … 232 232 public void createReservation(HotelRoomReservations r) { 233 233 em.persist(r); 234 eventPublisher.publishEvent(new OnHotelReservationEvent(r.getUser(), r)); 234 235 } 235 236 … … 243 244 @Override 244 245 public void deleteReservation(HotelRoomReservations hr) { 245 246 246 em.remove(hr); 247 247 } … … 281 281 .setParameter("user", u).getResultList(); 282 282 } 283 284 @Override 285 public List<HotelRoomReservations> getReservationsInPeriod(String hotelLocation, Date dateFrom, Date dateTo) { 286 return em.createQuery("select hr from HotelRoomReservations hr where hr.hotelRoom.hotel.hotelLocation like :hotelLocation and (hr.dateFrom between :dateFrom and :dateTo) or (hr.dateTo between :dateFrom and :dateTo)") 287 .setParameter("hotelLocation", hotelLocation) 288 .setParameter("dateFrom", dateFrom) 289 .setParameter("dateTo", dateTo) 290 .getResultList(); 291 } 292 293 @Override 294 public List<Hotels> getHotelsByLocation(String hotelLocation) 295 { 296 return em.createQuery("select h from Hotels h where h.hotelLocation like :hotelLocation") 297 .setParameter("hotelLocation", hotelLocation) 298 .getResultList(); 299 } 283 300 } -
src/main/java/com/tourMate/dao/impl/RestaurantDaoImpl.java
r07f4e8b r0f5aa27 102 102 @Override 103 103 public List<Restaurant> getRestaurantsByUser(User u) { 104 return em.createQuery("select r from Restaurant r where r.restaurantOwner = :u").setParameter("u", u).getResultList(); 104 return em.createQuery("select r from Restaurant r where r.restaurantOwner = :u or r.restaurantOwner in :users") 105 .setParameter("u", u) 106 .setParameter("users", u.getConnectedAccounts()) 107 .getResultList(); 105 108 } 106 109 -
src/main/java/com/tourMate/dao/impl/TransportDaoImpl.java
r07f4e8b r0f5aa27 2 2 3 3 import com.tourMate.dao.TransportDao; 4 import com.tourMate.dto.RouteListingDto;5 import com.tourMate.dto.TransportDto;6 4 import com.tourMate.entities.*; 7 5 import jakarta.persistence.EntityManager; … … 37 35 38 36 @Override 39 public List<TransportDto> getTransportsByUser(User u) { 40 List<Transport> transports = em.createQuery("select t from Transport t where t.owner = :u").setParameter("u", u).getResultList(); 41 return transports.stream().map(x -> new TransportDto( 42 x.getTransportID(), 43 x.getTransportName(), 44 x.getCarBrand(), 45 x.getCarType(), 46 x.getCarManufacturedYear(), 47 x.getNoPassengers(), 48 x.getNoBags(), 49 x.getEMBG(), 50 x.getOwner(), 51 x.getCarPlate(), 52 x.getAvailableRoutes().stream().map(y -> new RouteListingDto( 53 y.getTransportAvailibleId(), 54 y.getFrom(), 55 y.getTo(), 56 y.getDate(), 57 y.getFreeSpace(), 58 y.getTime(), 59 y.getRoutes(), 60 y.getRoutes().stream() 61 .mapToDouble(TransportRoute::getPrice) 62 .max().orElse(0) 63 )).toList(), 64 x.getAvailableRoutes().stream() 65 .flatMapToDouble(y -> y.getRoutes() 66 .stream() 67 .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0) 68 )).toList(); 37 public List<Transport> getTransportsByUser(User u) { 38 List<Transport> transports = em.createQuery("select t from Transport t where t.owner = :u or t.owner in :users") 39 .setParameter("u", u) 40 .setParameter("users", u.getConnectedAccounts()) 41 .getResultList(); 42 return transports; 69 43 } 70 44 71 45 @Override 72 public List< RouteListingDto> getRoutesForTransport(Transport t) {46 public List<TransportAvailible> getRoutesForTransport(Transport t) { 73 47 List<TransportAvailible> transportsAvailible = em.createQuery("select ta from TransportAvailible ta where ta.transport = :transport").setParameter("transport", t).getResultList(); 74 return transportsAvailible.stream().map(x -> new RouteListingDto( 75 x.getTransportAvailibleId(), 76 x.getFrom(), 77 x.getTo(), 78 x.getDate(), 79 x.getFreeSpace(), 80 x.getTime(), 81 x.getRoutes(), 82 x.getRoutes().stream() 83 .mapToDouble(TransportRoute::getPrice) 84 .max().orElse(0) 85 )).toList(); 48 return transportsAvailible; 86 49 } 87 50 88 51 @Override 89 public Transport DtofindTransportById(long transportId) {52 public Transport findTransportById(long transportId) { 90 53 Transport x = em.find(Transport.class,transportId); 91 return new TransportDto( 92 x.getTransportID(), 93 x.getTransportName(), 94 x.getCarBrand(), 95 x.getCarType(), 96 x.getCarManufacturedYear(), 97 x.getNoPassengers(), 98 x.getNoBags(), 99 x.getEMBG(), 100 x.getOwner(), 101 x.getCarPlate(), 102 x.getAvailableRoutes().stream().map(y -> new RouteListingDto( 103 y.getTransportAvailibleId(), 104 y.getFrom(), 105 y.getTo(), 106 y.getDate(), 107 y.getFreeSpace(), 108 y.getTime(), 109 y.getRoutes(), 110 y.getRoutes().stream() 111 .mapToDouble(TransportRoute::getPrice) 112 .max().orElse(0) 113 )).toList(), 114 x.getAvailableRoutes().stream() 115 .flatMapToDouble(y -> y.getRoutes() 116 .stream() 117 .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0)); 54 return x; 118 55 } 119 56 -
src/main/java/com/tourMate/dao/impl/UsersDaoImpl.java
r07f4e8b r0f5aa27 4 4 import com.tourMate.entities.Role; 5 5 import com.tourMate.entities.User; 6 import com.tourMate.events.OnProfileEnabledEvent; 7 import com.tourMate.events.OnRegistrationSuccessEvent; 6 8 import jakarta.persistence.EntityManager; 7 9 import jakarta.persistence.PersistenceContext; 8 10 import jakarta.transaction.Transactional; 9 import org.jetbrains.annotations.NotNull;10 11 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.context.ApplicationEventPublisher; 11 13 import org.springframework.security.core.userdetails.UserDetails; 12 14 import org.springframework.security.crypto.password.PasswordEncoder; 13 import org.springframework.stereotype. Service;15 import org.springframework.stereotype.Repository; 14 16 15 17 import java.util.Date; 16 18 import java.util.List; 17 19 18 @ Service20 @Repository 19 21 public class UsersDaoImpl implements UsersDao { 20 22 21 23 @PersistenceContext 22 24 EntityManager em; 23 24 25 @Autowired 25 26 PasswordEncoder passwordEncoder; 27 @Autowired 28 private ApplicationEventPublisher eventPublisher; 26 29 27 30 @Transactional … … 30 33 Role r = em.find(Role.class, 2); 31 34 User user = new User(name, surname, email, passwordEncoder.encode("password"), birthDate, address, contact, r); 35 user.setProvider("local"); 36 user.setLocked(true); 32 37 em.persist(user); 38 if(user.getProvider().equals("local")) 39 { 40 eventPublisher.publishEvent(new OnRegistrationSuccessEvent(user)); 41 } 33 42 } 34 43 … … 84 93 u.setEnabled(true); 85 94 em.persist(u); 95 eventPublisher.publishEvent(new OnProfileEnabledEvent(u)); 86 96 } 87 97 … … 93 103 @Override 94 104 @Transactional 95 public voidupdateUser(User s) {105 public User updateUser(User s) { 96 106 em.persist(s); 107 return s; 97 108 } 98 109 110 @Override 111 public User findByUsernameAndProvider(String username, String providers) 112 { 113 try 114 { 115 return (User) em.createQuery("select u from User u where u.email = :username and u.provider = :provider") 116 .setParameter("username", username) 117 .setParameter("provider", providers) 118 .getSingleResult(); 119 } 120 catch (Exception ex) 121 { 122 return null; 123 } 124 } 99 125 126 @Override 127 @Transactional 128 public User mergeUser(User user) { 129 return em.merge(user); 130 } 131 132 @Override 133 public List<User> getAdmins() { 134 return em.createQuery("select u from User u where u.role.roleName = 'SUPERADMIN'") 135 .getResultList(); 136 } 137 138 @Override 139 public List<User> findConnectedAccountsByUser(User u) { 140 return em.createQuery("select u.connectedAccounts from User u where u = :user") 141 .setParameter("user", u) 142 .getResultList(); 143 } 100 144 } -
src/main/java/com/tourMate/dto/HotelDto.java
r07f4e8b r0f5aa27 21 21 private double averageScore; 22 22 private List<HotelsImages> images; 23 24 public HotelDto(long hotelId, String hotelName, String hotelDescripiton, String hotelLocation, String hotelEDBS, Boolean parking, Boolean petFriendly, Boolean internetAvailable, double totalPrice, List<HotelRoomAvailable> hotelRooms, List<Reviews> hotelReviews, double averageScore, List<HotelsImages> images) { 23 private Boolean promoted; 24 private Boolean marketed; 25 public HotelDto(long hotelId, String hotelName, String hotelDescripiton, String hotelLocation, String hotelEDBS, Boolean parking, Boolean petFriendly, Boolean internetAvailable, double totalPrice, List<HotelRoomAvailable> hotelRooms, List<Reviews> hotelReviews, double averageScore, List<HotelsImages> images, Boolean promoted, Boolean marketed) { 25 26 this.hotelId = hotelId; 26 27 this.hotelName = hotelName; … … 36 37 this.averageScore = averageScore; 37 38 this.images = images; 39 this.promoted = promoted; 40 this.marketed = marketed; 38 41 } 39 42 … … 132 135 this.images = images; 133 136 } 137 138 public void setHotelReviews(List<Reviews> hotelReviews) { 139 this.hotelReviews = hotelReviews; 140 } 141 142 public void setAverageScore(double averageScore) { 143 this.averageScore = averageScore; 144 } 145 146 public Boolean getPromoted() { 147 return promoted; 148 } 149 150 public void setPromoted(Boolean promoted) { 151 this.promoted = promoted; 152 } 153 154 public Boolean getMarketed() { 155 return marketed; 156 } 157 158 public void setMarketed(Boolean marketed) { 159 this.marketed = marketed; 160 } 134 161 } -
src/main/java/com/tourMate/entities/User.java
r07f4e8b r0f5aa27 14 14 import java.util.Collections; 15 15 import java.util.Date; 16 import java.util.List; 16 17 17 18 @Entity … … 27 28 private String name; 28 29 29 @Column(name = "surname", unique = false, nullable = false)30 @Column(name = "surname", unique = false, nullable = true) 30 31 private String surname; 31 32 … … 34 35 private String email; 35 36 36 @Column(name = "password", unique = true, nullable = false)37 @Column(name = "password", unique = true, nullable = true) 37 38 @NotNull 38 39 private String password; 39 40 40 @Column(name = "birth_date", unique = false, nullable = false)41 @Column(name = "birth_date", unique = false, nullable = true) 41 42 @NotNull 42 43 private Date birthDate; 43 44 44 @Column(name = "address", unique = false, nullable = false)45 @Column(name = "address", unique = false, nullable = true) 45 46 private String address; 46 47 47 @Column(name = "contact", unique = false, nullable = false)48 @Column(name = "contact", unique = false, nullable = true) 48 49 private String contact; 49 50 … … 57 58 boolean enabled; 58 59 60 @Column(name = "provider", unique = false, nullable = true) 61 String provider; 62 63 @ManyToMany 64 @JsonIgnore 65 List<User> connectedAccounts; 66 59 67 60 68 public User(@NotNull String name, String surname, @NotNull String email, @NotNull String password, @NotNull Date birthDate, String address, String contact, Role role) { … … 120 128 } 121 129 130 public List<User> getConnectedAccounts() { 131 return connectedAccounts; 132 } 133 134 public void setConnectedAccounts(List<User> connectedAccounts) { 135 this.connectedAccounts = connectedAccounts; 136 } 137 138 public void addConnectedUser(User u) 139 { 140 connectedAccounts.add(u); 141 } 122 142 123 143 public void setSurname(String surname) { … … 212 232 this.enabled = enabled; 213 233 } 234 235 public String getProvider() { 236 return provider; 237 } 238 239 public void setProvider(String provider) { 240 this.provider = provider; 241 } 214 242 } -
src/main/java/com/tourMate/services/HotelManager.java
r07f4e8b r0f5aa27 25 25 public HotelRoom findRoomById (long hotelRoomId); 26 26 public List<HotelRoomImages> getRoomImages(Long hotelRoom); 27 public void createRoom( Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds);27 public void createRoom(Long hotelId, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds); 28 28 public void editRoom(long hotelRoomId, Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price); 29 29 public void deleteRoom(long hotelRoomId); 30 public void createRoomAvailible( HotelRoomhotelRoom, Date dateFrom, Date dateTo, int numberOfBeds);30 public void createRoomAvailible(long hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds); 31 31 public void editRoomAvailible(long hotelRoomAvailableId, HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds); 32 32 public void editRoomAvailibleReservation(Long HotelRoomAvailableId, Long hotelRoomId, Date from, Date to, int numberOfBeds); … … 36 36 public List<HotelRoomAvailable> getRoomsAvailableById(Long id); 37 37 public List<HotelRoomAvailable> getRoomsAvailibilityByHotel(Hotels hotel); 38 39 List<HotelRoomReservations> getReservationsInPeriod(String hotelLocation, Date dateFrom, Date dateTo); 40 38 41 public List<HotelDto> getRoomsAvailibilityByDateAndLocation(String hotelLocation, Date dateFrom, Date dateTo, int numberOfBeds, Boolean flexible); 39 42 public void createReservation(Long userId, Long hotelRoomId, Long hotelRoomAvailableId, Date dateFrom, Date dateTo, Integer numberOfBeds); -
src/main/java/com/tourMate/services/RestaurantManager.java
r07f4e8b r0f5aa27 37 37 public List<RestaurantsTable> getRestaurantTables(long restaurantID); 38 38 39 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date hourFrom, DatehourTo, int noSeats);39 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date date, String hourFrom, String hourTo, int noSeats); 40 40 41 41 public RestaurantsTable findTableById(long tableId); -
src/main/java/com/tourMate/services/TransportManager.java
r07f4e8b r0f5aa27 45 45 public List<TransportAvailible> getTransportsAvailable(); 46 46 47 public void createTransportAvailable(Transport transport, String departureLocation, String arrivalLocation, Date date, Integer noSeats, Date departureHour, Collection<TransportRoute> routes);47 public void createTransportAvailable(TransportAvailible transportAvailible, Transport transport, String departureLocation, String arrivalLocation, Date date, Integer noSeats, Date departureHour, Long trnasportId, Collection<TransportRoute> routes); 48 48 public void editTransportAvailable(Transport transport, long availableID, String departureLocation, String arrivalLocation, Date date, Integer noSeats, Date departureHour); 49 49 -
src/main/java/com/tourMate/services/UsersManager.java
r07f4e8b r0f5aa27 1 1 package com.tourMate.services; 2 2 3 import com.tourMate.dto.PrincipalInfo; 3 4 import com.tourMate.entities.User; 4 5 … … 20 21 21 22 void unlock(Long id); 23 24 List<User> getAdmins(); 25 26 void connectAccount(Long id, String username, String password); 27 28 List<User> findConnectedAccountsByUser(Long id); 29 PrincipalInfo getPrincipalInfo(Long userId); 22 30 } -
src/main/java/com/tourMate/services/impl/HotelManagerImpl.java
r07f4e8b r0f5aa27 13 13 14 14 import java.time.Duration; 15 import java.util.Date; 16 import java.util.List; 17 import java.util.Map; 15 import java.util.*; 18 16 import java.util.stream.Collectors; 19 17 … … 123 121 124 122 @Override 125 public void createRoom(Hotels hotel, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) { 123 public void createRoom(Long hotelId, String hotelRoomDescription, String hotelRoomName, Boolean kitchenAvailable, Boolean airConditioning, Boolean balcony, double price, int numOfBeds) { 124 Hotels hotel = findHotelByID(hotelId); 126 125 HotelRoom hotelRoom = new HotelRoom(hotel, hotelRoomDescription, hotelRoomName, kitchenAvailable, airConditioning, balcony, price, numOfBeds); 127 126 hotelDao.createRoom(hotelRoom); … … 154 153 155 154 @Override 156 public void createRoomAvailible(HotelRoom hotelRoom, Date dateFrom, Date dateTo, int numberOfBeds) { 155 public void createRoomAvailible(long hotelRoomId, Date dateFrom, Date dateTo, int numberOfBeds) { 156 HotelRoom hotelRoom = findRoomById(hotelRoomId); 157 157 HotelRoomAvailable hra = new HotelRoomAvailable(hotelRoom, dateFrom, dateTo, numberOfBeds); 158 158 hotelDao.createRoomAvailible(hra); … … 168 168 hotelDao.editRoomAvailible(hr); 169 169 } 170 170 //01-01-2024 - 30-01-2024 171 //05-01-2024 - 10-01-2024 172 173 //01-01 - 05-01 174 //10-01 - 30-01 171 175 @Override 172 176 public void editRoomAvailibleReservation(Long HotelRoomAvailableId, Long hotelRoomId, Date from, Date to, int numberOfBeds){ … … 202 206 203 207 @Override 208 public List<HotelRoomReservations> getReservationsInPeriod(String hotelLocation, Date dateFrom, Date dateTo) 209 { 210 return hotelDao.getReservationsInPeriod(hotelLocation, dateFrom, dateTo); 211 } 212 213 @Override 204 214 public List<HotelDto> getRoomsAvailibilityByDateAndLocation(String hotelLocation, Date dateFrom, Date dateTo, int numberOfBeds, Boolean flexible) { 205 215 long numberOfNights = Duration.between(dateFrom.toInstant(), dateTo.toInstant()).toDays(); 216 List<Hotels> hotels = getHotelsByLocation(hotelLocation); 217 List<HotelRoomReservations> hotelRoomReservations = getReservationsInPeriod(hotelLocation, dateFrom, dateTo); 218 List<Hotels> hotelsWithReservations = hotelRoomReservations.stream().map(x -> x.getHotelRoom().getHotel()).toList(); 219 List<Hotels> mostReservedHotels = hotelRoomReservations.stream() 220 .collect(Collectors.groupingBy(x -> x.getHotelRoom().getHotel(), Collectors.counting())).entrySet().stream() 221 .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) 222 .limit(5) 223 .map(Map.Entry::getKey) 224 .toList(); 225 List<Hotels> leastReservedHotels = hotelRoomReservations.stream() 226 .collect(Collectors.groupingBy(x -> x.getHotelRoom().getHotel(), Collectors.counting())).entrySet().stream() 227 .sorted(Map.Entry.comparingByValue()) 228 .limit(5) 229 .map(Map.Entry::getKey) 230 .toList(); 231 List<Hotels> hotelsWithoutReservations = hotels.stream().filter(x -> !hotelsWithReservations.contains(x)).toList(); 232 List<Hotels> hotelsToBeMarketed = new ArrayList<>(); 233 hotelsToBeMarketed.addAll(hotelsWithoutReservations); 234 hotelsToBeMarketed.addAll(leastReservedHotels); 206 235 List<HotelRoomAvailable> roomsAvailible = hotelDao.getRoomsAvailibilityByDateAndLocation(hotelLocation, dateFrom, dateTo, numberOfBeds, flexible); 207 236 Map<Hotels, List<HotelRoomAvailable>> roomsByHotels = roomsAvailible.stream().collect(Collectors.groupingBy(x -> x.getHotelRoom().getHotel())); … … 220 249 getReviewsForHotel(x.getHotelId()), 221 250 getReviewsForHotel(x.getHotelId()).stream().mapToDouble(Reviews::getNumStar).average().orElse(0), 222 getHotelImages(x.getHotelId()) 251 getHotelImages(x.getHotelId()), 252 mostReservedHotels.contains(x), 253 hotelsToBeMarketed.contains(x) 223 254 )).toList(); 224 255 return hotelsList; … … 227 258 228 259 @Override 260 // TODO:Transactional 229 261 public void createReservation(Long userId, Long hotelRoomId, Long hotelRoomAvailableId, Date dateFrom, Date dateTo, Integer numberOfBeds) { 230 262 HotelRoom room = hotelDao.findRoomById(hotelRoomId); … … 246 278 hotelDao.editReservation(hr); 247 279 } 280 248 281 249 282 @Override -
src/main/java/com/tourMate/services/impl/RestaurantManagerImpl.java
r07f4e8b r0f5aa27 89 89 90 90 @Override 91 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date hourFrom, Date hourTo, int noSeats) { 92 List<RestaurantsAvailible> restaurantsAvailibles = restaurantDao.getTablesByDateAndLocation(restaurantLocation, hourFrom, hourTo, noSeats); 91 public List<RestaurantDto> getTablesByDateAndLocation(String restaurantLocation, Date date, String hourFrom, String hourTo, int noSeats) { 92 Date dateFrom = date; 93 Date dateTo = Date.from(date.toInstant()); 94 String[] splittedFrom = hourFrom.split(":"); 95 String[] splittedTo = hourTo.split(":"); 96 dateFrom.setHours(Integer.parseInt(splittedFrom[0])); 97 dateFrom.setMinutes(Integer.parseInt(splittedFrom[1])); 98 dateTo.setHours(Integer.parseInt(splittedTo[0])); 99 dateTo.setMinutes(Integer.parseInt(splittedTo[1])); 100 List<RestaurantsAvailible> restaurantsAvailibles = restaurantDao.getTablesByDateAndLocation(restaurantLocation, dateFrom, dateTo, noSeats); 93 101 Map<Restaurant, List<RestaurantsAvailible>> tablesByRestaurants = restaurantsAvailibles.stream().collect(Collectors.groupingBy(x -> x.getRestaurantTable().getRestaurant())); 94 102 List<RestaurantDto> restaurantsList = tablesByRestaurants.keySet().stream() -
src/main/java/com/tourMate/services/impl/TransportManagerImpl.java
r07f4e8b r0f5aa27 46 46 public List<TransportDto> getTransportsByUser(long userId) { 47 47 User u = usersManager.findUserByID(userId); 48 return transportDao.getTransportsByUser(u); 48 List<Transport> transports = transportDao.getTransportsByUser(u); 49 return transports.stream().map(x -> new TransportDto( 50 x.getTransportID(), 51 x.getTransportName(), 52 x.getCarBrand(), 53 x.getCarType(), 54 x.getCarManufacturedYear(), 55 x.getNoPassengers(), 56 x.getNoBags(), 57 x.getEMBG(), 58 x.getOwner(), 59 x.getCarPlate(), 60 x.getAvailableRoutes().stream().map(y -> new RouteListingDto( 61 y.getTransportAvailibleId(), 62 y.getFrom(), 63 y.getTo(), 64 y.getDate(), 65 y.getFreeSpace(), 66 y.getTime(), 67 y.getRoutes(), 68 y.getRoutes().stream() 69 .mapToDouble(TransportRoute::getPrice) 70 .max().orElse(0) 71 )).toList(), 72 x.getAvailableRoutes().stream() 73 .flatMapToDouble(y -> y.getRoutes() 74 .stream() 75 .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0) 76 )).toList(); 49 77 } 50 78 … … 52 80 public List<RouteListingDto> getRoutesForTransport(long transportId) { 53 81 Transport t = getTransportById(transportId); 54 return transportDao.getRoutesForTransport(t); 82 List<TransportAvailible> transportAvailibles = transportDao.getRoutesForTransport(t); 83 return transportAvailibles.stream().map(x -> new RouteListingDto( 84 x.getTransportAvailibleId(), 85 x.getFrom(), 86 x.getTo(), 87 x.getDate(), 88 x.getFreeSpace(), 89 x.getTime(), 90 x.getRoutes(), 91 x.getRoutes().stream() 92 .mapToDouble(TransportRoute::getPrice) 93 .max().orElse(0) 94 )).toList(); 55 95 } 56 96 57 97 @Override 58 98 public TransportDto findTransportById(long transportId) { 59 return transportDao.findTransportById(transportId); 99 Transport x = transportDao.findTransportById(transportId); 100 return new TransportDto( 101 x.getTransportID(), 102 x.getTransportName(), 103 x.getCarBrand(), 104 x.getCarType(), 105 x.getCarManufacturedYear(), 106 x.getNoPassengers(), 107 x.getNoBags(), 108 x.getEMBG(), 109 x.getOwner(), 110 x.getCarPlate(), 111 x.getAvailableRoutes().stream().map(y -> new RouteListingDto( 112 y.getTransportAvailibleId(), 113 y.getFrom(), 114 y.getTo(), 115 y.getDate(), 116 y.getFreeSpace(), 117 y.getTime(), 118 y.getRoutes(), 119 y.getRoutes().stream() 120 .mapToDouble(TransportRoute::getPrice) 121 .max().orElse(0) 122 )).toList(), 123 x.getAvailableRoutes().stream() 124 .flatMapToDouble(y -> y.getRoutes() 125 .stream() 126 .mapToDouble(TransportRoute::getPrice)).max().orElseGet(() -> 0)); 60 127 } 61 128 … … 152 219 153 220 @Override 154 public void createTransportAvailable(Transport transport, String departureLocation, String arrivalLocation, Date date, Integer noSeats, Date departureHour, Collection<TransportRoute> routes) { 155 TransportAvailible ta=new TransportAvailible(transport,departureLocation,arrivalLocation,date,noSeats,departureHour); 221 public void createTransportAvailable(TransportAvailible transportAvailible, Transport transport, String departureLocation, String arrivalLocation, Date date, Integer noSeats, Date departureHour, Long transportId, Collection<TransportRoute> trRoutes) { 222 Transport t = getTransportById(transportId); 223 List<TransportRoute> routes = trRoutes.stream().toList(); 224 routes.get(0).setDeparture(transportAvailible.getDate()); 225 transportAvailible.setTime(routes.get(routes.size() - 1).getArrival()); 226 routes.forEach(x -> x.setParentRoute(transportAvailible)); 227 transportAvailible.setTransport(t); 228 TransportAvailible ta=new TransportAvailible(t,departureLocation,arrivalLocation,date,noSeats,departureHour); 156 229 transportDao.createTransportAvailable(ta); 157 230 routes.forEach(x -> { -
src/main/java/com/tourMate/services/impl/UsersManagerImpl.java
r07f4e8b r0f5aa27 2 2 3 3 import com.tourMate.dao.UsersDao; 4 import com.tourMate.dto.PrincipalInfo; 4 5 import com.tourMate.entities.User; 6 import com.tourMate.events.OnProfileEnabledEvent; 5 7 import com.tourMate.services.UsersManager; 6 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.context.ApplicationEventPublisher; 7 10 import org.springframework.security.core.userdetails.UserDetails; 8 11 import org.springframework.security.core.userdetails.UserDetailsService; 9 12 import org.springframework.security.core.userdetails.UsernameNotFoundException; 13 import org.springframework.security.crypto.password.PasswordEncoder; 10 14 import org.springframework.stereotype.Service; 11 15 … … 18 22 @Autowired 19 23 UsersDao usersDao; 20 24 @Autowired 25 ApplicationEventPublisher eventPublisher; 26 @Autowired 27 PasswordEncoder passwordEncoder; 21 28 @Override 22 29 public void createUser(String name, String surname, String email, Date birthDate, String address, String contact) { … … 64 71 65 72 @Override 73 public List<User> getAdmins() { 74 return usersDao.getAdmins(); 75 } 76 77 @Override 78 public void connectAccount(Long id, String username, String password) { 79 User u1 = findUserByID(id); 80 User u2 = (User) loadUserByUsername(username); 81 if(passwordEncoder.matches(password, u2.getPassword())) 82 { 83 u1.addConnectedUser(u2); 84 } 85 usersDao.updateUser(u1); 86 } 87 88 @Override 89 public List<User> findConnectedAccountsByUser(Long id) { 90 User u = findUserByID(id); 91 return usersDao.findConnectedAccountsByUser(u); 92 } 93 94 @Override 95 public PrincipalInfo getPrincipalInfo(Long userId) { 96 PrincipalInfo principalInfo = new PrincipalInfo(); 97 User u = findUserByID(userId); 98 principalInfo.setUsername(u.getUsername()); 99 principalInfo.setRole(u.getRole().getRoleName()); 100 principalInfo.setId(userId); 101 principalInfo.setName(u.getName()); 102 principalInfo.setEmail(u.getEmail()); 103 principalInfo.setSurname(u.getSurname()); 104 return principalInfo; 105 } 106 107 @Override 66 108 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 67 109 return usersDao.findUserByUsername(username); -
src/main/resources/application.properties
r07f4e8b r0f5aa27 14 14 spring.datasource.hikari.maximumPoolSize=5 15 15 16 17 16 18 spring.jpa.generate-ddl=true 17 19 logging.level.org.springframework.security=DEBUG 18 20 19 21 22 spring.security.oauth2.client.registration.github.client-id=f84a0839a98bf3b25d38 23 spring.security.oauth2.client.registration.github.client-secret=e22be1f60e10517c8906bde54529280e57ff21f3 24 25 spring.security.oauth2.client.registration.google.client-id=122292211431-p18l1falsh51nevvm2sg85rjp0psqsn4.apps.googleusercontent.com 26 spring.security.oauth2.client.registration.google.client-secret=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 27 spring.security.oauth2.client.registration.google.scope=profile,email 28 29 spring.security.oauth2.client.registration.facebook.client-id=904891684514537 30 spring.security.oauth2.client.registration.facebook.client-secret=f69fe635933dd32c12b5786968f18b4c 31 #logging.level.org.springframework.security=DEBUG 32 logging.level.org.springframework.security.oauth2=DEBUG 33 34 35
Note:
See TracChangeset
for help on using the changeset viewer.