2022-12-31 10:22:38 +01:00
|
|
|
package adapters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/doug-martin/goqu/v9"
|
|
|
|
"github.com/google/uuid"
|
2023-01-30 19:59:42 +01:00
|
|
|
"github.com/twofas/2fas-server/internal/common/clock"
|
2022-12-31 10:22:38 +01:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeviceExtensionsService struct {
|
|
|
|
db *gorm.DB
|
|
|
|
qb *goqu.Database
|
|
|
|
clock clock.Clock
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDeviceExtensionsService(db *gorm.DB, qb *goqu.Database, clock clock.Clock) *DeviceExtensionsService {
|
|
|
|
return &DeviceExtensionsService{
|
|
|
|
db: db,
|
|
|
|
qb: qb,
|
|
|
|
clock: clock,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DeviceExtensionsService) PairDeviceWithBrowserExtension(deviceId string, extId uuid.UUID) error {
|
|
|
|
ds := r.qb.Insert("mobile_device_browser_extension").OnConflict(goqu.DoNothing()).Rows(
|
|
|
|
goqu.Record{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"extension_id": extId.String(),
|
|
|
|
"created_at": r.clock.Now(),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
sql, _, _ := ds.ToSQL()
|
|
|
|
|
|
|
|
if err := r.db.Exec(sql).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|