feat(auth): return smoke mode in login response
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"wx_service/internal/model"
|
||||
smokemodel "wx_service/internal/smoke/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -40,6 +41,7 @@ type LoginResult struct {
|
||||
User *model.User
|
||||
SessionKey string
|
||||
MiniProgram *model.MiniProgram
|
||||
Mode string
|
||||
}
|
||||
|
||||
func NewAuthService(db *gorm.DB, miniProgramSvc *MiniProgramService) *AuthService {
|
||||
@@ -139,9 +141,38 @@ func (s *AuthService) LoginWithCode(ctx context.Context, req LoginRequest) (*Log
|
||||
SessionKey: session.SessionKey,
|
||||
MiniProgram: miniProgram,
|
||||
}
|
||||
if mode, err := s.getSmokeMode(ctx, int(user.ID)); err == nil {
|
||||
result.Mode = mode
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *AuthService) getSmokeMode(ctx context.Context, uid int) (string, error) {
|
||||
var profile smokemodel.SmokeUserProfile
|
||||
err := s.db.WithContext(ctx).
|
||||
Select("mode").
|
||||
Where("uid = ? AND deleted_at IS NULL", uid).
|
||||
First(&profile).Error
|
||||
if err == nil {
|
||||
return normalizeSmokeMode(profile.Mode), nil
|
||||
}
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", nil
|
||||
}
|
||||
return "", fmt.Errorf("load smoke profile mode: %w", err)
|
||||
}
|
||||
|
||||
func normalizeSmokeMode(mode string) string {
|
||||
switch strings.TrimSpace(mode) {
|
||||
case "quit":
|
||||
return "quit"
|
||||
case "record":
|
||||
return "record"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AuthService) getWeChatClient(mp *model.MiniProgram) *WeChatClient {
|
||||
s.cacheMu.RLock()
|
||||
client, ok := s.wechatClientCache[mp.ID]
|
||||
|
||||
Reference in New Issue
Block a user