gebz97 / mandulis-ticketing-system

GNU General Public License v3.0
9 stars 8 forks source link

API - ArcureDev's suggestions #35

Open gebz97 opened 2 months ago

gebz97 commented 2 months ago
  1. User service changes: // What I do in a Service class is that I put this annotation @Transactional(readOnly = true) so that every method can read data // By doing this, it reduce the number of annotations, but do as you think is best / readable for you // When I need to update data in a method, I add specifically @Transaction annotation to this method @Transactional(readOnly = true)
  2. UserMapper class
  3. @Transactional(readOnly = true) on readonly methods
  4. UserService change: // I think this can be done with one method, something like this "userRepository.existsByEmailOrUserName(request.getEmail(), request.getUserName())" if (userRepository.existsByEmail(request.getEmail()) || userRepository.existsByUsername(request.getUsername())) { throw new UserAlreadyExistsException(ErrorMessages.USER_ALREADY_EXISTS);
  5. updateUserById in UserService: Unhappy path first in the if-condition
  6. UserController changes: `// in this case, I would have done it this way because, most of the time, in front end, you won't care about if it's a 200 or a 201 // @PostMapping // public UserResponse createUser(@Valid @RequestBody CreateOrUpdateUserRequest request) { // return userService.saveUser(request); // }

    // if you want your URI to look like this '/api/v1/public/users/1', you only need "/{id}" // @GetMapping("{id}") @GetMapping("/id={id}") @GetMapping("/id={id}")`

  7. Changing ResponseEntity<?> to ResponseDto or List in all methods (This is a violent change)