add a separate function to handle ConstructName

This commit is contained in:
Alfred Kamanda 2024-12-03 14:10:05 +03:00
parent 0f21b01813
commit ba430a5849
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
2 changed files with 18 additions and 12 deletions

View File

@ -1398,18 +1398,7 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte)
offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS))
// Construct the full name
name := defaultValue
if familyName != defaultValue {
if firstName != defaultValue {
name = firstName + " " + familyName
} else {
name = familyName
}
} else {
if firstName != defaultValue {
name = firstName
}
}
name := utils.ConstructName(firstName, familyName, defaultValue)
// Calculate age from year of birth
age := defaultValue

17
internal/utils/name.go Normal file
View File

@ -0,0 +1,17 @@
package utils
func ConstructName(firstName, familyName, defaultValue string) string {
name := defaultValue
if familyName != defaultValue {
if firstName != defaultValue {
name = firstName + " " + familyName
} else {
name = familyName
}
} else {
if firstName != defaultValue {
name = firstName
}
}
return name
}