KotlinIntermediate

Kotlin Null-Safety & Data Class Cleanup

NextCtrl+j
src/services/UserProfileService.kt
0.0s/ 38s0/ 42
1
package com.vimhero.account
2
3
data class UserProfile(
4
val id: String,
5
val email: String,
6
val displayName: String?,
7
val status: String = "PENDING_VERIFICATION",
8
val tier: String = "FREE"
9
)
10
11
class UserProfileService(
12
private val repository: ProfileRepository
13
) {
14
fun activateProfile(userId: String): UserProfile {
15
val existing = repository.findById(userId)
16
?: throw IllegalArgumentException("User not found")
17
println("DEBUG: activating profile for " + existing.email)
18
val resolvedName = existing.displayName ?: "Guest"
19
val updated = existing.copy(
20
displayName = resolvedName,
21
status = "ACTIVE"
22
)
23
return repository.save(updated)
24
}
25
26
fun normalizeTier(rawTier: String?): String {
27
// TODO: remove legacy tier fallback after migration
28
val cleaned = rawTier?.trim()?.uppercase()
29
return if (cleaned.isNullOrEmpty()) "FREE" else cleaned
30
}
31
}
-L7 val status: String = "PENDING_VERIFICATION",
+L7 val status: String = "ACTIVE",
-L17 println("DEBUG: activating profile for " + existing.email)
-L18 val resolvedName = existing.displayName ?: "Guest"
+L17 val resolvedName = existing.displayName ?: "Anonymous"
-L27 // TODO: remove legacy tier fallback after migration