From ba430a5849030c3fd4581c6596c8947ecff160e0 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 3 Dec 2024 14:10:05 +0300 Subject: [PATCH] add a separate function to handle ConstructName --- internal/handlers/ussd/menuhandler.go | 13 +------------ internal/utils/name.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 internal/utils/name.go diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 6bc00ec..acd3dd4 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -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 diff --git a/internal/utils/name.go b/internal/utils/name.go new file mode 100644 index 0000000..4665d02 --- /dev/null +++ b/internal/utils/name.go @@ -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 +} \ No newline at end of file