Rehabilitate until localhandler

This commit is contained in:
lash 2025-01-10 14:04:23 +00:00
parent 85ede15613
commit b60d2648ea
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 64 additions and 58 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path" "path"
testdataloader "github.com/peteole/testdata-loader"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/visedriver/config" "git.grassecon.net/grassrootseconomics/visedriver/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/storage"

View File

@ -1,7 +1,13 @@
package handlers package handlers
import ( import (
"context"
"fmt"
"git.defalsify.org/vise.git/asm"
"git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
@ -9,7 +15,12 @@ import (
"git.grassecon.net/grassrootseconomics/visedriver/request" "git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/visedriver/errors" "git.grassecon.net/grassrootseconomics/visedriver/errors"
dbstorage "git.grassecon.net/grassrootseconomics/visedriver/storage/db"
"git.grassecon.net/grassrootseconomics/visedriver/common"
"git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/visedriver/remote"
"git.grassecon.net/grassrootseconomics/visedriver/models"
"git.grassecon.net/grassrootseconomics/visedriver/utils"
) )
var ( var (
@ -29,6 +40,47 @@ type Handlers struct {
ReplaceSeparatorFunc func(string) string ReplaceSeparatorFunc func(string) string
} }
// NewHandlers creates a new instance of the Handlers struct with the provided dependencies.
func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface, replaceSeparatorFunc func(string) string) (*Handlers, error) {
if userdataStore == nil {
return nil, fmt.Errorf("cannot create handler with nil userdata store")
}
userDb := &common.UserDataStore{
Db: userdataStore,
}
// Instantiate the SubPrefixDb with "DATATYPE_USERDATA" prefix
prefix := common.ToBytes(db.DATATYPE_USERDATA)
prefixDb := dbstorage.NewSubPrefixDb(userdataStore, prefix)
h := &Handlers{
userdataStore: userDb,
flagManager: appFlags,
adminstore: adminstore,
accountService: accountService,
prefixDb: prefixDb,
profile: &models.Profile{Max: 6},
ReplaceSeparatorFunc: replaceSeparatorFunc,
}
return h, nil
}
func (h *Handlers) Exit() {
h.pe = nil
}
func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource.Result, error) {
return resource.Result{}, nil
}
// WithPersister sets persister instance to the handlers.
func (h *Handlers) WithPersister(pe *persist.Persister) *Handlers {
if h.pe != nil {
panic("persister already set")
}
h.pe = pe
return h
}
type BaseSessionHandler struct { type BaseSessionHandler struct {
cfgTemplate engine.Config cfgTemplate engine.Config
rp request.RequestParser rp request.RequestParser
@ -37,7 +89,7 @@ type BaseSessionHandler struct {
provider storage.StorageProvider provider storage.StorageProvider
} }
func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *application.Handlers) *BaseSessionHandler { func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *Handlers) *BaseSessionHandler {
return &BaseSessionHandler{ return &BaseSessionHandler{
cfgTemplate: cfg, cfgTemplate: cfg,
rs: rs, rs: rs,

View File

@ -4,21 +4,21 @@ import (
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"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.grassecon.net/urdt/ussd/internal/handlers" "git.grassecon.net/grassrootseconomics/visedriver/request"
) )
// MockRequestHandler implements handlers.RequestHandler interface for testing // MockRequestHandler implements request.RequestHandler interface for testing
type MockRequestHandler struct { type MockRequestHandler struct {
ProcessFunc func(handlers.RequestSession) (handlers.RequestSession, error) ProcessFunc func(request.RequestSession) (request.RequestSession, error)
GetConfigFunc func() engine.Config GetConfigFunc func() engine.Config
GetEngineFunc func(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine GetEngineFunc func(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine
OutputFunc func(rs handlers.RequestSession) (handlers.RequestSession, error) OutputFunc func(rs request.RequestSession) (request.RequestSession, error)
ResetFunc func(rs handlers.RequestSession) (handlers.RequestSession, error) ResetFunc func(rs request.RequestSession) (request.RequestSession, error)
ShutdownFunc func() ShutdownFunc func()
GetRequestParserFunc func() handlers.RequestParser GetRequestParserFunc func() request.RequestParser
} }
func (m *MockRequestHandler) Process(rqs handlers.RequestSession) (handlers.RequestSession, error) { func (m *MockRequestHandler) Process(rqs request.RequestSession) (request.RequestSession, error) {
return m.ProcessFunc(rqs) return m.ProcessFunc(rqs)
} }
@ -30,11 +30,11 @@ func (m *MockRequestHandler) GetEngine(cfg engine.Config, rs resource.Resource,
return m.GetEngineFunc(cfg, rs, pe) return m.GetEngineFunc(cfg, rs, pe)
} }
func (m *MockRequestHandler) Output(rs handlers.RequestSession) (handlers.RequestSession, error) { func (m *MockRequestHandler) Output(rs request.RequestSession) (request.RequestSession, error) {
return m.OutputFunc(rs) return m.OutputFunc(rs)
} }
func (m *MockRequestHandler) Reset(rs handlers.RequestSession) (handlers.RequestSession, error) { func (m *MockRequestHandler) Reset(rs request.RequestSession) (request.RequestSession, error) {
return m.ResetFunc(rs) return m.ResetFunc(rs)
} }
@ -42,6 +42,6 @@ func (m *MockRequestHandler) Shutdown() {
m.ShutdownFunc() m.ShutdownFunc()
} }
func (m *MockRequestHandler) GetRequestParser() handlers.RequestParser { func (m *MockRequestHandler) GetRequestParser() request.RequestParser {
return m.GetRequestParserFunc() return m.GetRequestParserFunc()
} }

View File

@ -1,47 +0,0 @@
package httpmocks
import (
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/grassrootseconomics/visedriver/request"
)
// MockRequestHandler implements request.RequestHandler interface for testing
type MockRequestHandler struct {
ProcessFunc func(request.RequestSession) (request.RequestSession, error)
GetConfigFunc func() engine.Config
GetEngineFunc func(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine
OutputFunc func(rs request.RequestSession) (request.RequestSession, error)
ResetFunc func(rs request.RequestSession) (request.RequestSession, error)
ShutdownFunc func()
GetRequestParserFunc func() request.RequestParser
}
func (m *MockRequestHandler) Process(rqs request.RequestSession) (request.RequestSession, error) {
return m.ProcessFunc(rqs)
}
func (m *MockRequestHandler) GetConfig() engine.Config {
return m.GetConfigFunc()
}
func (m *MockRequestHandler) GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine {
return m.GetEngineFunc(cfg, rs, pe)
}
func (m *MockRequestHandler) Output(rs request.RequestSession) (request.RequestSession, error) {
return m.OutputFunc(rs)
}
func (m *MockRequestHandler) Reset(rs request.RequestSession) (request.RequestSession, error) {
return m.ResetFunc(rs)
}
func (m *MockRequestHandler) Shutdown() {
m.ShutdownFunc()
}
func (m *MockRequestHandler) GetRequestParser() request.RequestParser {
return m.GetRequestParserFunc()
}