Changeset b738035 for trip-planner/src


Ignore:
Timestamp:
01/24/22 21:08:32 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
76712b2
Parents:
bdd6491
Message:

signup/login server errors on front and remove location from planner

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  
    109109    List<Location> getVillages();
    110110
     111    @Query(value = "SELECT * FROM locations AS l WHERE l.id_city = :cityId", nativeQuery = true)
     112    List<Location> getLocationsForCity(@Param("cityId") Long cityId);
    111113}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaPlannerRepository.java

    rbdd6491 rb738035  
    1616        List<Planner> getPlannersByUser(@Param("username") String username );
    1717
    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);
    2024}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaUserRepository.java

    rbdd6491 rb738035  
    22
    33import finki.diplomska.tripplanner.models.User;
     4import org.springframework.data.jpa.repository.Query;
    45import org.springframework.data.repository.CrudRepository;
     6import org.springframework.data.repository.query.Param;
    57import org.springframework.stereotype.Repository;
     8
     9import java.util.List;
     10import java.util.Optional;
    611
    712@Repository
     
    914    User findByUsername(String username);
    1015    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
    1123}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java

    rbdd6491 rb738035  
    7878                .antMatchers("/api/weekend").permitAll()
    7979                .antMatchers("/api/villages").permitAll()
     80                .antMatchers("/api/cities").permitAll()
    8081                .anyRequest().authenticated();
    8182        http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    rbdd6491 rb738035  
    2525    List<Location> getVillages();
    2626    List<Long> getAllLocationIdsForPlanner(Long plannerId);
     27    List<Location> getLocationsForCity(Long cityId);
    2728}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/PlannerService.java

    rbdd6491 rb738035  
    44import finki.diplomska.tripplanner.models.Planner;
    55import finki.diplomska.tripplanner.models.dto.PlannerDto;
     6import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
     7import org.springframework.http.ResponseEntity;
    68
    79import java.util.List;
     
    1820        Optional<Planner> newPlanner(PlannerDto plannerDto, String username);
    1921        void deletePlannerById(Long id);
    20         void deleteLocationFromPlanner(Long locationId);
     22        ResponseEntity deleteLocationFromPlanner(PlannerLocationDto plannerLocationDto);
    2123}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/UserService.java

    rbdd6491 rb738035  
    44import finki.diplomska.tripplanner.models.dto.UserDto;
    55
     6import java.util.List;
    67import java.util.Optional;
    78
     
    1011
    1112    User saveUser (User user);
    12 
     13    List<String> getAllUsernames();
     14    Optional<String> getPassword(UserDto userDto);
     15    Optional<User> findById(Long id);
    1316}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    rbdd6491 rb738035  
    183183        return this.locationRepository.getAllLocationIdsForPlanner(plannerId);
    184184    }
     185
     186    @Override
     187    public List<Location> getLocationsForCity(Long cityId) {
     188        return this.locationRepository.getLocationsForCity(cityId);
     189    }
    185190}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java

    rbdd6491 rb738035  
    55import finki.diplomska.tripplanner.models.User;
    66import finki.diplomska.tripplanner.models.dto.PlannerDto;
     7import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    78import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException;
    89import finki.diplomska.tripplanner.models.exceptions.PlannerNotFoundException;
     
    1112import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository;
    1213import finki.diplomska.tripplanner.service.PlannerService;
     14import org.springframework.http.ResponseEntity;
    1315import org.springframework.stereotype.Service;
    1416
     
    6769
    6870    @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;
    7174    }
    7275
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/UserServiceImpl.java

    rbdd6491 rb738035  
    77import finki.diplomska.tripplanner.service.UserService;
    88import org.springframework.beans.factory.annotation.Autowired;
     9import org.springframework.http.ResponseEntity;
    910import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    1011import org.springframework.stereotype.Service;
    1112
     13import java.util.List;
    1214import java.util.Optional;
    1315
     
    3436            throw new UsernameAlreadyExistsException("Username '"+newUser.getUsername()+ "' already exists");
    3537        }
     38    }
    3639
     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);
    3754    }
    3855
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    rbdd6491 rb738035  
    4545
    4646    @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){
    5151        return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
    5252    }
    5353
    54     @PutMapping(value = "/add-location")
     54    @PostMapping(value = "/add-location")
    5555    public Location addLocationToPlanner(@RequestBody PlannerLocationDto plannerLocationDto){
    5656        return this.locationService.addLocationToPlanner(plannerLocationDto);
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java

    rbdd6491 rb738035  
    55import finki.diplomska.tripplanner.models.User;
    66import finki.diplomska.tripplanner.models.dto.PlannerDto;
     7import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    78import finki.diplomska.tripplanner.service.LocationService;
    89import finki.diplomska.tripplanner.service.PlannerService;
     
    9293    }
    9394
    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);
    10198    }
    10299}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/UserController.java

    rbdd6491 rb738035  
    1919import org.springframework.web.bind.annotation.*;
    2020import org.springframework.security.core.Authentication;
     21
    2122import javax.validation.Valid;
     23import java.util.List;
     24import java.util.Optional;
    2225
    2326@RestController
     
    5255                )
    5356        );
    54 
    5557        SecurityContextHolder.getContext().setAuthentication(authentication);
    5658        String jwt = SecurityConstants.TOKEN_PREFIX +  tokenProvider.generateToken(authentication);
    57 
    5859        return ResponseEntity.ok(new JWTLoginSucessReponse(true, jwt));
    5960    }
     
    6566        ResponseEntity<?> errorMap = mapValidationErrorService.MapValidationService(result);
    6667        if(errorMap != null)return errorMap;
     68        User newUser = userService.saveUser(user);
     69        return  new ResponseEntity<User>(newUser, HttpStatus.CREATED);
     70    }
    6771
    68         User newUser = userService.saveUser(user);
     72    @GetMapping(value = "/usernames")
     73    public List<String> getAllUsernames (){
     74        return this.userService.getAllUsernames();
     75    }
    6976
    70         return  new ResponseEntity<User>(newUser, HttpStatus.CREATED);
     77    @GetMapping(value = "/password")
     78    public Optional<String> getPassword(@RequestBody UserDto userDto){
    7179
     80        return this.userService.getPassword(userDto);
    7281    }
     82
    7383}
  • trip-planner/src/test/api.http

    rbdd6491 rb738035  
    9494
    9595###
    96 DELETE http://localhost:8080/api/delete/19
     96DELETE http://localhost:8080/api/delete-location
    9797Content-Type: application/json
     98
     99{"plannerId": 23, "locationId": 3}
     100
     101###
     102GET http://localhost:8080/api/users/usernames
     103Content-Type: application/json
     104
     105###
     106GET http://localhost:8080/api/users/password
     107Content-Type: application/json
     108
     109{"username": "ema@test.com"}
Note: See TracChangeset for help on using the changeset viewer.