Handle optional account name with "Anonymous" fallback

Make account name optional in API response and map nil/empty values to
"Anonymous" at the network boundary. This ensures users who haven't set
their name can remain anonymous while keeping the name non-optional in
domain and UI layers.

- Make AccountInformationResponse.Response.name optional (String?)
- Add mapping logic in AccountUpdateNetworkService to default nil/empty
  names to "Anonymous"
- Preserve non-optional String type in AccountResponse and
  Account models
- No changes required in UI or persistence layers
This commit is contained in:
Otavio Cordeiro 2025-12-17 11:21:09 +01:00 committed by Otávio
parent 9115e25017
commit 853a1e1e8b
2 changed files with 10 additions and 2 deletions

View file

@ -76,11 +76,19 @@ private extension AccountResponse {
/// Initializes the `AccountResponse` model from the network response /// Initializes the `AccountResponse` model from the network response
/// model, so that the client doesn't depend on network models. /// model, so that the client doesn't depend on network models.
///
/// If the name from the API response is `nil` or empty, it defaults to "Anonymous"
/// to ensure all layers of the application work with a non-optional name value.
///
/// - Parameter response: The network model to be mapped. /// - Parameter response: The network model to be mapped.
init( init(
response: AccountInformationResponse.Response response: AccountInformationResponse.Response
) { ) {
name = response.name if let responseName = response.name, !responseName.isEmpty {
name = responseName
} else {
name = "Anonymous"
}
email = response.email email = response.email
unixEpochTime = response.created.unixEpochTime unixEpochTime = response.created.unixEpochTime
} }

View file

@ -16,7 +16,7 @@ public extension AccountInformationResponse {
public let message: String public let message: String
public let email: String public let email: String
public let name: String public let name: String?
public let created: Created public let created: Created
} }
} }