44 lines
943 B
Go
44 lines
943 B
Go
package sav
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/omnex/control-plane/api/internal/auth"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Store interface {
|
|
ContactSupportByUser(username, telegram, sujet, message string) (Contact, error)
|
|
GetMessage() ([]Contact, error)
|
|
}
|
|
|
|
type GormStore struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewGormStore(db *gorm.DB) *GormStore {
|
|
return &GormStore{db: db}
|
|
}
|
|
|
|
func (s *GormStore) ContactSupportByUser(username, telegram, sujet, message string) (Contact, error) {
|
|
contact := Contact{
|
|
ID: uuid.NewString(),
|
|
Username: auth.NormalizeUsername(username),
|
|
Telegram: auth.NormalizeUsername(telegram),
|
|
Sujet: sujet,
|
|
Message: message,
|
|
}
|
|
|
|
if err := s.db.Create(&contact).Error; err != nil {
|
|
return Contact{}, err
|
|
}
|
|
return contact, nil
|
|
}
|
|
|
|
func (s *GormStore) GetMessage() ([]Contact, error) {
|
|
var contacts []Contact
|
|
if err := s.db.Find(&contacts).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return contacts, nil
|
|
}
|