Ignore:
Timestamp:
09/23/22 02:03:14 (22 months ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
895cd87
Parents:
436e0da
Message:

Implemented all use cases

Location:
phonelux-backend/src/main/java/finki/it/phoneluxbackend
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/UserController.java

    r436e0da r48f3030  
    3333    }
    3434
     35    @PutMapping(path = "/{userId}/editspecifications")
     36    public ResponseEntity<Object> editSpecificationsForUser(@PathVariable("userId") Long userId,
     37                                                            @RequestBody String specifications){
     38        return userService.editSpecificationsForUser(userId,specifications);
     39    }
     40
     41    @GetMapping(path = "/{userId}/getspecifications")
     42    public String getSpecificationsForUser(@PathVariable("userId") Long userId){
     43        return userService.getSpecificationsForUser(userId);
     44    }
     45
    3546}
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/User.java

    r436e0da r48f3030  
    6969    }
    7070
     71
    7172    public User(Long id, String firstName, String lastName, String email, UserRole userRole) {
    7273        this.id = id;
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java

    r436e0da r48f3030  
    5252                .withClaim("name", user.getFirstName())
    5353                .withClaim("id", user.getId())
     54//                .withClaim("pickedSpecifications",user.getSpecifications()!=null ?
     55//                        user.getSpecifications() : "[]")
    5456                .sign(algorithm);
    5557
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java

    r436e0da r48f3030  
    8585        String name = decodedJWT.getClaim("name").as(String.class);
    8686        Long id = decodedJWT.getClaim("id").as(Long.class);
    87 
     87//        String pickedSpecifications = decodedJWT.getClaim("pickedSpecifications").as(String.class);
    8888        return new User(id,name,role);
    8989    }
     
    175175        return ResponseEntity.ok().build();
    176176    }
     177
     178    public ResponseEntity<Object> editSpecificationsForUser(Long userId, String specifications) {
     179        boolean userExists = userRepository.existsById(userId);
     180        if (!userExists)
     181        {
     182            return ResponseEntity.badRequest().body("User with id "+userId+" doesn't exist");
     183        }
     184        User user = userRepository.findById(userId).get();
     185
     186        user.setSpecifications(specifications);
     187        userRepository.save(user);
     188
     189        return ResponseEntity.ok().build();
     190    }
     191
     192    public String getSpecificationsForUser(Long userId) {
     193        boolean userExists = userRepository.existsById(userId);
     194        if (!userExists)
     195        {
     196            throw new UsernameNotFoundException("User with id "+userId+" doesn't exist");
     197        }
     198
     199        User user = userRepository.findById(userId).get();
     200
     201        return user.getSpecifications() != null ? user.getSpecifications() : "[]";
     202    }
    177203}
Note: See TracChangeset for help on using the changeset viewer.