From 308f3327d065b50d60257046438474078d98fa3b Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 6 Nov 2024 17:48:50 +0300 Subject: [PATCH 01/16] use edit prefix on each profile edit information --- services/registration/edit_familyname_menu | 1 - services/registration/edit_familyname_menu_swa | 1 - services/registration/edit_name_menu | 1 - services/registration/edit_name_menu_swa | 1 - services/registration/enter_familyname | 1 - services/registration/enter_familyname.vis | 8 -------- services/registration/enter_familyname_swa | 1 - services/registration/enter_location | 1 - services/registration/enter_location.vis | 8 -------- services/registration/enter_location_swa | 1 - services/registration/enter_name | 1 - services/registration/enter_name.vis | 8 -------- services/registration/enter_name_swa | 1 - services/registration/enter_offerings | 1 - services/registration/enter_offerings.vis | 8 -------- services/registration/enter_offerings_swa | 1 - services/registration/enter_yob | 1 - services/registration/enter_yob.vis | 10 ---------- services/registration/enter_yob_swa | 1 - 19 files changed, 56 deletions(-) delete mode 100644 services/registration/edit_familyname_menu delete mode 100644 services/registration/edit_familyname_menu_swa delete mode 100644 services/registration/edit_name_menu delete mode 100644 services/registration/edit_name_menu_swa delete mode 100644 services/registration/enter_familyname delete mode 100644 services/registration/enter_familyname.vis delete mode 100644 services/registration/enter_familyname_swa delete mode 100644 services/registration/enter_location delete mode 100644 services/registration/enter_location.vis delete mode 100644 services/registration/enter_location_swa delete mode 100644 services/registration/enter_name delete mode 100644 services/registration/enter_name.vis delete mode 100644 services/registration/enter_name_swa delete mode 100644 services/registration/enter_offerings delete mode 100644 services/registration/enter_offerings.vis delete mode 100644 services/registration/enter_offerings_swa delete mode 100644 services/registration/enter_yob delete mode 100644 services/registration/enter_yob.vis delete mode 100644 services/registration/enter_yob_swa diff --git a/services/registration/edit_familyname_menu b/services/registration/edit_familyname_menu deleted file mode 100644 index 21a9033..0000000 --- a/services/registration/edit_familyname_menu +++ /dev/null @@ -1 +0,0 @@ -Edit family name \ No newline at end of file diff --git a/services/registration/edit_familyname_menu_swa b/services/registration/edit_familyname_menu_swa deleted file mode 100644 index 48a38b2..0000000 --- a/services/registration/edit_familyname_menu_swa +++ /dev/null @@ -1 +0,0 @@ -Weka jina la familia \ No newline at end of file diff --git a/services/registration/edit_name_menu b/services/registration/edit_name_menu deleted file mode 100644 index c7383b7..0000000 --- a/services/registration/edit_name_menu +++ /dev/null @@ -1 +0,0 @@ -Edit name \ No newline at end of file diff --git a/services/registration/edit_name_menu_swa b/services/registration/edit_name_menu_swa deleted file mode 100644 index 9395f7c..0000000 --- a/services/registration/edit_name_menu_swa +++ /dev/null @@ -1 +0,0 @@ -Weka jina \ No newline at end of file diff --git a/services/registration/enter_familyname b/services/registration/enter_familyname deleted file mode 100644 index 889915a..0000000 --- a/services/registration/enter_familyname +++ /dev/null @@ -1 +0,0 @@ -Enter family name: \ No newline at end of file diff --git a/services/registration/enter_familyname.vis b/services/registration/enter_familyname.vis deleted file mode 100644 index 5db4c17..0000000 --- a/services/registration/enter_familyname.vis +++ /dev/null @@ -1,8 +0,0 @@ -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH update_familyname flag_allow_update 1 -MOUT back 0 -HALT -LOAD save_familyname 0 -RELOAD save_familyname -INCMP _ 0 -INCMP pin_entry * diff --git a/services/registration/enter_familyname_swa b/services/registration/enter_familyname_swa deleted file mode 100644 index 82f64cd..0000000 --- a/services/registration/enter_familyname_swa +++ /dev/null @@ -1 +0,0 @@ -Weka jina la familia diff --git a/services/registration/enter_location b/services/registration/enter_location deleted file mode 100644 index 675b835..0000000 --- a/services/registration/enter_location +++ /dev/null @@ -1 +0,0 @@ -Enter your location: \ No newline at end of file diff --git a/services/registration/enter_location.vis b/services/registration/enter_location.vis deleted file mode 100644 index 8966872..0000000 --- a/services/registration/enter_location.vis +++ /dev/null @@ -1,8 +0,0 @@ -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH update_location flag_allow_update 1 -MOUT back 0 -HALT -LOAD save_location 0 -RELOAD save_location -INCMP _ 0 -INCMP pin_entry * diff --git a/services/registration/enter_location_swa b/services/registration/enter_location_swa deleted file mode 100644 index 41682a2..0000000 --- a/services/registration/enter_location_swa +++ /dev/null @@ -1 +0,0 @@ -Weka eneo: \ No newline at end of file diff --git a/services/registration/enter_name b/services/registration/enter_name deleted file mode 100644 index c6851cf..0000000 --- a/services/registration/enter_name +++ /dev/null @@ -1 +0,0 @@ -Enter your first names: \ No newline at end of file diff --git a/services/registration/enter_name.vis b/services/registration/enter_name.vis deleted file mode 100644 index f853d0a..0000000 --- a/services/registration/enter_name.vis +++ /dev/null @@ -1,8 +0,0 @@ -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH update_firstname flag_allow_update 1 -MOUT back 0 -HALT -LOAD save_firstname 0 -RELOAD save_firstname -INCMP _ 0 -INCMP pin_entry * diff --git a/services/registration/enter_name_swa b/services/registration/enter_name_swa deleted file mode 100644 index b600b90..0000000 --- a/services/registration/enter_name_swa +++ /dev/null @@ -1 +0,0 @@ -Weka majina yako ya kwanza: \ No newline at end of file diff --git a/services/registration/enter_offerings b/services/registration/enter_offerings deleted file mode 100644 index a9333ba..0000000 --- a/services/registration/enter_offerings +++ /dev/null @@ -1 +0,0 @@ -Enter the services or goods you offer: \ No newline at end of file diff --git a/services/registration/enter_offerings.vis b/services/registration/enter_offerings.vis deleted file mode 100644 index 5cc7977..0000000 --- a/services/registration/enter_offerings.vis +++ /dev/null @@ -1,8 +0,0 @@ -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH update_offerings flag_allow_update 1 -LOAD save_offerings 0 -MOUT back 0 -HALT -RELOAD save_offerings -INCMP _ 0 -INCMP pin_entry * diff --git a/services/registration/enter_offerings_swa b/services/registration/enter_offerings_swa deleted file mode 100644 index f37e125..0000000 --- a/services/registration/enter_offerings_swa +++ /dev/null @@ -1 +0,0 @@ -Weka unachouza \ No newline at end of file diff --git a/services/registration/enter_yob b/services/registration/enter_yob deleted file mode 100644 index 54e039e..0000000 --- a/services/registration/enter_yob +++ /dev/null @@ -1 +0,0 @@ -Enter your year of birth \ No newline at end of file diff --git a/services/registration/enter_yob.vis b/services/registration/enter_yob.vis deleted file mode 100644 index c74aeed..0000000 --- a/services/registration/enter_yob.vis +++ /dev/null @@ -1,10 +0,0 @@ -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH update_yob flag_allow_update 1 -MOUT back 0 -HALT -LOAD verify_yob 0 -CATCH incorrect_date_format flag_incorrect_date_format 1 -LOAD save_yob 0 -RELOAD save_yob -INCMP _ 0 -INCMP pin_entry * diff --git a/services/registration/enter_yob_swa b/services/registration/enter_yob_swa deleted file mode 100644 index 9bb272a..0000000 --- a/services/registration/enter_yob_swa +++ /dev/null @@ -1 +0,0 @@ -Weka mwaka wa kuzaliwa \ No newline at end of file -- 2.45.2 From 29e1e912d79f2bdedb4be556570740f145fb6149 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 6 Nov 2024 17:52:22 +0300 Subject: [PATCH 02/16] use edit prefix on each profile edit node --- services/registration/edit_first_name.vis | 11 +++++++++++ services/registration/edit_first_name_menu_swa | 1 + services/registration/edit_location | 1 + services/registration/edit_location.vis | 10 ++++++++++ services/registration/edit_location_swa | 1 + services/registration/edit_offerings | 1 + services/registration/edit_offerings.vis | 10 ++++++++++ services/registration/edit_offerings_swa | 1 + services/registration/edit_profile.vis | 14 +++++++------- services/registration/edit_yob | 1 + services/registration/edit_yob.vis | 12 ++++++++++++ services/registration/edit_yob_swa | 1 + 12 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 services/registration/edit_first_name.vis create mode 100644 services/registration/edit_first_name_menu_swa create mode 100644 services/registration/edit_location create mode 100644 services/registration/edit_location.vis create mode 100644 services/registration/edit_location_swa create mode 100644 services/registration/edit_offerings create mode 100644 services/registration/edit_offerings.vis create mode 100644 services/registration/edit_offerings_swa create mode 100644 services/registration/edit_yob create mode 100644 services/registration/edit_yob.vis create mode 100644 services/registration/edit_yob_swa diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis new file mode 100644 index 0000000..b8dab5a --- /dev/null +++ b/services/registration/edit_first_name.vis @@ -0,0 +1,11 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH update_firstname flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info +MAP get_current_profile_info +MOUT back 0 +HALT +LOAD save_firstname 0 +RELOAD save_firstname +INCMP _ 0 +INCMP pin_entry * diff --git a/services/registration/edit_first_name_menu_swa b/services/registration/edit_first_name_menu_swa new file mode 100644 index 0000000..9395f7c --- /dev/null +++ b/services/registration/edit_first_name_menu_swa @@ -0,0 +1 @@ +Weka jina \ No newline at end of file diff --git a/services/registration/edit_location b/services/registration/edit_location new file mode 100644 index 0000000..675b835 --- /dev/null +++ b/services/registration/edit_location @@ -0,0 +1 @@ +Enter your location: \ No newline at end of file diff --git a/services/registration/edit_location.vis b/services/registration/edit_location.vis new file mode 100644 index 0000000..eaf248a --- /dev/null +++ b/services/registration/edit_location.vis @@ -0,0 +1,10 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH update_location flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info +MOUT back 0 +HALT +LOAD save_location 0 +RELOAD save_location +INCMP _ 0 +INCMP pin_entry * diff --git a/services/registration/edit_location_swa b/services/registration/edit_location_swa new file mode 100644 index 0000000..41682a2 --- /dev/null +++ b/services/registration/edit_location_swa @@ -0,0 +1 @@ +Weka eneo: \ No newline at end of file diff --git a/services/registration/edit_offerings b/services/registration/edit_offerings new file mode 100644 index 0000000..a9333ba --- /dev/null +++ b/services/registration/edit_offerings @@ -0,0 +1 @@ +Enter the services or goods you offer: \ No newline at end of file diff --git a/services/registration/edit_offerings.vis b/services/registration/edit_offerings.vis new file mode 100644 index 0000000..dad3193 --- /dev/null +++ b/services/registration/edit_offerings.vis @@ -0,0 +1,10 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH update_offerings flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info +LOAD save_offerings 0 +MOUT back 0 +HALT +RELOAD save_offerings +INCMP _ 0 +INCMP pin_entry * diff --git a/services/registration/edit_offerings_swa b/services/registration/edit_offerings_swa new file mode 100644 index 0000000..f37e125 --- /dev/null +++ b/services/registration/edit_offerings_swa @@ -0,0 +1 @@ +Weka unachouza \ No newline at end of file diff --git a/services/registration/edit_profile.vis b/services/registration/edit_profile.vis index 277f330..af20e0f 100644 --- a/services/registration/edit_profile.vis +++ b/services/registration/edit_profile.vis @@ -2,8 +2,8 @@ LOAD reset_account_authorized 16 RELOAD reset_account_authorized LOAD reset_allow_update 0 RELOAD reset_allow_update -MOUT edit_name 1 -MOUT edit_familyname 2 +MOUT edit_first_name 1 +MOUT edit_family_name 2 MOUT edit_gender 3 MOUT edit_yob 4 MOUT edit_location 5 @@ -12,10 +12,10 @@ MOUT view 7 MOUT back 0 HALT INCMP my_account 0 -INCMP enter_name 1 -INCMP enter_familyname 2 +INCMP edit_first_name 1 +INCMP edit_family_name 2 INCMP select_gender 3 -INCMP enter_yob 4 -INCMP enter_location 5 -INCMP enter_offerings 6 +INCMP edit_yob 4 +INCMP edit_location 5 +INCMP edit_offerings 6 INCMP view_profile 7 diff --git a/services/registration/edit_yob b/services/registration/edit_yob new file mode 100644 index 0000000..54e039e --- /dev/null +++ b/services/registration/edit_yob @@ -0,0 +1 @@ +Enter your year of birth \ No newline at end of file diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis new file mode 100644 index 0000000..3cb7bd0 --- /dev/null +++ b/services/registration/edit_yob.vis @@ -0,0 +1,12 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH update_yob flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info +MOUT back 0 +HALT +LOAD verify_yob 0 +CATCH incorrect_date_format flag_incorrect_date_format 1 +LOAD save_yob 0 +RELOAD save_yob +INCMP _ 0 +INCMP pin_entry * diff --git a/services/registration/edit_yob_swa b/services/registration/edit_yob_swa new file mode 100644 index 0000000..9bb272a --- /dev/null +++ b/services/registration/edit_yob_swa @@ -0,0 +1 @@ +Weka mwaka wa kuzaliwa \ No newline at end of file -- 2.45.2 From ebdc7b200a572a6fef4ce9cbf13467554bf82dec Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 09:16:49 +0300 Subject: [PATCH 03/16] register handler for getting current profile information --- internal/handlers/handlerservice.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 7d8325c..7a1e912 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -115,6 +115,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn ls.DbRs.AddLocalFunc("reset_unregistered_number", ussdHandlers.ResetUnregisteredNumber) ls.DbRs.AddLocalFunc("reset_others_pin", ussdHandlers.ResetOthersPin) ls.DbRs.AddLocalFunc("save_others_temporary_pin", ussdHandlers.SaveOthersTemporaryPin) + ls.DbRs.AddLocalFunc("get_current_profile_info", ussdHandlers.GetCurrentProfileInfo) return ussdHandlers, nil } -- 2.45.2 From f66609bbaeb5a31e3574bcbcb0796e1cc7fabde2 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 09:18:11 +0300 Subject: [PATCH 04/16] add helper for getting db key from string --- common/db.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/db.go b/common/db.go index 1992476..e90fd47 100644 --- a/common/db.go +++ b/common/db.go @@ -2,6 +2,7 @@ package common import ( "encoding/binary" + "errors" "git.defalsify.org/vise.git/logging" ) @@ -48,3 +49,23 @@ func PackKey(typ DataTyp, data []byte) []byte { v := typToBytes(typ) return append(v, data...) } + +func StringToDataTyp(str string) (DataTyp, error) { + switch str { + case "DATA_FIRST_NAME": + return DATA_FIRST_NAME, nil + case "DATA_FAMILY_NAME": + return DATA_FAMILY_NAME, nil + case "DATA_YOB": + return DATA_YOB, nil + case "DATA_LOCATION": + return DATA_LOCATION, nil + case "DATA_GENDER": + return DATA_GENDER, nil + case "DATA_OFFERINGS": + return DATA_OFFERINGS, nil + + default: + return 0, errors.New("invalid DataTyp string") + } +} -- 2.45.2 From 3e258a35fa851a2c84fe9d4bfd998a94e7c8b2a7 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 11:58:25 +0300 Subject: [PATCH 05/16] show currently set profile information --- services/registration/edit_family_name | 2 ++ services/registration/edit_family_name.vis | 10 ++++++++++ services/registration/edit_family_name_menu | 1 + services/registration/edit_family_name_menu_swa | 1 + services/registration/edit_family_name_swa | 2 ++ services/registration/edit_first_name | 2 ++ services/registration/edit_first_name_menu | 1 + services/registration/edit_first_name_swa | 2 ++ services/registration/edit_location | 1 + services/registration/edit_location_swa | 1 + services/registration/edit_offerings | 1 + services/registration/edit_offerings_swa | 1 + services/registration/edit_yob | 1 + services/registration/edit_yob.vis | 1 + services/registration/edit_yob_swa | 1 + services/registration/select_gender | 1 + services/registration/select_gender.vis | 6 ++---- 17 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 services/registration/edit_family_name create mode 100644 services/registration/edit_family_name.vis create mode 100644 services/registration/edit_family_name_menu create mode 100644 services/registration/edit_family_name_menu_swa create mode 100644 services/registration/edit_family_name_swa create mode 100644 services/registration/edit_first_name create mode 100644 services/registration/edit_first_name_menu create mode 100644 services/registration/edit_first_name_swa diff --git a/services/registration/edit_family_name b/services/registration/edit_family_name new file mode 100644 index 0000000..2170a7e --- /dev/null +++ b/services/registration/edit_family_name @@ -0,0 +1,2 @@ +Current familyname: {{.get_current_profile_info}} +Enter family name: \ No newline at end of file diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis new file mode 100644 index 0000000..1d71939 --- /dev/null +++ b/services/registration/edit_family_name.vis @@ -0,0 +1,10 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH update_familyname flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info +MOUT back 0 +HALT +LOAD save_familyname 0 +RELOAD save_familyname +INCMP _ 0 +INCMP pin_entry * diff --git a/services/registration/edit_family_name_menu b/services/registration/edit_family_name_menu new file mode 100644 index 0000000..21a9033 --- /dev/null +++ b/services/registration/edit_family_name_menu @@ -0,0 +1 @@ +Edit family name \ No newline at end of file diff --git a/services/registration/edit_family_name_menu_swa b/services/registration/edit_family_name_menu_swa new file mode 100644 index 0000000..48a38b2 --- /dev/null +++ b/services/registration/edit_family_name_menu_swa @@ -0,0 +1 @@ +Weka jina la familia \ No newline at end of file diff --git a/services/registration/edit_family_name_swa b/services/registration/edit_family_name_swa new file mode 100644 index 0000000..a1a1cab --- /dev/null +++ b/services/registration/edit_family_name_swa @@ -0,0 +1,2 @@ +Jina la familia la sasa: {{.get_current_profile_info}} +Weka jina la familia \ No newline at end of file diff --git a/services/registration/edit_first_name b/services/registration/edit_first_name new file mode 100644 index 0000000..3d141ee --- /dev/null +++ b/services/registration/edit_first_name @@ -0,0 +1,2 @@ +Current name: {{.get_current_profile_info}} +Enter your first names: \ No newline at end of file diff --git a/services/registration/edit_first_name_menu b/services/registration/edit_first_name_menu new file mode 100644 index 0000000..c7383b7 --- /dev/null +++ b/services/registration/edit_first_name_menu @@ -0,0 +1 @@ +Edit name \ No newline at end of file diff --git a/services/registration/edit_first_name_swa b/services/registration/edit_first_name_swa new file mode 100644 index 0000000..3fdd986 --- /dev/null +++ b/services/registration/edit_first_name_swa @@ -0,0 +1,2 @@ +Jina la kwanza la sasa {{.get_current_profile_info}} +Weka majina yako ya kwanza: \ No newline at end of file diff --git a/services/registration/edit_location b/services/registration/edit_location index 675b835..4e11d1a 100644 --- a/services/registration/edit_location +++ b/services/registration/edit_location @@ -1 +1,2 @@ +Current location: {{.get_current_profile_info}} Enter your location: \ No newline at end of file diff --git a/services/registration/edit_location_swa b/services/registration/edit_location_swa index 41682a2..0a3476e 100644 --- a/services/registration/edit_location_swa +++ b/services/registration/edit_location_swa @@ -1 +1,2 @@ +Eneo la sasa {{.get_current_profile_info}} Weka eneo: \ No newline at end of file diff --git a/services/registration/edit_offerings b/services/registration/edit_offerings index a9333ba..5bb0e7f 100644 --- a/services/registration/edit_offerings +++ b/services/registration/edit_offerings @@ -1 +1,2 @@ +Current offerings: {{.get_current_profile_info}} Enter the services or goods you offer: \ No newline at end of file diff --git a/services/registration/edit_offerings_swa b/services/registration/edit_offerings_swa index f37e125..cd81497 100644 --- a/services/registration/edit_offerings_swa +++ b/services/registration/edit_offerings_swa @@ -1 +1,2 @@ +Unachouza kwa sasa: {{.get_current_profile_info}} Weka unachouza \ No newline at end of file diff --git a/services/registration/edit_yob b/services/registration/edit_yob index 54e039e..105812b 100644 --- a/services/registration/edit_yob +++ b/services/registration/edit_yob @@ -1 +1,2 @@ +Current year of birth: {{.get_current_profile_info}} Enter your year of birth \ No newline at end of file diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis index 3cb7bd0..a260531 100644 --- a/services/registration/edit_yob.vis +++ b/services/registration/edit_yob.vis @@ -2,6 +2,7 @@ CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_yob flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info +MAP get_current_profile_info MOUT back 0 HALT LOAD verify_yob 0 diff --git a/services/registration/edit_yob_swa b/services/registration/edit_yob_swa index 9bb272a..e0b5708 100644 --- a/services/registration/edit_yob_swa +++ b/services/registration/edit_yob_swa @@ -1 +1,2 @@ +Mwaka wa sasa wa kuzaliwa {{.get_current_profile_info}} Weka mwaka wa kuzaliwa \ No newline at end of file diff --git a/services/registration/select_gender b/services/registration/select_gender index f8a6f47..22b9be9 100644 --- a/services/registration/select_gender +++ b/services/registration/select_gender @@ -1 +1,2 @@ +Current gender: {{.get_current_profile_info}} Select gender: \ No newline at end of file diff --git a/services/registration/select_gender.vis b/services/registration/select_gender.vis index 1082cef..c1a00f5 100644 --- a/services/registration/select_gender.vis +++ b/services/registration/select_gender.vis @@ -1,5 +1,7 @@ CATCH incorrect_pin flag_incorrect_pin 1 CATCH profile_update_success flag_allow_update 1 +LOAD get_current_profile_info 0 +RELOAD get_current_profile_info MOUT male 1 MOUT female 2 MOUT unspecified 3 @@ -9,7 +11,3 @@ INCMP _ 0 INCMP set_male 1 INCMP set_female 2 INCMP set_unspecified 3 - - - - -- 2.45.2 From 4e170b25e23fa396d9317e9aebdd64ea23593b2d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 11:58:58 +0300 Subject: [PATCH 06/16] show currently set profile information --- services/registration/select_gender_swa | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/select_gender_swa b/services/registration/select_gender_swa index 2b3a748..b077a0b 100644 --- a/services/registration/select_gender_swa +++ b/services/registration/select_gender_swa @@ -1 +1,2 @@ +Jinsia ya sasa {{.get_current_profile_info}} Chagua jinsia \ No newline at end of file -- 2.45.2 From f3388aef31a122420aee22934c182f1b6c4b0302 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 11:59:12 +0300 Subject: [PATCH 07/16] use _ for back --- services/registration/incorrect_date_format.vis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/incorrect_date_format.vis b/services/registration/incorrect_date_format.vis index e94db5d..f4a8a2b 100644 --- a/services/registration/incorrect_date_format.vis +++ b/services/registration/incorrect_date_format.vis @@ -2,5 +2,5 @@ LOAD reset_incorrect_date_format 8 MOUT retry 1 MOUT quit 9 HALT -INCMP enter_yob 1 +INCMP _ 1 INCMP quit 9 -- 2.45.2 From cc36ddcb6de9eeaec9ffb530e972658b533b5818 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 12:02:03 +0300 Subject: [PATCH 08/16] add handler for showing the currently set profile information --- internal/handlers/ussd/menuhandler.go | 89 +++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index ca4af09..db710d2 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1153,6 +1153,95 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input [] return res, nil } +func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + var profileInfo []byte + var err error + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + sm, _ := h.st.Where() + parts := strings.SplitN(sm, "_", 2) + filename := parts[1] + dbKeyStr := "DATA_" + strings.ToUpper(filename) + dbKey, err := common.StringToDataTyp(dbKeyStr) + + if err != nil { + return res, err + } + store := h.userdataStore + + switch dbKey { + case common.DATA_FIRST_NAME: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + case common.DATA_FAMILY_NAME: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + + case common.DATA_GENDER: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + case common.DATA_YOB: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + + case common.DATA_LOCATION: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + case common.DATA_OFFERINGS: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) + if err != nil { + if db.IsNotFound(err) { + res.Content = "-" + break + } + return res, err + } + res.Content = string(profileInfo) + default: + break + } + + return res, nil +} + func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result var defaultValue string -- 2.45.2 From fc8915ea33a1dee0b0e3c4afc7cfa58dfee414e5 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 16:35:58 +0300 Subject: [PATCH 09/16] add http logging --- remote/accountservice.go | 44 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/remote/accountservice.go b/remote/accountservice.go index 2e19de1..92fd9df 100644 --- a/remote/accountservice.go +++ b/remote/accountservice.go @@ -1,20 +1,26 @@ package remote import ( + "bytes" "context" "encoding/json" "errors" "io" + "log" "net/http" "net/url" + "os" - dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" - "github.com/grassrootseconomics/eth-custodial/pkg/api" "git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/models" + "github.com/grassrootseconomics/eth-custodial/pkg/api" + dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) var ( + DebugLogger = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile) + InfoLogger = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime) + ErrorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) ) type AccountServiceInterface interface { @@ -51,7 +57,7 @@ func (as *AccountService) TrackAccountStatus(ctx context.Context, publicKey stri return nil, err } - _, err = doCustodialRequest(ctx, req, &r) + _, err = doCustodialRequest(ctx, req, &r) if err != nil { return nil, err } @@ -79,7 +85,6 @@ func (as *AccountService) CheckBalance(ctx context.Context, publicKey string) (* return &balanceResult, err } - // CreateAccount creates a new account in the custodial system. // Returns: // - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account. @@ -94,7 +99,7 @@ func (as *AccountService) CreateAccount(ctx context.Context) (*models.AccountRes return nil, err } - _, err = doCustodialRequest(ctx, req, &r) + _, err = doCustodialRequest(ctx, req, &r) if err != nil { return nil, err } @@ -118,7 +123,7 @@ func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) ( return nil, err } - _, err = doDataRequest(ctx, req, r) + _, err = doDataRequest(ctx, req, r) if err != nil { return nil, err } @@ -126,7 +131,6 @@ func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) ( return r, nil } - // FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint // Parameters: // - publicKey: The public key associated with the account. @@ -143,7 +147,7 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin return nil, err } - _, err = doDataRequest(ctx, req, r) + _, err = doDataRequest(ctx, req, r) if err != nil { return nil, err } @@ -151,7 +155,6 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin return r, nil } - // VoucherData retrieves voucher metadata from the data indexer API endpoint. // Parameters: // - address: The voucher address. @@ -173,7 +176,7 @@ func (as *AccountService) VoucherData(ctx context.Context, address string) (*mod } func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { - var okResponse api.OKResponse + var okResponse api.OKResponse var errResponse api.ErrResponse req.Header.Set("Content-Type", "application/json") @@ -184,6 +187,7 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons } defer resp.Body.Close() + InfoLogger.Printf("Received response for %s: Status Code: %d | Content-Type: %s", req.URL, resp.StatusCode, resp.Header.Get("Content-Type")) body, err := io.ReadAll(resp.Body) if err != nil { return nil, err @@ -214,10 +218,30 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { req.Header.Set("X-GE-KEY", config.CustodialAPIKey) + logRequestDetails(req, config.CustodialAPIKey) return doRequest(ctx, req, rcpt) } func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { req.Header.Set("X-GE-KEY", config.DataAPIKey) + logRequestDetails(req, config.CustodialAPIKey) return doRequest(ctx, req, rcpt) } + +func logRequestDetails(req *http.Request, apiKey string) { + var bodyBytes []byte + contentType := req.Header.Get("Content-Type") + if req.Body != nil { + bodyBytes, err := io.ReadAll(req.Body) + if err != nil { + ErrorLogger.Printf("Error reading request body: %s", err) + return + } + req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + } else { + bodyBytes = []byte("-") + } + + InfoLogger.Printf("URL: %s | Content-Type: %s | Method: %s| Request Body: %s", req.URL, contentType, req.Method, string(bodyBytes)) + +} -- 2.45.2 From f4f95b32926cc6c1407505c33964902c16cfb6ee Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 8 Nov 2024 17:15:27 +0300 Subject: [PATCH 10/16] add some spacing --- services/registration/edit_family_name | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/edit_family_name b/services/registration/edit_family_name index 2170a7e..1d637be 100644 --- a/services/registration/edit_family_name +++ b/services/registration/edit_family_name @@ -1,2 +1,2 @@ -Current familyname: {{.get_current_profile_info}} +Current family name: {{.get_current_profile_info}} Enter family name: \ No newline at end of file -- 2.45.2 From 68d162854614e9ae8b111f0a5d9bc440172b74f5 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 8 Nov 2024 17:19:41 +0300 Subject: [PATCH 11/16] replace - with: Not provided --- internal/handlers/ussd/menuhandler.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index db710d2..d59b1e9 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1177,7 +1177,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err @@ -1187,7 +1187,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err @@ -1198,7 +1198,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err @@ -1208,7 +1208,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err @@ -1219,7 +1219,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err @@ -1229,7 +1229,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) if err != nil { if db.IsNotFound(err) { - res.Content = "-" + res.Content = "Not provided" break } return res, err -- 2.45.2 From 9ebfb643aaa67d8379fb5051e688de9f47c94795 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 8 Nov 2024 17:28:20 +0300 Subject: [PATCH 12/16] remove unused import --- remote/accountservice.go | 1 - 1 file changed, 1 deletion(-) diff --git a/remote/accountservice.go b/remote/accountservice.go index 3a51e45..e6a5556 100644 --- a/remote/accountservice.go +++ b/remote/accountservice.go @@ -9,7 +9,6 @@ import ( "log" "net/http" "net/url" - "os" "git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/models" -- 2.45.2 From f97ad2a262ad326aeaf485787a490397013bbe64 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 14 Nov 2024 10:25:42 +0300 Subject: [PATCH 13/16] use 1 for retry --- services/registration/api_failure.vis | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/registration/api_failure.vis b/services/registration/api_failure.vis index e045355..78318f2 100644 --- a/services/registration/api_failure.vis +++ b/services/registration/api_failure.vis @@ -1,5 +1,6 @@ -MOUT retry 0 +MOUT retry 1 MOUT quit 9 HALT -INCMP _ 0 +INCMP _ 1 INCMP quit 9 + -- 2.45.2 From f9e51618c5eb598632f3283da00a2132b7b122ef Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 14 Nov 2024 10:29:22 +0300 Subject: [PATCH 14/16] remove extra line --- services/registration/api_failure.vis | 1 - 1 file changed, 1 deletion(-) diff --git a/services/registration/api_failure.vis b/services/registration/api_failure.vis index 78318f2..37b3deb 100644 --- a/services/registration/api_failure.vis +++ b/services/registration/api_failure.vis @@ -3,4 +3,3 @@ MOUT quit 9 HALT INCMP _ 1 INCMP quit 9 - -- 2.45.2 From 94d2e8203f9cb34c2451a320ac2514eb3469bfbe Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 14 Nov 2024 10:53:20 +0300 Subject: [PATCH 15/16] reload verify yob --- services/registration/edit_yob.vis | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis index a260531..6a5abe0 100644 --- a/services/registration/edit_yob.vis +++ b/services/registration/edit_yob.vis @@ -5,7 +5,8 @@ RELOAD get_current_profile_info MAP get_current_profile_info MOUT back 0 HALT -LOAD verify_yob 0 +LOAD verify_yob 6 +RELOAD verify_yob CATCH incorrect_date_format flag_incorrect_date_format 1 LOAD save_yob 0 RELOAD save_yob -- 2.45.2 From 381e581e8ef855852d6aa909248c1934189f7b72 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 14 Nov 2024 11:00:12 +0300 Subject: [PATCH 16/16] add terminal logs --- internal/handlers/ussd/menuhandler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 7d1db1e..31d0e30 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1217,6 +1217,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read first name entry with", "key", "error", common.DATA_FIRST_NAME, err) return res, err } res.Content = string(profileInfo) @@ -1227,6 +1228,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read family name entry with", "key", "error", common.DATA_FAMILY_NAME, err) return res, err } res.Content = string(profileInfo) @@ -1238,6 +1240,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read gender entry with", "key", "error", common.DATA_GENDER, err) return res, err } res.Content = string(profileInfo) @@ -1248,6 +1251,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read year of birth(yob) entry with", "key", "error", common.DATA_YOB, err) return res, err } res.Content = string(profileInfo) @@ -1259,6 +1263,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read location entry with", "key", "error", common.DATA_LOCATION, err) return res, err } res.Content = string(profileInfo) @@ -1269,6 +1274,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input res.Content = "Not provided" break } + logg.ErrorCtxf(ctx, "Failed to read offerings entry with", "key", "error", common.DATA_OFFERINGS, err) return res, err } res.Content = string(profileInfo) -- 2.45.2