From 8d309be8aefde5daa5dad02dcf33dec1a505923b Mon Sep 17 00:00:00 2001 From: Carlos Ponton Date: Mon, 26 Aug 2024 13:32:22 +0200 Subject: [PATCH] refactor: apply necessary code refactoring to pass the checkStyle --- .../backend/config/EmailConfiguration.java | 8 +++++++- .../java/com/greenfoxacademy/backend/models/User.java | 1 - .../backend/services/mail/EmailService.java | 2 +- .../backend/services/mail/EmailServiceImpl.java | 3 +++ .../backend/services/user/UserServiceImpl.java | 3 +-- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/greenfoxacademy/backend/config/EmailConfiguration.java b/backend/src/main/java/com/greenfoxacademy/backend/config/EmailConfiguration.java index 06f29d53..05684137 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/config/EmailConfiguration.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/config/EmailConfiguration.java @@ -5,7 +5,13 @@ import org.springframework.context.annotation.Configuration; /** - * This configuration is to setup the email sending services. + * Configuration class for managing email-related settings. + *

+ * This class is used to load email-related properties from the application's configuration files, + * such as the base URL used for email verification links. + * It leverages Spring's {@link Configuration} + * and {@link Value} annotations to inject configuration properties into the class. + *

*/ @Configuration @Getter diff --git a/backend/src/main/java/com/greenfoxacademy/backend/models/User.java b/backend/src/main/java/com/greenfoxacademy/backend/models/User.java index 355a7dc9..2d40c708 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/models/User.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/models/User.java @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.List; import java.util.UUID; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailService.java b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailService.java index 8e501ad1..9d242641 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailService.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailService.java @@ -5,7 +5,7 @@ import java.util.UUID; /** - * Service to handle emails. + * An interface for a service that handles sending emails. */ public interface EmailService { EmailSentDto sendRegistrationEmail( diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java index fb84a29b..48b59fc7 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java @@ -14,6 +14,9 @@ /** * EmailServiceImplementation to handle emails. + * Implementation of the {@link EmailService} interface for sending registration emails. + * This service uses Spring's {@link JavaMailSender} to create and send emails + * with a registration verification link. */ @Service @RequiredArgsConstructor 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 a7b46158..9a1c5602 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 @@ -14,7 +14,6 @@ import com.greenfoxacademy.backend.services.mail.EmailService; import jakarta.transaction.Transactional; import java.util.UUID; -import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -80,7 +79,7 @@ public ProfileUpdateResponseDto profileUpdate( .orElseThrow(() -> new UsernameNotFoundException("User not found")); if ( userRepository.existsByEmail(profileUpdateRequestDto.email()) - && !Objects.equals(email, profileUpdateRequestDto.email()) + && !email.equals(profileUpdateRequestDto.email()) ) { throw new CannotUpdateUserException("Email is already taken!"); }