Compare commits
	
		
			No commits in common. "06dc8222324bea13ba06aea1b15d96e282ef3c92" and "0284bc5ef935393f2e6ba0942b193f49bc43f954" have entirely different histories.
		
	
	
		
			06dc822232
			...
			0284bc5ef9
		
	
		
| @ -98,20 +98,21 @@ func main() { | |||||||
| 		cfg.EngineDebug = true | 		cfg.EngineDebug = true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) | 	menuStorageService := storage.MenuStorageService{} | ||||||
| 	rs, err := menuStorageService.GetResource(ctx) | 
 | ||||||
|  | 	rs, err := menuStorageService.GetResource(scriptDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = menuStorageService.EnsureDbDir() | 	err = menuStorageService.EnsureDbDir(dbDir) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	userdataStore, err := menuStorageService.GetUserdataDb(ctx) | 	userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| @ -124,7 +125,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | ||||||
| 	lhs.SetDataStore(&userdataStore) | 	lhs.WithDataStore(&userdataStore) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| @ -137,7 +138,7 @@ func main() { | |||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	stateStore, err := menuStorageService.GetStateStore(ctx) | 	stateStore, err := menuStorageService.GetStateStore(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
|  | |||||||
| @ -71,20 +71,20 @@ func main() { | |||||||
| 		cfg.EngineDebug = true | 		cfg.EngineDebug = true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) | 	menuStorageService := storage.MenuStorageService{} | ||||||
| 	rs, err := menuStorageService.GetResource(ctx) | 	rs, err := menuStorageService.GetResource(scriptDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = menuStorageService.EnsureDbDir() | 	err = menuStorageService.EnsureDbDir(dbDir) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	userdataStore, err := menuStorageService.GetUserdataDb(ctx) | 	userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| @ -97,7 +97,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | ||||||
| 	lhs.SetDataStore(&userdataStore) | 	lhs.WithDataStore(&userdataStore) | ||||||
| 
 | 
 | ||||||
| 	hl, err := lhs.GetHandler() | 	hl, err := lhs.GetHandler() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @ -105,7 +105,7 @@ func main() { | |||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	stateStore, err := menuStorageService.GetStateStore(ctx) | 	stateStore, err := menuStorageService.GetStateStore(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
|  | |||||||
| @ -59,20 +59,20 @@ func main() { | |||||||
| 		cfg.EngineDebug = true | 		cfg.EngineDebug = true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) | 	menuStorageService := storage.MenuStorageService{} | ||||||
| 	rs, err := menuStorageService.GetResource(ctx) | 	rs, err := menuStorageService.GetResource(scriptDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = menuStorageService.EnsureDbDir() | 	err = menuStorageService.EnsureDbDir(dbDir) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	userdataStore, err := menuStorageService.GetUserdataDb(ctx) | 	userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| @ -85,7 +85,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | ||||||
| 	lhs.SetDataStore(&userdataStore) | 	lhs.WithDataStore(&userdataStore) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| @ -98,7 +98,7 @@ func main() { | |||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	stateStore, err := menuStorageService.GetStateStore(ctx) | 	stateStore, err := menuStorageService.GetStateStore(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								cmd/main.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								cmd/main.go
									
									
									
									
									
								
							| @ -43,28 +43,27 @@ func main() { | |||||||
| 		FlagCount:  uint32(16), | 		FlagCount:  uint32(16), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	resourceDir := scriptDir | 	menuStorageService := storage.MenuStorageService{} | ||||||
| 	menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) |  | ||||||
| 
 | 
 | ||||||
| 	err := menuStorageService.EnsureDbDir() | 	err := menuStorageService.EnsureDbDir(dbDir) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	rs, err := menuStorageService.GetResource(ctx) | 	rs, err := menuStorageService.GetResource(scriptDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pe, err := menuStorageService.GetPersister(ctx) | 	pe, err := menuStorageService.GetPersister(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	userdatastore, err := menuStorageService.GetUserdataDb(ctx) | 	userdatastore := menuStorageService.GetUserdataDb(dbDir, ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| @ -77,8 +76,8 @@ func main() { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | 	lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) | ||||||
| 	lhs.SetDataStore(&userdatastore) | 	lhs.WithDataStore(&userdatastore) | ||||||
| 	lhs.SetPersister(pe) | 	lhs.WithPersister(pe) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, err.Error()) | 		fmt.Fprintf(os.Stderr, err.Error()) | ||||||
| @ -97,7 +96,13 @@ func main() { | |||||||
| 		en = en.WithDebug(nil) | 		en = en.WithDebug(nil) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = engine.Loop(ctx, en, os.Stdin, os.Stdout, nil) | 	_, err = en.Init(ctx) | ||||||
|  | 	if err != nil { | ||||||
|  | 		fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err) | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	err = engine.Loop(ctx, en, os.Stdin, os.Stdout) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err) | 		fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								go.mod
									
									
									
									
									
								
							| @ -3,15 +3,12 @@ module git.grassecon.net/urdt/ussd | |||||||
| go 1.22.6 | go 1.22.6 | ||||||
| 
 | 
 | ||||||
| require ( | require ( | ||||||
| 	git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4 | 	git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f | ||||||
| 	github.com/alecthomas/assert/v2 v2.2.2 | 	github.com/alecthomas/assert/v2 v2.2.2 | ||||||
| 	github.com/peteole/testdata-loader v0.3.0 | 	github.com/peteole/testdata-loader v0.3.0 | ||||||
| 	golang.org/x/crypto v0.17.0 |  | ||||||
| 	gopkg.in/leonelquinteros/gotext.v1 v1.3.1 | 	gopkg.in/leonelquinteros/gotext.v1 v1.3.1 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| require golang.org/x/sys v0.15.0 // indirect |  | ||||||
| 
 |  | ||||||
| require ( | require ( | ||||||
| 	github.com/alecthomas/participle/v2 v2.0.0 // indirect | 	github.com/alecthomas/participle/v2 v2.0.0 // indirect | ||||||
| 	github.com/alecthomas/repr v0.2.0 // indirect | 	github.com/alecthomas/repr v0.2.0 // indirect | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								go.sum
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | |||||||
| git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4 h1:IMVUK9OkZ/QtYZPHgTZ+XUs5VQ4eIewIaTyVSCF/nAY= | git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f h1:CuJvG3NyMoRtHUim4aZdrfjjJBg2AId7z0yp7Q97bRM= | ||||||
| git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M= | git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M= | ||||||
| github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= | github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= | ||||||
| github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= | github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= | ||||||
| github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g= | github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g= | ||||||
| @ -28,12 +28,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT | |||||||
| github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||||
| github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= | github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= | ||||||
| github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= | github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= | ||||||
| golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= |  | ||||||
| golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= |  | ||||||
| golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= |  | ||||||
| golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |  | ||||||
| golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= |  | ||||||
| golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= |  | ||||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||||
| gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc= | gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc= | ||||||
|  | |||||||
| @ -71,7 +71,19 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) | |||||||
| 	} | 	} | ||||||
| 	rqs.Engine = en | 	rqs.Engine = en | ||||||
| 
 | 
 | ||||||
| 	r, err = rqs.Engine.Exec(rqs.Ctx, rqs.Input) | 	r, err = rqs.Engine.Init(rqs.Ctx) | ||||||
|  | 	if err != nil { | ||||||
|  | 		perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage) | ||||||
|  | 		rqs.Storage = nil | ||||||
|  | 		if perr != nil { | ||||||
|  | 			logg.ErrorCtxf(rqs.Ctx, "", "storage put error", perr) | ||||||
|  | 		} | ||||||
|  | 		return rqs, err | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if r && len(rqs.Input) > 0 { | ||||||
|  | 		r, err = rqs.Engine.Exec(rqs.Ctx, rqs.Input) | ||||||
|  | 	} | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage) | 		perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage) | ||||||
| 		rqs.Storage = nil | 		rqs.Storage = nil | ||||||
| @ -87,7 +99,7 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) | |||||||
| 
 | 
 | ||||||
| func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession,  error) { | func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession,  error) { | ||||||
| 	var err error | 	var err error | ||||||
| 	_, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) | 	_, err = rqs.Engine.WriteResult(rqs.Ctx, rqs.Writer) | ||||||
| 	return rqs, err | 	return rqs, err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -44,63 +44,62 @@ func NewLocalHandlerService(fp string, debug bool, dbResource *resource.DbResour | |||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ls *LocalHandlerService) SetPersister(Pe *persist.Persister) { | func (localHandlerService *LocalHandlerService) WithPersister(Pe *persist.Persister) { | ||||||
| 	ls.Pe = Pe | 	localHandlerService.Pe = Pe | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ls *LocalHandlerService) SetDataStore(db *db.Db) { | func (localHandlerService *LocalHandlerService) WithDataStore(db *db.Db) { | ||||||
| 	ls.UserdataStore = db | 	localHandlerService.UserdataStore = db | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { | func (localHandlerService *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { | ||||||
| 	ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore) | 	ussdHandlers, err := ussd.NewHandlers(localHandlerService.Parser, *localHandlerService.UserdataStore) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	ussdHandlers = ussdHandlers.WithPersister(ls.Pe) | 	ussdHandlers = ussdHandlers.WithPersister(localHandlerService.Pe) | ||||||
| 	ls.DbRs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) | 	localHandlerService.DbRs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) | ||||||
| 	ls.DbRs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) | 	localHandlerService.DbRs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) | ||||||
| 	ls.DbRs.AddLocalFunc("save_pin", ussdHandlers.SavePin) | 	localHandlerService.DbRs.AddLocalFunc("save_pin", ussdHandlers.SavePin) | ||||||
| 	ls.DbRs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) | 	localHandlerService.DbRs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) | ||||||
| 	ls.DbRs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier) | 	localHandlerService.DbRs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier) | ||||||
| 	ls.DbRs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus) | 	localHandlerService.DbRs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus) | ||||||
| 	ls.DbRs.AddLocalFunc("authorize_account", ussdHandlers.Authorize) | 	localHandlerService.DbRs.AddLocalFunc("authorize_account", ussdHandlers.Authorize) | ||||||
| 	ls.DbRs.AddLocalFunc("quit", ussdHandlers.Quit) | 	localHandlerService.DbRs.AddLocalFunc("quit", ussdHandlers.Quit) | ||||||
| 	ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance) | 	localHandlerService.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance) | ||||||
| 	ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient) | 	localHandlerService.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient) | ||||||
| 	ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset) | 	localHandlerService.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset) | ||||||
| 	ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount) | 	localHandlerService.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount) | ||||||
| 	ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount) | 	localHandlerService.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount) | 	localHandlerService.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount) | ||||||
| 	ls.DbRs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient) | 	localHandlerService.DbRs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient) | ||||||
| 	ls.DbRs.AddLocalFunc("get_sender", ussdHandlers.GetSender) | 	localHandlerService.DbRs.AddLocalFunc("get_sender", ussdHandlers.GetSender) | ||||||
| 	ls.DbRs.AddLocalFunc("get_amount", ussdHandlers.GetAmount) | 	localHandlerService.DbRs.AddLocalFunc("get_amount", ussdHandlers.GetAmount) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin) | 	localHandlerService.DbRs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin) | ||||||
| 	ls.DbRs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname) | 	localHandlerService.DbRs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname) | ||||||
| 	ls.DbRs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname) | 	localHandlerService.DbRs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname) | ||||||
| 	ls.DbRs.AddLocalFunc("save_gender", ussdHandlers.SaveGender) | 	localHandlerService.DbRs.AddLocalFunc("save_gender", ussdHandlers.SaveGender) | ||||||
| 	ls.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation) | 	localHandlerService.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation) | ||||||
| 	ls.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob) | 	localHandlerService.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob) | ||||||
| 	ls.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings) | 	localHandlerService.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings) | ||||||
| 	ls.DbRs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance) | 	localHandlerService.DbRs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized) | 	localHandlerService.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate) | 	localHandlerService.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate) | ||||||
| 	ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo) | 	localHandlerService.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo) | ||||||
| 	ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob) | 	localHandlerService.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) | 	localHandlerService.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) | ||||||
| 	ls.DbRs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) | 	localHandlerService.DbRs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) | ||||||
| 	ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) | 	localHandlerService.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) | ||||||
| 	ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) | 	localHandlerService.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) | ||||||
| 	ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) | 	localHandlerService.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) | ||||||
| 	ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) | 	localHandlerService.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) | ||||||
| 	ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp) | 	localHandlerService.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp) | ||||||
| 
 | 
 | ||||||
