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") + } +} 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 } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 1836833..31d0e30 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1190,6 +1190,101 @@ 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 = "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) + case common.DATA_FAMILY_NAME: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) + if err != nil { + if db.IsNotFound(err) { + 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) + + case common.DATA_GENDER: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER) + if err != nil { + if db.IsNotFound(err) { + 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) + case common.DATA_YOB: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) + if err != nil { + if db.IsNotFound(err) { + 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) + + case common.DATA_LOCATION: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) + if err != nil { + if db.IsNotFound(err) { + 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) + case common.DATA_OFFERINGS: + profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) + if err != nil { + if db.IsNotFound(err) { + 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) + 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 diff --git a/services/registration/api_failure.vis b/services/registration/api_failure.vis index e045355..37b3deb 100644 --- a/services/registration/api_failure.vis +++ b/services/registration/api_failure.vis @@ -1,5 +1,5 @@ -MOUT retry 0 +MOUT retry 1 MOUT quit 9 HALT -INCMP _ 0 +INCMP _ 1 INCMP quit 9 diff --git a/services/registration/edit_family_name b/services/registration/edit_family_name new file mode 100644 index 0000000..1d637be --- /dev/null +++ b/services/registration/edit_family_name @@ -0,0 +1,2 @@ +Current family name: {{.get_current_profile_info}} +Enter family name: \ No newline at end of file diff --git a/services/registration/enter_familyname.vis b/services/registration/edit_family_name.vis similarity index 73% rename from services/registration/enter_familyname.vis rename to services/registration/edit_family_name.vis index 5db4c17..1d71939 100644 --- a/services/registration/enter_familyname.vis +++ b/services/registration/edit_family_name.vis @@ -1,5 +1,7 @@ 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 diff --git a/services/registration/edit_familyname_menu b/services/registration/edit_family_name_menu similarity index 100% rename from services/registration/edit_familyname_menu rename to services/registration/edit_family_name_menu diff --git a/services/registration/edit_familyname_menu_swa b/services/registration/edit_family_name_menu_swa similarity index 100% rename from services/registration/edit_familyname_menu_swa rename to services/registration/edit_family_name_menu_swa 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/enter_name.vis b/services/registration/edit_first_name.vis similarity index 65% rename from services/registration/enter_name.vis rename to services/registration/edit_first_name.vis index f853d0a..b8dab5a 100644 --- a/services/registration/enter_name.vis +++ b/services/registration/edit_first_name.vis @@ -1,5 +1,8 @@ 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 diff --git a/services/registration/edit_name_menu b/services/registration/edit_first_name_menu similarity index 100% rename from services/registration/edit_name_menu rename to services/registration/edit_first_name_menu diff --git a/services/registration/edit_name_menu_swa b/services/registration/edit_first_name_menu_swa similarity index 100% rename from services/registration/edit_name_menu_swa rename to services/registration/edit_first_name_menu_swa 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 new file mode 100644 index 0000000..4e11d1a --- /dev/null +++ b/services/registration/edit_location @@ -0,0 +1,2 @@ +Current location: {{.get_current_profile_info}} +Enter your location: \ No newline at end of file diff --git a/services/registration/enter_location.vis b/services/registration/edit_location.vis similarity index 72% rename from services/registration/enter_location.vis rename to services/registration/edit_location.vis index 8966872..eaf248a 100644 --- a/services/registration/enter_location.vis +++ b/services/registration/edit_location.vis @@ -1,5 +1,7 @@ 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 diff --git a/services/registration/edit_location_swa b/services/registration/edit_location_swa new file mode 100644 index 0000000..0a3476e --- /dev/null +++ b/services/registration/edit_location_swa @@ -0,0 +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 new file mode 100644 index 0000000..5bb0e7f --- /dev/null +++ b/services/registration/edit_offerings @@ -0,0 +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/enter_offerings.vis b/services/registration/edit_offerings.vis similarity index 72% rename from services/registration/enter_offerings.vis rename to services/registration/edit_offerings.vis index 5cc7977..dad3193 100644 --- a/services/registration/enter_offerings.vis +++ b/services/registration/edit_offerings.vis @@ -1,5 +1,7 @@ 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 diff --git a/services/registration/edit_offerings_swa b/services/registration/edit_offerings_swa new file mode 100644 index 0000000..cd81497 --- /dev/null +++ b/services/registration/edit_offerings_swa @@ -0,0 +1,2 @@ +Unachouza kwa sasa: {{.get_current_profile_info}} +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..105812b --- /dev/null +++ b/services/registration/edit_yob @@ -0,0 +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/enter_yob.vis b/services/registration/edit_yob.vis similarity index 62% rename from services/registration/enter_yob.vis rename to services/registration/edit_yob.vis index c74aeed..6a5abe0 100644 --- a/services/registration/enter_yob.vis +++ b/services/registration/edit_yob.vis @@ -1,8 +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 +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 diff --git a/services/registration/edit_yob_swa b/services/registration/edit_yob_swa new file mode 100644 index 0000000..e0b5708 --- /dev/null +++ b/services/registration/edit_yob_swa @@ -0,0 +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/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_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_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_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_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_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 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 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 - - - - 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