diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 532eeb4..c43f98f 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -18,12 +18,13 @@ import ( "git.grassecon.net/grassrootseconomics/visedriver/config" "git.grassecon.net/grassrootseconomics/visedriver/initializers" - "git.grassecon.net/grassrootseconomics/visedriver/remote" "git.grassecon.net/grassrootseconomics/visedriver/common" "git.grassecon.net/grassrootseconomics/visedriver/session" at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking" "git.grassecon.net/grassrootseconomics/visedriver-africastalking/args" + + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" ) @@ -132,8 +133,8 @@ func main() { os.Exit(1) } - accountService := remote.AccountService{} - hl, err := lhs.GetHandler(&accountService) + accountService := &httpremote.HTTPAccountService{} + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/async/main.go b/cmd/async/main.go index ba25ba0..3b06692 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -18,8 +18,8 @@ import ( "git.grassecon.net/grassrootseconomics/visedriver/initializers" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/session" - "git.grassecon.net/grassrootseconomics/visedriver/remote" "git.grassecon.net/grassrootseconomics/visedriver/request" + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" ) @@ -131,9 +131,9 @@ func main() { lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs) lhs.SetDataStore(&userdataStore) - accountService := remote.AccountService{} + accountService := &httpremote.HTTPAccountService{} - hl, err := lhs.GetHandler(&accountService) + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/http/main.go b/cmd/http/main.go index ae43a68..bcd454f 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -21,8 +21,8 @@ import ( httpsession "git.grassecon.net/grassrootseconomics/visedriver/session/http" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/session" - "git.grassecon.net/grassrootseconomics/visedriver/remote" + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" ) @@ -121,8 +121,8 @@ func main() { os.Exit(1) } - accountService := remote.AccountService{} - hl, err := lhs.GetHandler(&accountService) + accountService := &httpremote.HTTPAccountService{} + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/main.go b/cmd/main.go index d36979f..72ab974 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -13,8 +13,8 @@ import ( "git.defalsify.org/vise.git/lang" "git.grassecon.net/grassrootseconomics/visedriver/config" "git.grassecon.net/grassrootseconomics/visedriver/initializers" - "git.grassecon.net/grassrootseconomics/visedriver/remote" "git.grassecon.net/grassrootseconomics/visedriver/common" + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" ) @@ -131,8 +131,8 @@ func main() { os.Exit(1) } - accountService := remote.AccountService{} - hl, err := lhs.GetHandler(&accountService) + accountService := &httpremote.HTTPAccountService{} + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/go.mod b/go.mod index 876cc3c..ac5e1aa 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d + git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250111175819-d3e6a462aa0f git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250111151614-46bf21b7b8bd git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250111150203-fd8301144509 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index 18547a9..65249d9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw= git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250111175819-d3e6a462aa0f h1:5WTCUeIlRNTJtdyqd1inF+F6RZ2PUcVcGg1eX9vqT1E= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250111175819-d3e6a462aa0f/go.mod h1:0cuilFAZApPE/SMa3cP72TPdH1MoqhuDEaeJ0VGQ6/I= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250111151614-46bf21b7b8bd h1:mKCov8udBJBQuMF3aFg38SkClL8OvAUZmtArNzgIPak= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250111151614-46bf21b7b8bd/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250111150203-fd8301144509 h1:xlX2FAJkjn1/VS/1z8A9eSGnKWDUmBJy+GtEEDRmggc= diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 3991789..08baef2 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -8,8 +8,9 @@ import ( "strconv" "strings" - "git.defalsify.org/vise.git/asm" + "gopkg.in/leonelquinteros/gotext.v1" + "git.defalsify.org/vise.git/asm" "git.defalsify.org/vise.git/cache" "git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/lang" @@ -19,9 +20,9 @@ import ( "git.defalsify.org/vise.git/state" "git.grassecon.net/grassrootseconomics/visedriver/common" "git.grassecon.net/grassrootseconomics/visedriver/utils" - "git.grassecon.net/grassrootseconomics/visedriver/models" - "git.grassecon.net/grassrootseconomics/visedriver/remote" - "gopkg.in/leonelquinteros/gotext.v1" + + "git.grassecon.net/grassrootseconomics/sarafu-api/models" + "git.grassecon.net/grassrootseconomics/sarafu-api/remote" dbstorage "git.grassecon.net/grassrootseconomics/visedriver/storage/db" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" @@ -63,14 +64,14 @@ type MenuHandlers struct { userdataStore common.DataStore adminstore *utils.AdminStore flagManager *asm.FlagParser - accountService remote.AccountServiceInterface + accountService remote.AccountService prefixDb dbstorage.PrefixDb profile *models.Profile ReplaceSeparatorFunc func(string) string } // NewHandlers creates a new instance of the Handlers struct with the provided dependencies. -func NewMenuHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) { +func NewMenuHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) { if userdataStore == nil { return nil, fmt.Errorf("cannot create handler with nil userdata store") } diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index c34cc51..51653c6 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -15,10 +15,10 @@ import ( "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/state" dbstorage "git.grassecon.net/grassrootseconomics/visedriver/storage/db" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/testservice" "git.grassecon.net/grassrootseconomics/visedriver/utils" - "git.grassecon.net/grassrootseconomics/visedriver/models" + "git.grassecon.net/grassrootseconomics/sarafu-api/models" + "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice" + "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks" "git.grassecon.net/grassrootseconomics/visedriver/common" "github.com/alecthomas/assert/v2" diff --git a/handlers/local.go b/handlers/local.go index bf800f1..06a1f9f 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -11,7 +11,7 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/visedriver/utils" - "git.grassecon.net/grassrootseconomics/visedriver/remote" + "git.grassecon.net/grassrootseconomics/sarafu-api/remote" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application" ) @@ -64,7 +64,7 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) { ls.UserdataStore = db } -func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*application.MenuHandlers, error) { +func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) (*application.MenuHandlers, error) { replaceSeparatorFunc := func(input string) string { return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator) } diff --git a/ssh/ssh.go b/ssh/ssh.go index e4b5722..34cb91d 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -16,10 +16,8 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/state" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/remote" - + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" ) @@ -182,7 +180,7 @@ func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) { } // TODO: clear up why pointer here and by-value other cmds - accountService := &remote.AccountService{} + accountService := &httpremote.HTTPAccountService{} hl, err := lhs.GetHandler(accountService) if err != nil { return nil, nil, err diff --git a/testutil/engine.go b/testutil/engine.go index 9f6f828..063350e 100644 --- a/testutil/engine.go +++ b/testutil/engine.go @@ -10,6 +10,7 @@ import ( "path/filepath" "time" + testdataloader "github.com/peteole/testdata-loader" "github.com/jackc/pgx/v5/pgxpool" "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/logging" @@ -18,10 +19,10 @@ import ( "git.grassecon.net/grassrootseconomics/visedriver/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/testservice" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/testtag" - testdataloader "github.com/peteole/testdata-loader" - "git.grassecon.net/grassrootseconomics/visedriver/remote" + "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice" + "git.grassecon.net/grassrootseconomics/sarafu-api/remote" + httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" + "git.grassecon.net/grassrootseconomics/sarafu-vise/testutil/testtag" ) var ( @@ -168,7 +169,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) { } if testtag.AccountService == nil { - testtag.AccountService = &remote.AccountService{} + testtag.AccountService = &httpremote.HTTPAccountService{} } switch testtag.AccountService.(type) { @@ -176,7 +177,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) { go func() { eventChannel <- false }() - case *remote.AccountService: + case remote.AccountService: go func() { time.Sleep(5 * time.Second) // Wait for 5 seconds eventChannel <- true diff --git a/testutil/testtag/offlinetest.go b/testutil/testtag/offlinetest.go new file mode 100644 index 0000000..ed23fc7 --- /dev/null +++ b/testutil/testtag/offlinetest.go @@ -0,0 +1,12 @@ +// +build !online + +package testtag + +import ( + "git.grassecon.net/grassrootseconomics/sarafu-api/remote" + accountservice "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice" +) + +var ( + AccountService remote.AccountService = &accountservice.TestAccountService{} +) diff --git a/testutil/testtag/onlinetest.go b/testutil/testtag/onlinetest.go new file mode 100644 index 0000000..46a0f88 --- /dev/null +++ b/testutil/testtag/onlinetest.go @@ -0,0 +1,9 @@ +// +build online + +package testtag + +import "git.grassecon.net/grassrootseconomics/visedriver/remote" + +var ( + AccountService remote.AccountServiceInterface +)