package sav import ( "sort" "sync" "github.com/google/uuid" "github.com/omnex/control-plane/api/internal/auth" ) type MemContactStore struct { mu sync.RWMutex items map[string]Contact } func NewMemContactStore() *MemContactStore { return &MemContactStore{ items: make(map[string]Contact), } } func (m *MemContactStore) ContactSupportByUser(username, telegram, sujet, message string) (Contact, error) { m.mu.RLock() defer m.mu.RUnlock() contact := Contact{ ID: uuid.NewString(), Username: auth.NormalizeUsername(username), Telegram: auth.NormalizeUsername(telegram), Sujet: sujet, Message: message, } m.items[contact.ID] = contact return contact, nil } func (m *MemContactStore) GetMessage() ([]Contact, error) { m.mu.RLock() defer m.mu.RUnlock() contacts := make([]Contact, 0, len(m.items)) for _, c := range m.items { contacts = append(contacts, c) } sort.Slice(contacts, func(i, j int) bool { return contacts[i].CreatedAt.After(contacts[j].CreatedAt) }) return contacts, nil }