| 	return ussdHandlers, nil | 	return ussdHandlers, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // TODO: enable setting of sessionId on engine init time
 | func (localHandlerService *LocalHandlerService) GetEngine() *engine.DefaultEngine { | ||||||
| func (ls *LocalHandlerService) GetEngine() *engine.DefaultEngine { | 	en := engine.NewEngine(localHandlerService.Cfg, localHandlerService.Rs) | ||||||
| 	en := engine.NewEngine(ls.Cfg, ls.Rs) | 	en = en.WithPersister(localHandlerService.Pe) | ||||||
| 	en = en.WithPersister(ls.Pe) |  | ||||||
| 	return en | 	return en | ||||||
| } | } | ||||||
|  | |||||||
| @ -37,6 +37,8 @@ type RequestSession struct { | |||||||
| 	Continue bool | 	Continue bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type engineMaker func(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine | ||||||
|  | 
 | ||||||
| // TODO: seems like can remove this.
 | // TODO: seems like can remove this.
 | ||||||
| type RequestParser interface { | type RequestParser interface { | ||||||
| 	GetSessionId(rq any) (string, error) | 	GetSessionId(rq any) (string, error) | ||||||
|  | |||||||
| @ -279,10 +279,7 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt | |||||||
| // SetResetSingleEdit sets and resets  flags to allow gradual editing of profile information.
 | // SetResetSingleEdit sets and resets  flags to allow gradual editing of profile information.
 | ||||||
| func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) { | func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) { | ||||||
| 	var res resource.Result | 	var res resource.Result | ||||||
| 	flag_single_edit, err := h.flagManager.GetFlag("flag_single_edit") | 	flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") | ||||||
| 	if err != nil { |  | ||||||
| 		return res, err |  | ||||||
| 	} |  | ||||||
| 	res.FlagReset = append(res.FlagReset, flag_single_edit) | 	res.FlagReset = append(res.FlagReset, flag_single_edit) | ||||||
| 	return res, nil | 	return res, nil | ||||||
| } | } | ||||||
| @ -301,6 +298,8 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return res, fmt.Errorf("missing session") | 		return res, fmt.Errorf("missing session") | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	//AccountPin, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_ACCOUNT_PIN)
 | ||||||
| 	store := h.userdataStore | 	store := h.userdataStore | ||||||
| 	AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN) | 	AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @ -337,12 +336,6 @@ func (h *Handlers) SaveFirstname(ctx context.Context, sym string, input []byte) | |||||||
| 		return res, fmt.Errorf("missing session") | 		return res, fmt.Errorf("missing session") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") |  | ||||||
| 	flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") |  | ||||||
| 
 |  | ||||||
| 	res.FlagReset = append(res.FlagReset, flag_allow_update) |  | ||||||
| 	res.FlagSet = append(res.FlagSet, flag_single_edit) |  | ||||||
| 
 |  | ||||||
| 	if len(input) > 0 { | 	if len(input) > 0 { | ||||||
| 		firstName := string(input) | 		firstName := string(input) | ||||||
| 		store := h.userdataStore | 		store := h.userdataStore | ||||||
| @ -385,6 +378,15 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return res, fmt.Errorf("missing session") | 		return res, fmt.Errorf("missing session") | ||||||
| 	} | 	} | ||||||
|  | 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||||
|  | 	flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") | ||||||
|  | 	execPath := utils.GetSingleEditExecutionPath("save_yob") | ||||||
|  | 	isSingleEdit := utils.MatchNavigationPath(execPath, h.st.ExecPath) | ||||||
|  | 
 | ||||||
|  | 	if isSingleEdit { | ||||||
|  | 		res.FlagReset = append(res.FlagReset, flag_allow_update) | ||||||
|  | 		res.FlagSet = append(res.FlagSet, flag_single_edit) | ||||||
|  | 	} | ||||||
| 	if len(input) == 4 { | 	if len(input) == 4 { | ||||||
| 		yob := string(input) | 		yob := string(input) | ||||||
| 		store := h.userdataStore | 		store := h.userdataStore | ||||||
| @ -405,6 +407,17 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) ( | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return res, fmt.Errorf("missing session") | 		return res, fmt.Errorf("missing session") | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||||
|  | 	flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") | ||||||
|  | 	execPath := utils.GetSingleEditExecutionPath("save_location") | ||||||
|  | 	isSingleEdit := utils.MatchNavigationPath(execPath, h.st.ExecPath) | ||||||
|  | 
 | ||||||
|  | 	if isSingleEdit { | ||||||
|  | 		res.FlagReset = append(res.FlagReset, flag_allow_update) | ||||||
|  | 		res.FlagSet = append(res.FlagSet, flag_single_edit) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if len(input) > 0 { | 	if len(input) > 0 { | ||||||
| 		location := string(input) | 		location := string(input) | ||||||
| 		store := h.userdataStore | 		store := h.userdataStore | ||||||
| @ -425,6 +438,15 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return res, fmt.Errorf("missing session") | 		return res, fmt.Errorf("missing session") | ||||||
| 	} | 	} | ||||||
|  | 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||||
|  | 	flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") | ||||||
|  | 	execPath := utils.GetSingleEditExecutionPath("select_gender") | ||||||
|  | 	isSingleEdit := utils.MatchNavigationPath(execPath, h.st.ExecPath) | ||||||
|  | 	if isSingleEdit { | ||||||
|  | 		res.FlagReset = append(res.FlagReset, flag_allow_update) | ||||||
|  | 		res.FlagSet = append(res.FlagSet, flag_single_edit) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	code := codeFromCtx(ctx) | 	code := codeFromCtx(ctx) | ||||||
| 	if len(input) > 0 { | 	if len(input) > 0 { | ||||||
| 		gender := string(input) | 		gender := string(input) | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
| 	"git.defalsify.org/vise.git/db" | 	"git.defalsify.org/vise.git/db" | ||||||
| 	"git.defalsify.org/vise.git/persist" | 	"git.defalsify.org/vise.git/lang" | ||||||
| 	"git.defalsify.org/vise.git/resource" | 	"git.defalsify.org/vise.git/resource" | ||||||
| 	"git.defalsify.org/vise.git/state" | 	"git.defalsify.org/vise.git/state" | ||||||
| 	"git.grassecon.net/urdt/ussd/internal/mocks" | 	"git.grassecon.net/urdt/ussd/internal/mocks" | ||||||
| @ -17,7 +17,6 @@ import ( | |||||||
| 	"git.grassecon.net/urdt/ussd/internal/utils" | 	"git.grassecon.net/urdt/ussd/internal/utils" | ||||||
| 	"github.com/alecthomas/assert/v2" | 	"github.com/alecthomas/assert/v2" | ||||||
| 	testdataloader "github.com/peteole/testdata-loader" | 	testdataloader "github.com/peteole/testdata-loader" | ||||||
| 	"github.com/stretchr/testify/require" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
| @ -97,11 +96,6 @@ func TestCreateAccount(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestSaveFirstname(t *testing.T) { | func TestSaveFirstname(t *testing.T) { | ||||||
| 
 |  | ||||||
| 	fm, err := NewFlagManager(flagsPath) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Fatal(err) |  | ||||||
| 	} |  | ||||||
| 	// Create a new instance of MockMyDataStore
 | 	// Create a new instance of MockMyDataStore
 | ||||||
| 	mockStore := new(mocks.MockUserDataStore) | 	mockStore := new(mocks.MockUserDataStore) | ||||||
| 
 | 
 | ||||||
| @ -110,16 +104,12 @@ func TestSaveFirstname(t *testing.T) { | |||||||
| 	firstName := "John" | 	firstName := "John" | ||||||
| 	ctx := context.WithValue(context.Background(), "SessionId", sessionId) | 	ctx := context.WithValue(context.Background(), "SessionId", sessionId) | ||||||
| 
 | 
 | ||||||
| 	flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update") |  | ||||||
| 	flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit") |  | ||||||
| 
 |  | ||||||
| 	// Set up the expected behavior of the mock
 | 	// Set up the expected behavior of the mock
 | ||||||
| 	mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_FIRST_NAME, []byte(firstName)).Return(nil) | 	mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_FIRST_NAME, []byte(firstName)).Return(nil) | ||||||
| 
 | 
 | ||||||
| 	// Create the Handlers instance with the mock store
 | 	// Create the Handlers instance with the mock store
 | ||||||
| 	h := &Handlers{ | 	h := &Handlers{ | ||||||
| 		userdataStore: mockStore, | 		userdataStore: mockStore, | ||||||
| 		flagManager:   fm.parser, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Call the method
 | 	// Call the method
 | ||||||
| @ -127,10 +117,7 @@ func TestSaveFirstname(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	// Assert results
 | 	// Assert results
 | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	assert.Equal(t, resource.Result{ | 	assert.Equal(t, resource.Result{}, res) | ||||||
| 		FlagSet:   []uint32{flag_single_edit}, |  | ||||||
| 		FlagReset: []uint32{flag_allow_update}, |  | ||||||
| 	}, res) |  | ||||||
| 
 | 
 | ||||||
| 	// Assert all expectations were met
 | 	// Assert all expectations were met
 | ||||||
| 	mockStore.AssertExpectations(t) | 	mockStore.AssertExpectations(t) | ||||||
| @ -575,6 +562,13 @@ func TestSetLanguage(t *testing.T) { | |||||||
| 				Content: "swa", | 				Content: "swa", | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
|  | 		// {
 | ||||||
|  | 		// 	name:     "Unhandled path",
 | ||||||
|  | 		// 	execPath: []string{""},
 | ||||||
|  | 		// 	expectedResult: resource.Result{
 | ||||||
|  | 		// 		FlagSet: []uint32{8},
 | ||||||
|  | 		// 	},
 | ||||||
|  | 		// },
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| @ -606,7 +600,7 @@ func TestSetLanguage(t *testing.T) { | |||||||
| func TestSetResetSingleEdit(t *testing.T) { | func TestSetResetSingleEdit(t *testing.T) { | ||||||
| 	fm, err := NewFlagManager(flagsPath) | 	fm, err := NewFlagManager(flagsPath) | ||||||
| 
 | 
 | ||||||
| 	//flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
 | 	flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update") | ||||||
| 	flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit") | 	flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit") | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @ -618,30 +612,30 @@ func TestSetResetSingleEdit(t *testing.T) { | |||||||
| 		input          []byte | 		input          []byte | ||||||
| 		expectedResult resource.Result | 		expectedResult resource.Result | ||||||
| 	}{ | 	}{ | ||||||
| 		// {
 | 		{ | ||||||
| 		// 	name:  "Set single Edit",
 | 			name:  "Set single Edit", | ||||||
| 		// 	input: []byte("2"),
 | 			input: []byte("2"), | ||||||
| 		// 	expectedResult: resource.Result{
 | 			expectedResult: resource.Result{ | ||||||
| 		// 		FlagSet:   []uint32{flag_single_edit},
 | 				FlagSet:   []uint32{flag_single_edit}, | ||||||
| 		// 		FlagReset: []uint32{flag_allow_update},
 | 				FlagReset: []uint32{flag_allow_update}, | ||||||
| 		// 	},
 | 			}, | ||||||
| 		// },
 | 		}, | ||||||
| 		// {
 | 		{ | ||||||
| 		// 	name:  "Set single Edit",
 | 			name:  "Set single Edit", | ||||||
| 		// 	input: []byte("3"),
 | 			input: []byte("3"), | ||||||
| 		// 	expectedResult: resource.Result{
 | 			expectedResult: resource.Result{ | ||||||
| 		// 		FlagSet:   []uint32{flag_single_edit},
 | 				FlagSet:   []uint32{flag_single_edit}, | ||||||
| 		// 		FlagReset: []uint32{flag_allow_update},
 | 				FlagReset: []uint32{flag_allow_update}, | ||||||
| 		// 	},
 | 			}, | ||||||
| 		// },
 | 		}, | ||||||
| 		// {
 | 		{ | ||||||
| 		// 	name:  "Set single edit",
 | 			name:  "Set single edit", | ||||||
| 		// 	input: []byte("4"),
 | 			input: []byte("4"), | ||||||
| 		// 	expectedResult: resource.Result{
 | 			expectedResult: resource.Result{ | ||||||
| 		// 		FlagReset: []uint32{flag_allow_update},
 | 				FlagReset: []uint32{flag_allow_update}, | ||||||
| 		// 		FlagSet:   []uint32{flag_single_edit},
 | 				FlagSet:   []uint32{flag_single_edit}, | ||||||
| 		// 	},
 | 			}, | ||||||
| 		// },
 | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name:  "No single edit set", | 			name:  "No single edit set", | ||||||
| 			input: []byte("1"), | 			input: []byte("1"), | ||||||
| @ -1666,13 +1660,20 @@ func TestGetProfile(t *testing.T) { | |||||||
| 	mockDataStore := new(mocks.MockUserDataStore) | 	mockDataStore := new(mocks.MockUserDataStore) | ||||||
| 	mockCreateAccountService := new(mocks.MockAccountService) | 	mockCreateAccountService := new(mocks.MockAccountService) | ||||||
| 	mockState := state.NewState(16) | 	mockState := state.NewState(16) | ||||||
|  | 	// Set the ExecPath
 | ||||||
|  | 
 | ||||||
|  | 	ll := &lang.Language{ | ||||||
|  | 		Code: "swa", | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	h := &Handlers{ | 	h := &Handlers{ | ||||||
| 		userdataStore:  mockDataStore, | 		userdataStore:  mockDataStore, | ||||||
| 		accountService: mockCreateAccountService, | 		accountService: mockCreateAccountService, | ||||||
| 		st:             mockState, | 		//	st:             mockState,
 | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	ctx := context.WithValue(context.Background(), "SessionId", sessionId) | 	ctx := context.WithValue(context.Background(), "SessionId", sessionId) | ||||||
|  | 	ctx = context.WithValue(ctx, "Language", ll) | ||||||
| 
 | 
 | ||||||
| 	tests := []struct { | 	tests := []struct { | ||||||
| 		name         string | 		name         string | ||||||
| @ -1709,10 +1710,10 @@ func TestGetProfile(t *testing.T) { | |||||||
| 			name:         "Test with with profile information with language that is not yet supported", | 			name:         "Test with with profile information with language that is not yet supported", | ||||||
| 			keys:         []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB}, | 			keys:         []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB}, | ||||||
| 			profileInfo:  []string{"Doee", "John", "Jinsia", "Bananas", "Kilifi", "1976"}, | 			profileInfo:  []string{"Doee", "John", "Jinsia", "Bananas", "Kilifi", "1976"}, | ||||||
| 			languageCode: "nor", | 			languageCode: "kamba", | ||||||
| 			result: resource.Result{ | 			result: resource.Result{ | ||||||
| 				Content: fmt.Sprintf( | 				Content: fmt.Sprintf( | ||||||
| 					"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n", | 					"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n", | ||||||
| 					"John Doee", "Male", "48", "Kilifi", "Bananas", | 					"John Doee", "Male", "48", "Kilifi", "Bananas", | ||||||
| 				), | 				), | ||||||
| 			}, | 			}, | ||||||
| @ -1724,12 +1725,8 @@ func TestGetProfile(t *testing.T) { | |||||||
| 				mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil) | 				mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil) | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			err := mockState.SetLanguage(tt.languageCode) | 			mockState.SetLanguage(tt.languageCode) | ||||||
| 			if err != nil { |  | ||||||
| 				t.Fail() |  | ||||||
| 			} |  | ||||||
| 			h.st = mockState | 			h.st = mockState | ||||||
| 
 |  | ||||||
| 			res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte("")) | 			res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte("")) | ||||||
| 
 | 
 | ||||||
| 			// Assert that expectations were met
 | 			// Assert that expectations were met
 | ||||||
| @ -1837,25 +1834,6 @@ func TestSaveTemporaryPIn(t *testing.T) { | |||||||
| 	mockStore.AssertExpectations(t) | 	mockStore.AssertExpectations(t) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestWithPersister(t *testing.T) { |  | ||||||
| 	// Test case: Setting a persister
 |  | ||||||
| 	h := &Handlers{} |  | ||||||
| 	p := &persist.Persister{} |  | ||||||
| 
 |  | ||||||
| 	result := h.WithPersister(p) |  | ||||||
| 
 |  | ||||||
| 	assert.Equal(t, p, h.pe, "The persister should be set correctly.") |  | ||||||
| 	assert.Equal(t, h, result, "The returned handler should be the same instance.") |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestWithPersister_PanicWhenAlreadySet(t *testing.T) { |  | ||||||
| 	// Test case: Panic on multiple calls
 |  | ||||||
| 	h := &Handlers{pe: &persist.Persister{}} |  | ||||||
| 	require.Panics(t, func() { |  | ||||||
| 		h.WithPersister(&persist.Persister{}) |  | ||||||
| 	}, "Should panic when trying to set a persister again.") |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestConfirmPin(t *testing.T) { | func TestConfirmPin(t *testing.T) { | ||||||
| 	sessionId := "session123" | 	sessionId := "session123" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -87,6 +87,6 @@ func (ash *ATSessionHandler) Output(rqs handlers.RequestSession) (handlers.Reque | |||||||
| 		return rqs, err | 		return rqs, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	_, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) | 	_, err = rqs.Engine.WriteResult(rqs.Ctx, rqs.Writer) | ||||||
| 	return rqs, err | 	return rqs, err | ||||||
| } | } | ||||||
| @ -69,7 +69,7 @@ func TestATSessionHandler_ServeHTTP(t *testing.T) { | |||||||
| 				mh.GetRequestParserFunc = func() handlers.RequestParser { return mrp } | 				mh.GetRequestParserFunc = func() handlers.RequestParser { return mrp } | ||||||
| 				mh.OutputFunc = func(rs handlers.RequestSession) (handlers.RequestSession, error) { return rs, nil } | 				mh.OutputFunc = func(rs handlers.RequestSession) (handlers.RequestSession, error) { return rs, nil } | ||||||
| 				mh.ResetFunc = func(rs handlers.RequestSession) (handlers.RequestSession, error) { return rs, nil } | 				mh.ResetFunc = func(rs handlers.RequestSession) (handlers.RequestSession, error) { return rs, nil } | ||||||
| 				me.FlushFunc = func(context.Context, io.Writer) (int, error) { return 0, nil } | 				me.WriteResultFunc = func(context.Context, io.Writer) (int, error) { return 0, nil } | ||||||
| 			}, | 			}, | ||||||
| 			formData: url.Values{ | 			formData: url.Values{ | ||||||
| 				"phoneNumber": []string{"+1234567890"}, | 				"phoneNumber": []string{"+1234567890"}, | ||||||
| @ -178,7 +178,7 @@ func TestATSessionHandler_Output(t *testing.T) { | |||||||
| 			input: handlers.RequestSession{ | 			input: handlers.RequestSession{ | ||||||
| 				Continue: true, | 				Continue: true, | ||||||
| 				Engine: &httpmocks.MockEngine{ | 				Engine: &httpmocks.MockEngine{ | ||||||
| 					FlushFunc: func(context.Context, io.Writer) (int, error) { | 					WriteResultFunc: func(context.Context, io.Writer) (int, error) { | ||||||
| 						return 0, nil | 						return 0, nil | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| @ -192,7 +192,7 @@ func TestATSessionHandler_Output(t *testing.T) { | |||||||
| 			input: handlers.RequestSession{ | 			input: handlers.RequestSession{ | ||||||
| 				Continue: false, | 				Continue: false, | ||||||
| 				Engine: &httpmocks.MockEngine{ | 				Engine: &httpmocks.MockEngine{ | ||||||
| 					FlushFunc: func(context.Context, io.Writer) (int, error) { | 					WriteResultFunc: func(context.Context, io.Writer) (int, error) { | ||||||
| 						return 0, nil | 						return 0, nil | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| @ -202,11 +202,11 @@ func TestATSessionHandler_Output(t *testing.T) { | |||||||
| 			expectedError:  false, | 			expectedError:  false, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "Flush error", | 			name: "WriteResult error", | ||||||
| 			input: handlers.RequestSession{ | 			input: handlers.RequestSession{ | ||||||
| 				Continue: true, | 				Continue: true, | ||||||
| 				Engine: &httpmocks.MockEngine{ | 				Engine: &httpmocks.MockEngine{ | ||||||
| 					FlushFunc: func(context.Context, io.Writer) (int, error) { | 					WriteResultFunc: func(context.Context, io.Writer) (int, error) { | ||||||
| 						return 0, errors.New("write error") | 						return 0, errors.New("write error") | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
|  | |||||||
| @ -7,10 +7,10 @@ import ( | |||||||
| 
 | 
 | ||||||
| // MockEngine implements the engine.Engine interface for testing
 | // MockEngine implements the engine.Engine interface for testing
 | ||||||
| type MockEngine struct { | type MockEngine struct { | ||||||
| 	InitFunc   func(context.Context) (bool, error) | 	InitFunc        func(context.Context) (bool, error) | ||||||
| 	ExecFunc   func(context.Context, []byte) (bool, error) | 	ExecFunc        func(context.Context, []byte) (bool, error) | ||||||
| 	FlushFunc  func(context.Context, io.Writer) (int, error) | 	WriteResultFunc func(context.Context, io.Writer) (int, error) | ||||||
| 	FinishFunc func() error | 	FinishFunc      func() error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (m *MockEngine) Init(ctx context.Context) (bool, error) { | func (m *MockEngine) Init(ctx context.Context) (bool, error) { | ||||||
| @ -21,8 +21,8 @@ func (m *MockEngine) Exec(ctx context.Context, input []byte) (bool, error) { | |||||||
| 	return m.ExecFunc(ctx, input) | 	return m.ExecFunc(ctx, input) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (m *MockEngine) Flush(ctx context.Context, w io.Writer) (int, error) { | func (m *MockEngine) WriteResult(ctx context.Context, w io.Writer) (int, error) { | ||||||
| 	return m.FlushFunc(ctx, w) | 	return m.WriteResultFunc(ctx, w) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (m *MockEngine) Finish() error { | func (m *MockEngine) Finish() error { | ||||||
|  | |||||||
| @ -1,115 +0,0 @@ | |||||||
| package storage |  | ||||||
| 
 |  | ||||||
| import ( |  | ||||||
| 	"context" |  | ||||||
| 
 |  | ||||||
| 	"git.defalsify.org/vise.git/db" |  | ||||||
| 	"git.defalsify.org/vise.git/lang" |  | ||||||
| 	gdbmdb "git.defalsify.org/vise.git/db/gdbm" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| var ( |  | ||||||
| 	dbC map[string]chan db.Db |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| type ThreadGdbmDb struct { |  | ||||||
| 	db db.Db |  | ||||||
| 	connStr string |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func NewThreadGdbmDb() *ThreadGdbmDb { |  | ||||||
| 	if dbC == nil { |  | ||||||
| 		dbC = make(map[string]chan db.Db) |  | ||||||
| 	} |  | ||||||
| 	return &ThreadGdbmDb{} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Connect(ctx context.Context, connStr string) error { |  | ||||||
| 	var ok bool |  | ||||||
| 	_, ok = dbC[connStr] |  | ||||||
| 	if ok { |  | ||||||
| 		logg.WarnCtxf(ctx, "already registered thread gdbm, skipping", "connStr", connStr) |  | ||||||
| 		return nil |  | ||||||
| 	} |  | ||||||
| 	gdb := gdbmdb.NewGdbmDb() |  | ||||||
| 	err := gdb.Connect(ctx, connStr) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return err |  | ||||||
| 	} |  | ||||||
| 	dbC[connStr] = make(chan db.Db, 1) |  | ||||||
| 	dbC[connStr]<- gdb |  | ||||||
| 	tdb.connStr = connStr |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) reserve() { |  | ||||||
| 	if tdb.db == nil { |  | ||||||
| 		tdb.db = <-dbC[tdb.connStr] |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) release() { |  | ||||||
| 	if tdb.db == nil { |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	dbC[tdb.connStr] <- tdb.db |  | ||||||
| 	tdb.db = nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) SetPrefix(pfx uint8) { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	tdb.db.SetPrefix(pfx) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) SetSession(sessionId string) { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	tdb.db.SetSession(sessionId) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) SetLanguage(lng *lang.Language) { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	tdb.db.SetLanguage(lng) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Safe() bool { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	v := tdb.db.Safe() |  | ||||||
| 	tdb.release() |  | ||||||
| 	return v |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Prefix() uint8 { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	v := tdb.db.Prefix() |  | ||||||
| 	tdb.release() |  | ||||||
| 	return v |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) SetLock(typ uint8, locked bool) error { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	err := tdb.db.SetLock(typ, locked) |  | ||||||
| 	tdb.release() |  | ||||||
| 	return err |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Put(ctx context.Context, key []byte, val []byte) error { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	err := tdb.db.Put(ctx, key, val) |  | ||||||
| 	tdb.release() |  | ||||||
| 	return err |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Get(ctx context.Context, key []byte) ([]byte, error) { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	v, err := tdb.db.Get(ctx, key) |  | ||||||
| 	tdb.release() |  | ||||||
| 	return v, err |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func(tdb *ThreadGdbmDb) Close() error { |  | ||||||
| 	tdb.reserve() |  | ||||||
| 	close(dbC[tdb.connStr]) |  | ||||||
| 	err := tdb.db.Close() |  | ||||||
| 	tdb.db = nil |  | ||||||
| 	return err |  | ||||||
| } |  | ||||||
| @ -5,10 +5,6 @@ import ( | |||||||
| 	"git.defalsify.org/vise.git/persist" | 	"git.defalsify.org/vise.git/persist" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( |  | ||||||
| 	DATATYPE_CUSTOM = 128  |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| type Storage struct { | type Storage struct { | ||||||
| 	Persister *persist.Persister | 	Persister *persist.Persister | ||||||
| 	UserdataDb db.Db	 | 	UserdataDb db.Db	 | ||||||
|  | |||||||
| @ -8,96 +8,57 @@ import ( | |||||||
| 
 | 
 | ||||||
| 	"git.defalsify.org/vise.git/db" | 	"git.defalsify.org/vise.git/db" | ||||||
| 	fsdb "git.defalsify.org/vise.git/db/fs" | 	fsdb "git.defalsify.org/vise.git/db/fs" | ||||||
|  | 	gdbmdb "git.defalsify.org/vise.git/db/gdbm" | ||||||
| 	"git.defalsify.org/vise.git/persist" | 	"git.defalsify.org/vise.git/persist" | ||||||
| 	"git.defalsify.org/vise.git/resource" | 	"git.defalsify.org/vise.git/resource" | ||||||
| 	"git.defalsify.org/vise.git/logging" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| var ( |  | ||||||
| 	logg = logging.NewVanilla().WithDomain("storage") |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type StorageService interface { | type StorageService interface { | ||||||
| 	GetPersister(ctx context.Context) (*persist.Persister, error) | 	GetPersister(dbDir string, ctx context.Context) (*persist.Persister, error) | ||||||
| 	GetUserdataDb(ctx context.Context) db.Db | 	GetUserdataDb(dbDir string, ctx context.Context) db.Db | ||||||
| 	GetResource(ctx context.Context) (resource.Resource, error) | 	GetResource(resourceDir string, ctx context.Context) (resource.Resource, error) | ||||||
| 	EnsureDbDir() error | 	EnsureDbDir(dbDir string) error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type MenuStorageService struct{ | type MenuStorageService struct{} | ||||||
| 	dbDir string |  | ||||||
| 	resourceDir string |  | ||||||
| 	resourceStore db.Db |  | ||||||
| 	stateStore db.Db |  | ||||||
| 	userDataStore db.Db |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| func NewMenuStorageService(dbDir string, resourceDir string) *MenuStorageService { | func (menuStorageService *MenuStorageService) GetPersister(dbDir string, ctx context.Context) (*persist.Persister, error) { | ||||||
| 	return &MenuStorageService{ | 	store := gdbmdb.NewGdbmDb() | ||||||
| 		dbDir: dbDir, | 	storeFile := path.Join(dbDir, "state.gdbm") | ||||||
| 		resourceDir: resourceDir, | 	store.Connect(ctx, storeFile) | ||||||
| 	} | 	pr := persist.NewPersister(store) | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (ms *MenuStorageService) GetPersister(ctx context.Context) (*persist.Persister, error) { |  | ||||||
| 	ms.stateStore = NewThreadGdbmDb() |  | ||||||
| 	storeFile := path.Join(ms.dbDir, "state.gdbm") |  | ||||||
| 	err := ms.stateStore.Connect(ctx, storeFile) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return nil, err |  | ||||||
| 	} |  | ||||||
| 	pr := persist.NewPersister(ms.stateStore) |  | ||||||
| 	logg.TraceCtxf(ctx, "menu storage service", "persist", pr, "store", ms.stateStore) |  | ||||||
| 	return pr, nil | 	return pr, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ms *MenuStorageService) GetUserdataDb(ctx context.Context) (db.Db, error) { | func (menuStorageService *MenuStorageService) GetUserdataDb(dbDir string, ctx context.Context) db.Db { | ||||||
| 	ms.userDataStore = NewThreadGdbmDb() | 	store := gdbmdb.NewGdbmDb() | ||||||
| 	storeFile := path.Join(ms.dbDir, "userdata.gdbm") | 	storeFile := path.Join(dbDir, "userdata.gdbm") | ||||||
| 	err := ms.userDataStore.Connect(ctx, storeFile) | 	store.Connect(ctx, storeFile) | ||||||
| 	if err != nil { | 
 | ||||||
| 		return nil, err | 	return store | ||||||
| 	} |  | ||||||
| 	return ms.userDataStore, nil |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ms *MenuStorageService) GetResource(ctx context.Context) (resource.Resource, error) { | func (menuStorageService *MenuStorageService) GetResource(resourceDir string, ctx context.Context) (resource.Resource, error) { | ||||||
| 	ms.resourceStore = fsdb.NewFsDb() | 	store := fsdb.NewFsDb() | ||||||
| 	err := ms.resourceStore.Connect(ctx, ms.resourceDir) | 	err := store.Connect(ctx, resourceDir) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	rfs := resource.NewDbResource(ms.resourceStore) | 	rfs := resource.NewDbResource(store) | ||||||
| 	return rfs, nil | 	return rfs, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ms *MenuStorageService) GetStateStore(ctx context.Context) (db.Db, error) { | func (menuStorageService *MenuStorageService) GetStateStore(dbDir string, ctx context.Context) (db.Db, error) { | ||||||
| 	if ms.stateStore != nil { | 	store := gdbmdb.NewGdbmDb() | ||||||
| 		panic("set up store when already exists") | 	storeFile := path.Join(dbDir, "state.gdbm") | ||||||
| 	} | 	store.Connect(ctx, storeFile) | ||||||
| 	ms.stateStore = NewThreadGdbmDb() | 	return store, nil | ||||||
| 	storeFile := path.Join(ms.dbDir, "state.gdbm") |  | ||||||
| 	err := ms.stateStore.Connect(ctx, storeFile) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return nil, err |  | ||||||
| 	} |  | ||||||
| 	return ms.stateStore, nil |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ms *MenuStorageService) EnsureDbDir() error { | func (menuStorageService *MenuStorageService) EnsureDbDir(dbDir string) error { | ||||||
| 	err := os.MkdirAll(ms.dbDir, 0700) | 	err := os.MkdirAll(dbDir, 0700) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("state dir create exited with error: %v\n", err) | 		return fmt.Errorf("state dir create exited with error: %v\n", err) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 |  | ||||||
| func (ms *MenuStorageService) Close() error { |  | ||||||
| 	errA := ms.stateStore.Close() |  | ||||||
| 	errB := ms.userDataStore.Close() |  | ||||||
| 	errC := ms.resourceStore.Close() |  | ||||||
| 	if errA != nil || errB != nil || errC != nil { |  | ||||||
| 		return fmt.Errorf("%v %v %v", errA, errB, errC) |  | ||||||
| 	} |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
|  | |||||||
							
								
								
									
										24
									
								
								internal/utils/navigationmatcher.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								internal/utils/navigationmatcher.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | package utils | ||||||
|  | 
 | ||||||
|  | func MatchNavigationPath(a, b []string) bool { | ||||||
|  | 
 | ||||||
|  | 	if len(a) != len(b) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 	//Check if the navigation path matches with single edit
 | ||||||
|  | 	for i := range a { | ||||||
|  | 		if a[i] != b[i] { | ||||||
|  | 			return false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func GetSingleEditExecutionPath(key string) []string { | ||||||
|  | 	paths := make(map[string][]string) | ||||||
|  | 	paths["select_gender"] = []string{"root", "main", "my_account", "edit_profile", "select_gender"} | ||||||
|  | 	paths["save_location"] = []string{"root", "main", "my_account", "edit_profile", "enter_location"} | ||||||
|  | 	paths["save_yob"] = []string{"root", "main", "my_account", "edit_profile", "enter_yob"} | ||||||
|  | 	return paths[key] | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user