diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserService.java b/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserService.java index 17e0b974..9f0064ad 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserService.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserService.java @@ -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; } diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserServiceImpl.java b/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserServiceImpl.java index 46f42a79..3328ce5c 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserServiceImpl.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/user/UserServiceImpl.java @@ -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) { @@ -40,7 +48,8 @@ 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"); } @@ -48,8 +57,12 @@ public LoginResponseDto login(LoginRequestDto loginRequestDto) throws Exception } @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!"); } @@ -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!")); } } \ No newline at end of file diff --git a/backend/src/test/java/com/greenfoxacademy/backend/config/JwtConfigTest.java b/backend/src/test/java/com/greenfoxacademy/backend/config/JwtConfigTest.java index b9e159bf..18185b33 100644 --- a/backend/src/test/java/com/greenfoxacademy/backend/config/JwtConfigTest.java +++ b/backend/src/test/java/com/greenfoxacademy/backend/config/JwtConfigTest.java @@ -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()); + } } \ No newline at end of file diff --git a/backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java b/backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java index bf8c93d8..006430d2 100644 --- a/backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java +++ b/backend/src/test/java/com/greenfoxacademy/backend/services/user/UserServiceImplTest.java @@ -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; @@ -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; -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;