Skip to content

Commit

Permalink
This code change removes a significant chunk of commented-out code fr…
Browse files Browse the repository at this point in the history
…om the `SignupService.kt` file, specifically an alternative implementation of the `validate` function and two functions related to account activation and expiry. Let's analyze the implications.

**Removed Code:**

* **Alternative `validate` function:** This older version of validation used a bean-based validator and iterated through specific user attributes (password, email, login).  It constructed a set of validation error messages based on constraint violations.
* **`accountByActivationKey` function:** This function likely retrieved an account based on its activation key, suggesting a previous implementation of account activation.
* **`deleteExpired` function:**  This suggests a mechanism for deleting expired accounts, likely related to the activation process or other time-sensitive account statuses.

**Impact:**

* **Reduced Code Clutter:** Removing the commented-out code improves readability and maintainability by eliminating obsolete code that might confuse developers.
* **Simplified Validation:** The remaining `validate` function (using `exchange.validator`) is presumably the preferred and actively used method.  Removing the alternative simplifies the codebase and reduces potential confusion.
* **Feature Removal (Potential):**  The removal of the activation and expiry functions suggests that these features may have been removed from the application entirely. If these features are still required, their removal constitutes a bug.  If they're no longer needed, removing the associated code is a good cleanup practice.

**Considerations:**

* **Testing:** Ensure that the remaining `validate` function covers all necessary validation scenarios previously handled by the removed code.
* **Documentation:**  If the account activation and expiry features were intentionally removed, update any related documentation accordingly.
* **Future Development:** If the removed functionality might be needed in the future, consider archiving the code snippet in a separate location rather than deleting it entirely.

By removing this dead code, the `SignupService` class becomes more focused and easier to understand, which is generally a positive change. However, it's crucial to ensure that the removed code doesn't represent a regression in functionality.
  • Loading branch information
cheroliv committed Nov 17, 2024
1 parent 6e8e41c commit 9ff242f
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions api/src/main/kotlin/school/users/signup/SignupService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SignupService(private val context: ApplicationContext) {

@JvmStatic
val SIGNUP_LOGIN_AND_EMAIL_NOT_AVAILABLE = Triple(false, false, false)

fun Signup.validate(
exchange: ServerWebExchange
): Set<Map<String, String?>> = exchange.validator.run {
Expand Down Expand Up @@ -120,27 +121,6 @@ class SignupService(private val context: ApplicationContext) {
ex.left()
}

// fun validate(signup: Signup): Set<Map<String, String?>> = context.getBean<Validator>().let {
// setOf(
// User.UserDao.Attributes.PASSWORD_ATTR,
// User.UserDao.Attributes.EMAIL_ATTR,
// User.UserDao.Attributes.LOGIN_ATTR,
// ).map { field -> field to it.validateProperty(signup, field) }
// .flatMap { violatedField: Pair<String, MutableSet<ConstraintViolation<Signup>>> ->
// violatedField.second.map {
// mapOf<String, String?>(
// MODEL_FIELD_OBJECTNAME to objectName,
// MODEL_FIELD_FIELD to violatedField.first,
// MODEL_FIELD_MESSAGE to it.message
// )
// }
// }.toSet()
// }

// @Transactional(readOnly = true)
// suspend fun accountByActivationKey(key: String) = accountRepository.findOneByActivationKey(key)
// @Transactional
// suspend fun deleteExpired(account: Account) = accountRepository.delete(account)
}


Expand Down

0 comments on commit 9ff242f

Please sign in to comment.