Conversation
Elena-Bruyako
left a comment
There was a problem hiding this comment.
Good job! Let's first fix comments in main code
Add readme file
pom.xml
Outdated
| <dependency> | ||
| <groupId>org.mapstruct</groupId> | ||
| <artifactId>mapstruct</artifactId> | ||
| <version>1.6.3</version> |
pom.xml
Outdated
| <dependency> | ||
| <groupId>org.mapstruct</groupId> | ||
| <artifactId>mapstruct-processor</artifactId> | ||
| <version>1.6.3</version> |
pom.xml
Outdated
| <path> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.18.30</version> |
| description = "Register a new user with email, password and other details") | ||
| @PostMapping("/registration") | ||
| public UserResponseDto registration( | ||
| @RequestBody UserRegistrationRequestDto userRegistrationRequestDto) |
There was a problem hiding this comment.
| @RequestBody UserRegistrationRequestDto userRegistrationRequestDto) | |
| @RequestBody @Valid UserRegistrationRequestDto userRegistrationRequestDto) |
| @Operation(summary = "Login user", | ||
| description = "Authenticate user and return JWT token") | ||
| @PostMapping("/login") | ||
| public UserLoginResponseDto login(@RequestBody UserLoginRequestDto userLoginRequestDto) { |
There was a problem hiding this comment.
| public UserLoginResponseDto login(@RequestBody UserLoginRequestDto userLoginRequestDto) { | |
| public UserLoginResponseDto login(@RequestBody @Valid UserLoginRequestDto userLoginRequestDto) { |
| @Column(name = "first_name", nullable = false) | ||
| private String firstName; | ||
|
|
||
| @Column(name = "last_name", nullable = false) |
There was a problem hiding this comment.
| @Column(name = "first_name", nullable = false) | |
| private String firstName; | |
| @Column(name = "last_name", nullable = false) | |
| @Column(nullable = false) | |
| private String firstName; | |
| @Column(nullable = false) |
| public Page<PaymentResponseDto> getWithUserId(Pageable pageable, Long userId) { | ||
| return paymentRepository.findAllByRental_UserId(pageable, userId) | ||
| .map(paymentMapper::toDto); | ||
|
|
There was a problem hiding this comment.
remove redundant empty line
| public Page<PaymentResponseDto> getWithUserId(Pageable pageable, Long userId) { | |
| return paymentRepository.findAllByRental_UserId(pageable, userId) | |
| .map(paymentMapper::toDto); | |
| public Page<PaymentResponseDto> getWithUserId(Pageable pageable, Long userId) { | |
| return paymentRepository.findAllByRental_UserId(pageable, userId) | |
| .map(paymentMapper::toDto); |
| payment.setSessionId("none"); | ||
| payment.setSessionUrl("http://none.none"); | ||
|
|
||
| payment = paymentRepository.save(payment); |
There was a problem hiding this comment.
| payment = paymentRepository.save(payment); | |
| paymentRepository.save(payment); |
| "Can't find payment by id: " + paymentId)); | ||
|
|
||
| if (payment.getStatus() == Payment.Status.PAID) { | ||
| return; |
| user.setPassword(passwordEncoder.encode(userRegistrationRequestDto.getPassword())); | ||
|
|
||
| Role defaultRole = roleRepository.findByName(Role.RoleName.CUSTOMER) | ||
| .orElseThrow(() -> new EntityNotFoundException("Default role not found")); |
liliia-ponomarenko
left a comment
There was a problem hiding this comment.
Good job! A few comments ;) Also, you can improve test coverage
| import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
|
||
| @ControllerAdvice | ||
| public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler { |
There was a problem hiding this comment.
Let’s handle all your custom exception
|
|
||
| private int inventory; | ||
|
|
||
| @Column(name = "daily_fee", nullable = false) |
There was a problem hiding this comment.
| @Column(name = "daily_fee", nullable = false) | |
| @Column(nullable = false) |
| payment.setSessionId("none"); | ||
| payment.setSessionUrl("http://none.none"); |
There was a problem hiding this comment.
Why do you hardcode these values?
| Payment payment = new Payment(); | ||
| payment.setRental(rental); | ||
| payment.setType(type); | ||
| payment.setStatus(Payment.Status.PENDING); | ||
| payment.setAmountToPay(amountToPay); | ||
| payment.setSessionId("none"); | ||
| payment.setSessionUrl("http://none.none"); |
There was a problem hiding this comment.
Move this logic to the private method and simplify it. a good method should have less than 20 lines
| } | ||
|
|
||
| @Override | ||
| @Transactional |
There was a problem hiding this comment.
move 'transaction above class
| } | ||
| } | ||
|
|
||
| private Long calculateExpirationTime() { |
There was a problem hiding this comment.
move private method after public
|
|
||
| @ExceptionHandler(RegistrationException.class) | ||
| public ResponseEntity<Object> handleRegistrationException(RegistrationException ex) { | ||
| return buildResponse(HttpStatus.BAD_REQUEST, ex.getMessage()); |
There was a problem hiding this comment.
| return buildResponse(HttpStatus.BAD_REQUEST, ex.getMessage()); | |
| return buildResponse(HttpStatus.CONFLICT, ex.getMessage()); |
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface UserRepository extends JpaRepository<User, Long> { | ||
| Boolean existsByEmail(String email); |
There was a problem hiding this comment.
| Boolean existsByEmail(String email); | |
| boolean existsByEmail(String email); |
| public UserResponseDto register(UserRegistrationRequestDto userRegistrationRequestDto) | ||
| throws RegistrationException { | ||
| if (userRepository.existsByEmail(userRegistrationRequestDto.getEmail())) { | ||
| throw new RegistrationException("Can't registration user " |
There was a problem hiding this comment.
| throw new RegistrationException("Can't registration user " | |
| throw new RegistrationException("Can't register user " |
No description provided.