Changeset b738035 for trip-planner
- Timestamp:
- 01/24/22 21:08:32 (3 years ago)
- Branches:
- master
- Children:
- 76712b2
- Parents:
- bdd6491
- Location:
- trip-planner/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java
rbdd6491 rb738035 109 109 List<Location> getVillages(); 110 110 111 @Query(value = "SELECT * FROM locations AS l WHERE l.id_city = :cityId", nativeQuery = true) 112 List<Location> getLocationsForCity(@Param("cityId") Long cityId); 111 113 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaPlannerRepository.java
rbdd6491 rb738035 16 16 List<Planner> getPlannersByUser(@Param("username") String username ); 17 17 18 @Query(value = "delete from planners_contain WHERE planners_contain.id_location = :locationId", nativeQuery = true) 19 void deleteLocationFromPlanner(@Param("locationId") Long locationId); 18 @Query(value = "DELETE planners_contain " + 19 "FROM planners_contain " + 20 "JOIN planners ON planners_contain.id_planner = planners.id_planner " + 21 "JOIN locations ON planners_contain.id_location = locations.id_location " + 22 "WHERE planners_contain.id_planner = :plannerId AND planners_contain.id_location = :locationId", nativeQuery = true) 23 void deleteLocationFromPlanner(@Param("plannerId") Long plannerId, @Param("locationId") Long locationId); 20 24 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaUserRepository.java
rbdd6491 rb738035 2 2 3 3 import finki.diplomska.tripplanner.models.User; 4 import org.springframework.data.jpa.repository.Query; 4 5 import org.springframework.data.repository.CrudRepository; 6 import org.springframework.data.repository.query.Param; 5 7 import org.springframework.stereotype.Repository; 8 9 import java.util.List; 10 import java.util.Optional; 6 11 7 12 @Repository … … 9 14 User findByUsername(String username); 10 15 User getById(Long id); 16 17 @Query(value = "SELECT u.username FROM users AS u", nativeQuery = true) 18 List<String> getAllUsernames(); 19 20 @Query(value = "SELECT u.password FROM users AS u WHERE u.username LIKE :username ", nativeQuery = true) 21 Optional<String> getPassword(@Param("username") String username); 22 11 23 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java
rbdd6491 rb738035 78 78 .antMatchers("/api/weekend").permitAll() 79 79 .antMatchers("/api/villages").permitAll() 80 .antMatchers("/api/cities").permitAll() 80 81 .anyRequest().authenticated(); 81 82 http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java
rbdd6491 rb738035 25 25 List<Location> getVillages(); 26 26 List<Long> getAllLocationIdsForPlanner(Long plannerId); 27 List<Location> getLocationsForCity(Long cityId); 27 28 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/PlannerService.java
rbdd6491 rb738035 4 4 import finki.diplomska.tripplanner.models.Planner; 5 5 import finki.diplomska.tripplanner.models.dto.PlannerDto; 6 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 7 import org.springframework.http.ResponseEntity; 6 8 7 9 import java.util.List; … … 18 20 Optional<Planner> newPlanner(PlannerDto plannerDto, String username); 19 21 void deletePlannerById(Long id); 20 void deleteLocationFromPlanner(Long locationId);22 ResponseEntity deleteLocationFromPlanner(PlannerLocationDto plannerLocationDto); 21 23 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/UserService.java
rbdd6491 rb738035 4 4 import finki.diplomska.tripplanner.models.dto.UserDto; 5 5 6 import java.util.List; 6 7 import java.util.Optional; 7 8 … … 10 11 11 12 User saveUser (User user); 12 13 List<String> getAllUsernames(); 14 Optional<String> getPassword(UserDto userDto); 15 Optional<User> findById(Long id); 13 16 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java
rbdd6491 rb738035 183 183 return this.locationRepository.getAllLocationIdsForPlanner(plannerId); 184 184 } 185 186 @Override 187 public List<Location> getLocationsForCity(Long cityId) { 188 return this.locationRepository.getLocationsForCity(cityId); 189 } 185 190 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java
rbdd6491 rb738035 5 5 import finki.diplomska.tripplanner.models.User; 6 6 import finki.diplomska.tripplanner.models.dto.PlannerDto; 7 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 7 8 import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException; 8 9 import finki.diplomska.tripplanner.models.exceptions.PlannerNotFoundException; … … 11 12 import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository; 12 13 import finki.diplomska.tripplanner.service.PlannerService; 14 import org.springframework.http.ResponseEntity; 13 15 import org.springframework.stereotype.Service; 14 16 … … 67 69 68 70 @Override 69 public void deleteLocationFromPlanner(Long locationId) { 70 this.plannerRepository.deleteLocationFromPlanner(locationId); 71 public ResponseEntity deleteLocationFromPlanner(PlannerLocationDto plannerLocationDto) { 72 plannerRepository.deleteLocationFromPlanner(plannerLocationDto.getPlannerId(), plannerLocationDto.getLocationId()); 73 return null; 71 74 } 72 75 -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/UserServiceImpl.java
rbdd6491 rb738035 7 7 import finki.diplomska.tripplanner.service.UserService; 8 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.http.ResponseEntity; 9 10 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 11 import org.springframework.stereotype.Service; 11 12 13 import java.util.List; 12 14 import java.util.Optional; 13 15 … … 34 36 throw new UsernameAlreadyExistsException("Username '"+newUser.getUsername()+ "' already exists"); 35 37 } 38 } 36 39 40 @Override 41 public List<String> getAllUsernames() { 42 return this.userRepository.getAllUsernames(); 43 } 44 45 @Override 46 public Optional<String> getPassword(UserDto userDto) { 47 this.userRepository.getPassword(userDto.getUsername()); 48 return null; 49 } 50 51 @Override 52 public Optional<User> findById(Long id) { 53 return this.userRepository.findById(id); 37 54 } 38 55 -
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java
rbdd6491 rb738035 45 45 46 46 @GetMapping(value = "/region/locations") 47 public List<Location> getAllLocationsFromRegion(@RequestParam (required = false)Long regionId,48 @RequestParam (required = false)Long companionId,49 @RequestParam (required = false)Long lengthOfStay,50 @RequestParam (required = false)String categoryIds){47 public List<Location> getAllLocationsFromRegion(@RequestParam Long regionId, 48 @RequestParam Long companionId, 49 @RequestParam Long lengthOfStay, 50 @RequestParam String categoryIds){ 51 51 return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds); 52 52 } 53 53 54 @P utMapping(value = "/add-location")54 @PostMapping(value = "/add-location") 55 55 public Location addLocationToPlanner(@RequestBody PlannerLocationDto plannerLocationDto){ 56 56 return this.locationService.addLocationToPlanner(plannerLocationDto); -
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java
rbdd6491 rb738035 5 5 import finki.diplomska.tripplanner.models.User; 6 6 import finki.diplomska.tripplanner.models.dto.PlannerDto; 7 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 7 8 import finki.diplomska.tripplanner.service.LocationService; 8 9 import finki.diplomska.tripplanner.service.PlannerService; … … 92 93 } 93 94 94 95 @DeleteMapping(value = "/delete-from-planner") 96 public ResponseEntity deleteLocationFromPlanner(@PathVariable Long locationId){ 97 this.plannerService.deleteLocationFromPlanner(locationId); 98 return this.locationService.findById(locationId) 99 .map(location -> ResponseEntity.ok().body(location)) 100 .orElseGet(()-> ResponseEntity.notFound().build()); 95 @DeleteMapping(value = "/delete-location") 96 public ResponseEntity deleteLocationFromPlanner(@RequestBody PlannerLocationDto plannerLocationDto){ 97 return this.plannerService.deleteLocationFromPlanner(plannerLocationDto); 101 98 } 102 99 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/UserController.java
rbdd6491 rb738035 19 19 import org.springframework.web.bind.annotation.*; 20 20 import org.springframework.security.core.Authentication; 21 21 22 import javax.validation.Valid; 23 import java.util.List; 24 import java.util.Optional; 22 25 23 26 @RestController … … 52 55 ) 53 56 ); 54 55 57 SecurityContextHolder.getContext().setAuthentication(authentication); 56 58 String jwt = SecurityConstants.TOKEN_PREFIX + tokenProvider.generateToken(authentication); 57 58 59 return ResponseEntity.ok(new JWTLoginSucessReponse(true, jwt)); 59 60 } … … 65 66 ResponseEntity<?> errorMap = mapValidationErrorService.MapValidationService(result); 66 67 if(errorMap != null)return errorMap; 68 User newUser = userService.saveUser(user); 69 return new ResponseEntity<User>(newUser, HttpStatus.CREATED); 70 } 67 71 68 User newUser = userService.saveUser(user); 72 @GetMapping(value = "/usernames") 73 public List<String> getAllUsernames (){ 74 return this.userService.getAllUsernames(); 75 } 69 76 70 return new ResponseEntity<User>(newUser, HttpStatus.CREATED); 77 @GetMapping(value = "/password") 78 public Optional<String> getPassword(@RequestBody UserDto userDto){ 71 79 80 return this.userService.getPassword(userDto); 72 81 } 82 73 83 } -
trip-planner/src/test/api.http
rbdd6491 rb738035 94 94 95 95 ### 96 DELETE http://localhost:8080/api/delete /1996 DELETE http://localhost:8080/api/delete-location 97 97 Content-Type: application/json 98 99 {"plannerId": 23, "locationId": 3} 100 101 ### 102 GET http://localhost:8080/api/users/usernames 103 Content-Type: application/json 104 105 ### 106 GET http://localhost:8080/api/users/password 107 Content-Type: application/json 108 109 {"username": "ema@test.com"}
Note:
See TracChangeset
for help on using the changeset viewer.