Rename handler/ussd package.
This commit is contained in:
parent
80b96e9bf6
commit
048f8f0d10
@ -6,42 +6,42 @@ import (
|
|||||||
"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/ussd"
|
"git.grassecon.net/urdt/ussd/internal/handlers/application"
|
||||||
"git.grassecon.net/urdt/ussd/internal/storage"
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseSessionHandler struct {
|
type BaseSessionHandler struct {
|
||||||
cfgTemplate engine.Config
|
cfgTemplate engine.Config
|
||||||
rp RequestParser
|
rp RequestParser
|
||||||
rs resource.Resource
|
rs resource.Resource
|
||||||
hn *ussd.Handlers
|
hn *application.Handlers
|
||||||
provider storage.StorageProvider
|
provider storage.StorageProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn *ussd.Handlers) *BaseSessionHandler {
|
func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn *application.Handlers) *BaseSessionHandler {
|
||||||
return &BaseSessionHandler{
|
return &BaseSessionHandler{
|
||||||
cfgTemplate: cfg,
|
cfgTemplate: cfg,
|
||||||
rs: rs,
|
rs: rs,
|
||||||
hn: hn,
|
hn: hn,
|
||||||
rp: rp,
|
rp: rp,
|
||||||
provider: storage.NewSimpleStorageProvider(stateDb, userdataDb),
|
provider: storage.NewSimpleStorageProvider(stateDb, userdataDb),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f* BaseSessionHandler) Shutdown() {
|
func (f *BaseSessionHandler) Shutdown() {
|
||||||
err := f.provider.Close()
|
err := f.provider.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.Errorf("handler shutdown error", "err", err)
|
logg.Errorf("handler shutdown error", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *BaseSessionHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine {
|
func (f *BaseSessionHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine {
|
||||||
en := engine.NewEngine(cfg, rs)
|
en := engine.NewEngine(cfg, rs)
|
||||||
en = en.WithPersister(pr)
|
en = en.WithPersister(pr)
|
||||||
return en
|
return en
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) {
|
func (f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) {
|
||||||
var r bool
|
var r bool
|
||||||
var err error
|
var err error
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -88,21 +88,21 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
|||||||
return rqs, nil
|
return rqs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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.Flush(rqs.Ctx, rqs.Writer)
|
||||||
return rqs, err
|
return rqs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) {
|
func (f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) {
|
||||||
defer f.provider.Put(rqs.Config.SessionId, rqs.Storage)
|
defer f.provider.Put(rqs.Config.SessionId, rqs.Storage)
|
||||||
return rqs, rqs.Engine.Finish()
|
return rqs, rqs.Engine.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *BaseSessionHandler) GetConfig() engine.Config {
|
func (f *BaseSessionHandler) GetConfig() engine.Config {
|
||||||
return f.cfgTemplate
|
return f.cfgTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *BaseSessionHandler) GetRequestParser() RequestParser {
|
func (f *BaseSessionHandler) GetRequestParser() RequestParser {
|
||||||
return f.rp
|
return f.rp
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,13 @@ import (
|
|||||||
"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/ussd"
|
"git.grassecon.net/urdt/ussd/internal/handlers/application"
|
||||||
"git.grassecon.net/urdt/ussd/internal/utils"
|
"git.grassecon.net/urdt/ussd/internal/utils"
|
||||||
"git.grassecon.net/urdt/ussd/remote"
|
"git.grassecon.net/urdt/ussd/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HandlerService interface {
|
type HandlerService interface {
|
||||||
GetHandler() (*ussd.Handlers, error)
|
GetHandler() (*application.Handlers, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParser(fp string, debug bool) (*asm.FlagParser, error) {
|
func getParser(fp string, debug bool) (*asm.FlagParser, error) {
|
||||||
@ -64,72 +64,72 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) {
|
|||||||
ls.UserdataStore = db
|
ls.UserdataStore = db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*ussd.Handlers, error) {
|
func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*application.Handlers, error) {
|
||||||
replaceSeparatorFunc := func(input string) string {
|
replaceSeparatorFunc := func(input string) string {
|
||||||
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
|
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc)
|
appHandlers, err := application.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ussdHandlers = ussdHandlers.WithPersister(ls.Pe)
|
appHandlers = appHandlers.WithPersister(ls.Pe)
|
||||||
ls.DbRs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage)
|
||||||
ls.DbRs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
ls.DbRs.AddLocalFunc("create_account", appHandlers.CreateAccount)
|
||||||
ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
ls.DbRs.AddLocalFunc("save_temporary_pin", appHandlers.SaveTemporaryPin)
|
||||||
ls.DbRs.AddLocalFunc("verify_create_pin", ussdHandlers.VerifyCreatePin)
|
ls.DbRs.AddLocalFunc("verify_create_pin", appHandlers.VerifyCreatePin)
|
||||||
ls.DbRs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
|
ls.DbRs.AddLocalFunc("check_identifier", appHandlers.CheckIdentifier)
|
||||||
ls.DbRs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
|
ls.DbRs.AddLocalFunc("check_account_status", appHandlers.CheckAccountStatus)
|
||||||
ls.DbRs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
|
ls.DbRs.AddLocalFunc("authorize_account", appHandlers.Authorize)
|
||||||
ls.DbRs.AddLocalFunc("quit", ussdHandlers.Quit)
|
ls.DbRs.AddLocalFunc("quit", appHandlers.Quit)
|
||||||
ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
ls.DbRs.AddLocalFunc("check_balance", appHandlers.CheckBalance)
|
||||||
ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
ls.DbRs.AddLocalFunc("validate_recipient", appHandlers.ValidateRecipient)
|
||||||
ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
ls.DbRs.AddLocalFunc("transaction_reset", appHandlers.TransactionReset)
|
||||||
ls.DbRs.AddLocalFunc("invite_valid_recipient", ussdHandlers.InviteValidRecipient)
|
ls.DbRs.AddLocalFunc("invite_valid_recipient", appHandlers.InviteValidRecipient)
|
||||||
ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
ls.DbRs.AddLocalFunc("max_amount", appHandlers.MaxAmount)
|
||||||
ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
ls.DbRs.AddLocalFunc("validate_amount", appHandlers.ValidateAmount)
|
||||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount)
|
||||||
ls.DbRs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
ls.DbRs.AddLocalFunc("get_recipient", appHandlers.GetRecipient)
|
||||||
ls.DbRs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
|
ls.DbRs.AddLocalFunc("get_sender", appHandlers.GetSender)
|
||||||
ls.DbRs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
|
ls.DbRs.AddLocalFunc("get_amount", appHandlers.GetAmount)
|
||||||
ls.DbRs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
|
ls.DbRs.AddLocalFunc("reset_incorrect", appHandlers.ResetIncorrectPin)
|
||||||
ls.DbRs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
|
ls.DbRs.AddLocalFunc("save_firstname", appHandlers.SaveFirstname)
|
||||||
ls.DbRs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
|
ls.DbRs.AddLocalFunc("save_familyname", appHandlers.SaveFamilyname)
|
||||||
ls.DbRs.AddLocalFunc("save_gender", ussdHandlers.SaveGender)
|
ls.DbRs.AddLocalFunc("save_gender", appHandlers.SaveGender)
|
||||||
ls.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
ls.DbRs.AddLocalFunc("save_location", appHandlers.SaveLocation)
|
||||||
ls.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
ls.DbRs.AddLocalFunc("save_yob", appHandlers.SaveYob)
|
||||||
ls.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
ls.DbRs.AddLocalFunc("save_offerings", appHandlers.SaveOfferings)
|
||||||
ls.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
ls.DbRs.AddLocalFunc("reset_account_authorized", appHandlers.ResetAccountAuthorized)
|
||||||
ls.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
ls.DbRs.AddLocalFunc("reset_allow_update", appHandlers.ResetAllowUpdate)
|
||||||
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
ls.DbRs.AddLocalFunc("get_profile_info", appHandlers.GetProfileInfo)
|
||||||
ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
ls.DbRs.AddLocalFunc("verify_yob", appHandlers.VerifyYob)
|
||||||
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", appHandlers.ResetIncorrectYob)
|
||||||
ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
ls.DbRs.AddLocalFunc("initiate_transaction", appHandlers.InitiateTransaction)
|
||||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
ls.DbRs.AddLocalFunc("verify_new_pin", appHandlers.VerifyNewPin)
|
||||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
ls.DbRs.AddLocalFunc("confirm_pin_change", appHandlers.ConfirmPinChange)
|
||||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
ls.DbRs.AddLocalFunc("quit_with_help", appHandlers.QuitWithHelp)
|
||||||
ls.DbRs.AddLocalFunc("fetch_community_balance", ussdHandlers.FetchCommunityBalance)
|
ls.DbRs.AddLocalFunc("fetch_community_balance", appHandlers.FetchCommunityBalance)
|
||||||
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
ls.DbRs.AddLocalFunc("set_default_voucher", appHandlers.SetDefaultVoucher)
|
||||||
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
ls.DbRs.AddLocalFunc("check_vouchers", appHandlers.CheckVouchers)
|
||||||
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
ls.DbRs.AddLocalFunc("get_vouchers", appHandlers.GetVoucherList)
|
||||||
ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher)
|
ls.DbRs.AddLocalFunc("view_voucher", appHandlers.ViewVoucher)
|
||||||
ls.DbRs.AddLocalFunc("set_voucher", ussdHandlers.SetVoucher)
|
ls.DbRs.AddLocalFunc("set_voucher", appHandlers.SetVoucher)
|
||||||
ls.DbRs.AddLocalFunc("get_voucher_details", ussdHandlers.GetVoucherDetails)
|
ls.DbRs.AddLocalFunc("get_voucher_details", appHandlers.GetVoucherDetails)
|
||||||
ls.DbRs.AddLocalFunc("reset_valid_pin", ussdHandlers.ResetValidPin)
|
ls.DbRs.AddLocalFunc("reset_valid_pin", appHandlers.ResetValidPin)
|
||||||
ls.DbRs.AddLocalFunc("check_pin_mismatch", ussdHandlers.CheckBlockedNumPinMisMatch)
|
ls.DbRs.AddLocalFunc("check_pin_mismatch", appHandlers.CheckBlockedNumPinMisMatch)
|
||||||
ls.DbRs.AddLocalFunc("validate_blocked_number", ussdHandlers.ValidateBlockedNumber)
|
ls.DbRs.AddLocalFunc("validate_blocked_number", appHandlers.ValidateBlockedNumber)
|
||||||
ls.DbRs.AddLocalFunc("retrieve_blocked_number", ussdHandlers.RetrieveBlockedNumber)
|
ls.DbRs.AddLocalFunc("retrieve_blocked_number", appHandlers.RetrieveBlockedNumber)
|
||||||
ls.DbRs.AddLocalFunc("reset_unregistered_number", ussdHandlers.ResetUnregisteredNumber)
|
ls.DbRs.AddLocalFunc("reset_unregistered_number", appHandlers.ResetUnregisteredNumber)
|
||||||
ls.DbRs.AddLocalFunc("reset_others_pin", ussdHandlers.ResetOthersPin)
|
ls.DbRs.AddLocalFunc("reset_others_pin", appHandlers.ResetOthersPin)
|
||||||
ls.DbRs.AddLocalFunc("save_others_temporary_pin", ussdHandlers.SaveOthersTemporaryPin)
|
ls.DbRs.AddLocalFunc("save_others_temporary_pin", appHandlers.SaveOthersTemporaryPin)
|
||||||
ls.DbRs.AddLocalFunc("get_current_profile_info", ussdHandlers.GetCurrentProfileInfo)
|
ls.DbRs.AddLocalFunc("get_current_profile_info", appHandlers.GetCurrentProfileInfo)
|
||||||
ls.DbRs.AddLocalFunc("check_transactions", ussdHandlers.CheckTransactions)
|
ls.DbRs.AddLocalFunc("check_transactions", appHandlers.CheckTransactions)
|
||||||
ls.DbRs.AddLocalFunc("get_transactions", ussdHandlers.GetTransactionsList)
|
ls.DbRs.AddLocalFunc("get_transactions", appHandlers.GetTransactionsList)
|
||||||
ls.DbRs.AddLocalFunc("view_statement", ussdHandlers.ViewTransactionStatement)
|
ls.DbRs.AddLocalFunc("view_statement", appHandlers.ViewTransactionStatement)
|
||||||
ls.DbRs.AddLocalFunc("update_all_profile_items", ussdHandlers.UpdateAllProfileItems)
|
ls.DbRs.AddLocalFunc("update_all_profile_items", appHandlers.UpdateAllProfileItems)
|
||||||
ls.DbRs.AddLocalFunc("set_back", ussdHandlers.SetBack)
|
ls.DbRs.AddLocalFunc("set_back", appHandlers.SetBack)
|
||||||
|
|
||||||
return ussdHandlers, nil
|
return appHandlers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: enable setting of sessionId on engine init time
|
// TODO: enable setting of sessionId on engine init time
|
||||||
|
Loading…
Reference in New Issue
Block a user