Merge branch 'master' into force-restart-state

This commit is contained in:
Alfred Kamanda 2024-12-31 05:06:26 +03:00
commit 8217ea8fdc
8 changed files with 34 additions and 21 deletions

View File

@ -1372,6 +1372,7 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
var profileInfo []byte var profileInfo []byte
var defaultValue string
var err error var err error
flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set") flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set")
@ -1388,7 +1389,18 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
if !ok { if !ok {
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
// Extract the field name from the state machine position. language, ok := ctx.Value("Language").(lang.Language)
if !ok {
return res, fmt.Errorf("value for 'Language' is not of type lang.Language")
}
code := language.Code
if code == "swa" {
defaultValue = "Haipo"
} else {
defaultValue = "Not Provided"
}
sm, _ := h.st.Where() sm, _ := h.st.Where()
parts := strings.SplitN(sm, "_", 2) parts := strings.SplitN(sm, "_", 2)
filename := parts[1] filename := parts[1]
@ -1405,7 +1417,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read first name entry with", "key", "error", common.DATA_FIRST_NAME, err) logg.ErrorCtxf(ctx, "Failed to read first name entry with", "key", "error", common.DATA_FIRST_NAME, err)
@ -1417,7 +1429,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read family name entry with", "key", "error", common.DATA_FAMILY_NAME, err) logg.ErrorCtxf(ctx, "Failed to read family name entry with", "key", "error", common.DATA_FAMILY_NAME, err)
@ -1430,7 +1442,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read gender entry with", "key", "error", common.DATA_GENDER, err) logg.ErrorCtxf(ctx, "Failed to read gender entry with", "key", "error", common.DATA_GENDER, err)
@ -1442,7 +1454,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read year of birth(yob) entry with", "key", "error", common.DATA_YOB, err) logg.ErrorCtxf(ctx, "Failed to read year of birth(yob) entry with", "key", "error", common.DATA_YOB, err)
@ -1454,7 +1466,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read location entry with", "key", "error", common.DATA_LOCATION, err) logg.ErrorCtxf(ctx, "Failed to read location entry with", "key", "error", common.DATA_LOCATION, err)
@ -1466,7 +1478,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = defaultValue
break break
} }
logg.ErrorCtxf(ctx, "Failed to read offerings entry with", "key", "error", common.DATA_OFFERINGS, err) logg.ErrorCtxf(ctx, "Failed to read offerings entry with", "key", "error", common.DATA_OFFERINGS, err)
@ -2020,15 +2032,16 @@ func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res
for index, profileItem := range h.profile.ProfileItems { for index, profileItem := range h.profile.ProfileItems {
// Ensure the profileItem is not "0"(is set) // Ensure the profileItem is not "0"(is set)
if profileItem != "0" { if profileItem != "0" {
err = store.WriteEntry(ctx, sessionId, profileDataKeys[index], []byte(profileItem))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write profile entry with", "key", profileDataKeys[index], "value", profileItem, "error", err)
return err
}
// Get the flag for the current index
flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) flag, _ := h.flagManager.GetFlag(profileFlagNames[index])
res.FlagSet = append(res.FlagSet, flag) isProfileItemSet := h.st.MatchFlag(flag, true)
if !isProfileItemSet {
err = store.WriteEntry(ctx, sessionId, profileDataKeys[index], []byte(profileItem))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write profile entry with", "key", profileDataKeys[index], "value", profileItem, "error", err)
return err
}
res.FlagSet = append(res.FlagSet, flag)
}
} }
} }
return nil return nil

View File

@ -430,7 +430,7 @@
}, },
{ {
"input": "1234", "input": "1234",
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 84\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back"
}, },
{ {
"input": "0", "input": "0",

View File

@ -1,2 +1,2 @@
Jina la kwanza la sasa {{.get_current_profile_info}} Jina la kwanza la sasa: {{.get_current_profile_info}}
Weka majina yako ya kwanza: Weka majina yako ya kwanza:

View File

@ -1,2 +1,2 @@
Eneo la sasa {{.get_current_profile_info}} Eneo la sasa: {{.get_current_profile_info}}
Weka eneo: Weka eneo:

View File

@ -10,5 +10,4 @@ CATCH _ flag_back_set 1
RELOAD save_offerings RELOAD save_offerings
INCMP _ 0 INCMP _ 0
CATCH pin_entry flag_offerings_set 1 CATCH pin_entry flag_offerings_set 1
CATCH pin_entry flag_offerings_set 0
INCMP update_profile_items * INCMP update_profile_items *

View File

@ -1,2 +1,2 @@
Mwaka wa sasa wa kuzaliwa {{.get_current_profile_info}} Mwaka wa sasa wa kuzaliwa: {{.get_current_profile_info}}
Weka mwaka wa kuzaliwa Weka mwaka wa kuzaliwa

View File

@ -11,3 +11,4 @@ INCMP _ 0
INCMP set_male 1 INCMP set_male 1
INCMP set_female 2 INCMP set_female 2
INCMP set_unspecified 3 INCMP set_unspecified 3
INCMP . *

View File

@ -1,2 +1,2 @@
Jinsia ya sasa {{.get_current_profile_info}} Jinsia ya sasa: {{.get_current_profile_info}}
Chagua jinsia Chagua jinsia