This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/db/devices.go

45 lines
1.2 KiB
Go
Raw Normal View History

2021-01-18 04:56:56 +00:00
package db
import (
2021-02-04 10:16:13 +00:00
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
2021-02-09 00:42:20 +00:00
"gorm.io/gorm"
2021-01-18 04:56:56 +00:00
2021-02-04 10:16:13 +00:00
"reichard.io/imagini/graph/model"
2021-01-18 04:56:56 +00:00
)
2021-02-04 10:16:13 +00:00
func (dbm *DBManager) CreateDevice(device *model.Device) error {
log.Debug("[db] Creating device: ", device.Name)
refreshKey := uuid.New().String()
device.RefreshKey = &refreshKey
err := dbm.db.Create(device).Error
return err
2021-01-18 04:56:56 +00:00
}
2021-02-04 10:16:13 +00:00
func (dbm *DBManager) Device(device *model.Device) (int64, error) {
var count int64
err := dbm.db.Where(device).First(device).Count(&count).Error
return count, err
2021-01-18 04:56:56 +00:00
}
2021-02-09 00:42:20 +00:00
func (dbm *DBManager) Devices(userID string, filters *model.DeviceFilter, page *model.Page, order *model.Order) ([]*model.Device, model.PageResponse, error) {
// Initial User Filter
tx := dbm.db.Session(&gorm.Session{}).Model(&model.Device{}).Where("user_id == ?", userID)
// Dynamically Generate Base Query
tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order)
// Acquire Results
2021-02-07 02:11:44 +00:00
var foundDevices []*model.Device
2021-02-09 00:42:20 +00:00
err := tx.Find(&foundDevices).Error
return foundDevices, pageResponse, err
2021-02-07 02:11:44 +00:00
}
2021-02-04 10:16:13 +00:00
func (dbm *DBManager) DeleteDevice(user *model.Device) error {
return nil
2021-01-18 04:56:56 +00:00
}
2021-02-04 10:16:13 +00:00
func (dbm *DBManager) UpdateRefreshToken(device *model.Device, refreshToken string) error {
return nil
2021-01-18 04:56:56 +00:00
}