32 lines
806 B
Go
32 lines
806 B
Go
package db
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"reichard.io/imagini/graph/model"
|
|
)
|
|
|
|
func (dbm *DBManager) CreateMediaItem(mediaItem *model.MediaItem) error {
|
|
log.Debug("[db] Creating media item: ", mediaItem.FileName)
|
|
err := dbm.db.Create(mediaItem).Error
|
|
return err
|
|
}
|
|
|
|
func (dbm *DBManager) MediaItem(mediaItem *model.MediaItem) (int64, error) {
|
|
var count int64
|
|
err := dbm.db.Where(mediaItem).First(mediaItem).Count(&count).Error
|
|
return count, err
|
|
}
|
|
|
|
func (dbm *DBManager) MediaItems(filters *model.MediaItemFilter) ([]*model.MediaItem, int64, error) {
|
|
// Perform Filters
|
|
tx, err := dbm.generateFilters(*filters)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
var mediaItems []*model.MediaItem
|
|
var count int64
|
|
err = tx.Find(&mediaItems).Count(&count).Error
|
|
return mediaItems, count, err
|
|
}
|