Skip to content

Commit

Permalink
style: fix checkstyle errors ❤️
Browse files Browse the repository at this point in the history
  • Loading branch information
markkovari committed Aug 15, 2024
1 parent d135c08 commit c6c4040
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ public interface UserService extends UserDetailsService {

LoginResponseDto login(LoginRequestDto loginRequestDto) throws Exception;

ProfileUpdateResponseDto profileUpdate(String user, ProfileUpdateRequestDto profileUpdateRequestDto) throws Exception;
ProfileUpdateResponseDto profileUpdate(
String user,
ProfileUpdateRequestDto profileUpdateRequestDto
) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ public class UserServiceImpl implements UserService {
private final AuthService authService;

@Override
public RegisterResponseDto register(RegisterRequestDto registerRequestDto) throws UserAlreadyExistsError {
public RegisterResponseDto register(RegisterRequestDto registerRequestDto)
throws UserAlreadyExistsError {

User user = User.builder().email(registerRequestDto.email()).firstName(registerRequestDto.firstName()).lastName(registerRequestDto.lastName()).password(passwordEncoder.encode(registerRequestDto.password())).build();
// @formatter:off
User user = User.builder()
.email(registerRequestDto.email())
.firstName(registerRequestDto.firstName())
.lastName(registerRequestDto.lastName())
.password(passwordEncoder.encode(registerRequestDto.password()))
.build();
// @formatter:on
try {
return new RegisterResponseDto(userRepository.save(user).getId());
} catch (Exception e) {
Expand All @@ -40,16 +48,21 @@ public RegisterResponseDto register(RegisterRequestDto registerRequestDto) throw

@Override
public LoginResponseDto login(LoginRequestDto loginRequestDto) throws Exception {
User user = userRepository.findByEmail(loginRequestDto.email()).orElseThrow(() -> new Exception("User not found"));
User user = userRepository.findByEmail(loginRequestDto.email())
.orElseThrow(() -> new Exception("User not found"));
if (!passwordEncoder.matches(loginRequestDto.password(), user.getPassword())) {
throw new Exception("Invalid password");
}
return new LoginResponseDto(authService.generateToken(user));
}

@Override
public ProfileUpdateResponseDto profileUpdate(String email, ProfileUpdateRequestDto profileUpdateRequestDto) throws Exception {
User user = userRepository.findByEmail(email).orElseThrow(() -> new UsernameNotFoundException("User not found"));
public ProfileUpdateResponseDto profileUpdate(
String email,
ProfileUpdateRequestDto profileUpdateRequestDto
) {
User user = userRepository.findByEmail(email)
.orElseThrow(() -> new UsernameNotFoundException("User not found"));
if (userRepository.existsByEmail(profileUpdateRequestDto.email())) {
throw new UserAlreadyExistsError("Email is already taken!");
}
Expand All @@ -64,6 +77,7 @@ public ProfileUpdateResponseDto profileUpdate(String email, ProfileUpdateRequest

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return userRepository.findByEmail(username).orElseThrow(() -> new UsernameNotFoundException("No such user!"));
return userRepository.findByEmail(username)
.orElseThrow(() -> new UsernameNotFoundException("No such user!"));
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.greenfoxacademy.backend.config;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class JwtConfigTest {

@Autowired
private JwtConfig jwtConfig = new JwtConfig();
@Autowired
private JwtConfig jwtConfig = new JwtConfig();

@Test
void getExpirationTime() {
assertEquals(86400000, jwtConfig.getExpirationTime());
}
@Test
void getExpirationTime() {
assertEquals(86400000, jwtConfig.getExpirationTime());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.greenfoxacademy.backend.services.user;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import com.greenfoxacademy.backend.dtos.LoginRequestDto;
import com.greenfoxacademy.backend.dtos.ProfileUpdateRequestDto;
Expand All @@ -18,13 +21,8 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Optional;

Check warning on line 24 in backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Wrong lexicographical order for 'java.util.Optional' import. Should be before 'org.springframework.security.crypto.password.PasswordEncoder'. Raw Output: /github/workspace/./backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java:24:1: warning: Wrong lexicographical order for 'java.util.Optional' import. Should be before 'org.springframework.security.crypto.password.PasswordEncoder'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class UserServiceImplTest {
private UserServiceImpl userService;
Expand Down

0 comments on commit c6c4040

Please sign in to comment.