Feat: join team

This commit is contained in:
Grail Finder
2025-05-08 12:31:44 +03:00
parent b20f7ac6b7
commit 21948b23f4
9 changed files with 112 additions and 22 deletions

View File

@ -60,6 +60,26 @@ func getStateByCtx(ctx context.Context) (*models.UserState, error) {
return us, nil
}
func saveStateByCtx(ctx context.Context, state *models.UserState) error {
username, ok := ctx.Value(models.CtxUsernameKey).(string)
if !ok {
log.Debug("no username in ctx")
return errors.New("no username in ctx")
}
return saveState(username, state)
}
func saveFullInfoByUsername(username string, fi *models.FullInfo) error {
// INFO: unfortunately working no transactions; so case are possible where first object is updated but the second is not
if err := saveState(username, fi.State); err != nil {
return err
}
if err := saveRoom(fi.Room); err != nil {
return err
}
return nil
}
// cache
func saveState(username string, state *models.UserState) error {