-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactoring DAL & initialization interfaces
- Loading branch information
1 parent
c6a68a1
commit 4735127
Showing
23 changed files
with
180 additions
and
83 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package botsdal | ||
|
||
import ( | ||
"context" | ||
"github.com/bots-go-framework/bots-fw-store/botsfwmodels" | ||
"github.com/bots-go-framework/bots-fw/botsfsobject" | ||
"github.com/dal-go/dalgo/dal" | ||
"github.com/dal-go/dalgo/record" | ||
) | ||
|
||
type AppUserDal interface { | ||
CreateAppUserFromBotUser(ctx context.Context, tx dal.ReadwriteTransaction, platform, botID string, botUser botsfsobject.BotUser) ( | ||
appUser record.DataWithID[string, botsfwmodels.AppUserData], err error, | ||
) | ||
GetAppUserByBotUserID(ctx context.Context, tx dal.ReadwriteTransaction, platform, botID, botUserID string) ( | ||
appUser record.DataWithID[string, botsfwmodels.AppUserData], err error, | ||
) | ||
//UpdateAppUser(ctx context.Context, tx dal.ReadwriteTransaction, appUser record.DataWithID[string, botsfwmodels.AppUserData]) error | ||
//LinkAppUserToBotUser(ctx context.Context, platform, botID, botUserID, appUserID string) (err error) | ||
} | ||
|
||
type appUserDal struct { | ||
} | ||
|
||
func DefaultAppUserDal() AppUserDal { | ||
return appUserDal{} | ||
} | ||
|
||
func (a appUserDal) CreateAppUserFromBotUser(ctx context.Context, tx dal.ReadwriteTransaction, platform, botID string, botUser botsfsobject.BotUser) (appUser record.DataWithID[string, botsfwmodels.AppUserData], err error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a appUserDal) GetAppUserByBotUserID(ctx context.Context, tx dal.ReadwriteTransaction, platform, botID, botUserID string) (appUser record.DataWithID[string, botsfwmodels.AppUserData], err error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a appUserDal) UpdateAppUser(ctx context.Context, tx dal.ReadwriteTransaction, appUser record.DataWithID[string, botsfwmodels.AppUserData]) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a appUserDal) LinkAppUserToBotUser(ctx context.Context, platform, botID, botUserID, appUserID string) (err error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package botsfsobject | ||
|
||
// BotUser provides info about current bot user | ||
type BotUser interface { | ||
// GetBotUserID returns bot user ID | ||
GetBotUserID() string | ||
|
||
// GetFirstName returns user's first name | ||
GetFirstName() string | ||
|
||
// GetLastName returns user's last name | ||
GetLastName() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package botsfw | ||
|
||
import ( | ||
"context" | ||
"github.com/bots-go-framework/bots-fw-store/botsfwmodels" | ||
"github.com/dal-go/dalgo/record" | ||
"github.com/bots-go-framework/bots-fw/botsdal" | ||
"github.com/strongo/i18n" | ||
) | ||
|
||
// BotAppContext is a context for bot app | ||
type BotAppContext interface { | ||
// AppContext is a context for an app that uses the botsfw | ||
type AppContext interface { | ||
//strongoapp.AppUserSettings // TODO: Do we really need it here? | ||
|
||
AppUserCollectionName() string | ||
botsdal.AppUserDal | ||
//AppUserCollectionName() string | ||
//GetAppUserByBotUserID(ctx context.Context, platform, botID, botUserID string) (appUser record.DataWithID[string, botsfwmodels.AppUserData], err error) | ||
|
||
i18n.TranslationContext | ||
|
||
NewBotAppUserEntity() botsfwmodels.AppUserData | ||
GetBotChatEntityFactory(platform string) func() botsfwmodels.BotChatData | ||
|
||
GetAppUserByBotUserID(ctx context.Context, platform, botID, botUserID string) (appUser record.DataWithID[string, botsfwmodels.AppUserData], err error) | ||
//NewBotAppUserEntity() botsfwmodels.AppUserData | ||
//GetBotChatEntityFactory(platform string) func() botsfwmodels.BotChatData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package botsfw | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/bots-go-framework/bots-fw/botsfwconst" | ||
) | ||
|
||
// BotContext binds a bot to a specific hosting environment | ||
type BotContext struct { | ||
AppContext AppContext | ||
BotHost BotHost // describes current bot app host environment | ||
BotSettings *BotSettings // keeps parameters of a bot that are static and are not changed in runtime | ||
} | ||
|
||
// BotContextProvider provides BotContext by platformID & botID | ||
type BotContextProvider interface { | ||
// GetBotContext returns BotContext by platformID & botID | ||
GetBotContext(ctx context.Context, platformID botsfwconst.Platform, botID string) (botContext *BotContext, err error) | ||
} | ||
|
||
type botContextProvider struct { | ||
botHost BotHost | ||
appContext AppContext | ||
botSettingProvider BotSettingsProvider | ||
} | ||
|
||
func NewBotContextProvider(botHost BotHost, appContext AppContext, botSettingProvider BotSettingsProvider) BotContextProvider { | ||
if botHost == nil { | ||
panic("required argument botHost == nil") | ||
} | ||
if appContext == nil { | ||
panic("required argument appContext == nil") | ||
} | ||
if botSettingProvider == nil { | ||
panic("required argument botSettingProvider == nil") | ||
} | ||
return botContextProvider{ | ||
appContext: appContext, | ||
botHost: botHost, | ||
botSettingProvider: botSettingProvider, | ||
} | ||
} | ||
|
||
var ErrUnknownBot = errors.New("unknown bot") | ||
|
||
func (v botContextProvider) GetBotContext(ctx context.Context, platformID botsfwconst.Platform, botID string) (botContext *BotContext, err error) { | ||
botSettingsBy := v.botSettingProvider(ctx) | ||
botSettings, ok := botSettingsBy.ByID[botID] | ||
if !ok { | ||
if botSettings, ok = botSettingsBy.ByCode[botID]; !ok { | ||
return nil, ErrUnknownBot | ||
} | ||
} | ||
return &BotContext{ | ||
AppContext: v.appContext, | ||
BotHost: v.botHost, | ||
BotSettings: botSettings, | ||
}, nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.