Перевел на multi-tenant

Добавил поставщиков
Накладные успешно создаются из фронта
This commit is contained in:
2025-12-18 03:56:21 +03:00
parent 47ec8094e5
commit 542beafe0e
38 changed files with 1942 additions and 977 deletions

View File

@@ -0,0 +1,77 @@
package telegram
import "sync"
// Состояния пользователя
type State int
const (
StateNone State = iota
StateAddServerURL
StateAddServerLogin
StateAddServerPassword
)
// UserContext хранит временные данные в процессе диалога
type UserContext struct {
State State
TempURL string
TempLogin string
TempPassword string
}
// StateManager управляет состояниями
type StateManager struct {
mu sync.RWMutex
states map[int64]*UserContext
}
func NewStateManager() *StateManager {
return &StateManager{
states: make(map[int64]*UserContext),
}
}
func (sm *StateManager) GetState(userID int64) State {
sm.mu.RLock()
defer sm.mu.RUnlock()
if ctx, ok := sm.states[userID]; ok {
return ctx.State
}
return StateNone
}
func (sm *StateManager) SetState(userID int64, state State) {
sm.mu.Lock()
defer sm.mu.Unlock()
if _, ok := sm.states[userID]; !ok {
sm.states[userID] = &UserContext{}
}
sm.states[userID].State = state
}
func (sm *StateManager) GetContext(userID int64) *UserContext {
sm.mu.RLock()
defer sm.mu.RUnlock()
if ctx, ok := sm.states[userID]; ok {
return ctx
}
return &UserContext{} // Return empty safe struct
}
func (sm *StateManager) UpdateContext(userID int64, updater func(*UserContext)) {
sm.mu.Lock()
defer sm.mu.Unlock()
if _, ok := sm.states[userID]; !ok {
sm.states[userID] = &UserContext{}
}
updater(sm.states[userID])
}
func (sm *StateManager) Reset(userID int64) {
sm.mu.Lock()
defer sm.mu.Unlock()
delete(sm.states, userID)
}