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/albums.go

38 lines
1019 B
Go
Raw Normal View History

2021-01-19 21:26:10 +00:00
package db
2021-02-07 02:11:44 +00:00
import (
log "github.com/sirupsen/logrus"
2021-02-09 00:42:20 +00:00
"gorm.io/gorm"
2021-02-07 02:11:44 +00:00
"reichard.io/imagini/graph/model"
)
func (dbm *DBManager) CreateAlbum(album *model.Album) error {
log.Debug("[db] Creating album: ", album.Name)
err := dbm.db.Create(album).Error
return err
}
func (dbm *DBManager) Album(album *model.Album) (int64, error) {
var count int64
err := dbm.db.Where(album).First(album).Count(&count).Error
return count, err
}
2021-02-09 00:42:20 +00:00
func (dbm *DBManager) Albums(userID string, filters *model.AlbumFilter, page *model.Page, order *model.Order) ([]*model.Album, model.PageResponse, error) {
// Initial User Filter
tx := dbm.db.Session(&gorm.Session{}).Model(&model.Album{}).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 foundAlbums []*model.Album
2021-02-09 00:42:20 +00:00
err := tx.Find(&foundAlbums).Error
return foundAlbums, pageResponse, err
2021-02-07 02:11:44 +00:00
}
func (dbm *DBManager) DeleteAlbum(album *model.Album) error {
return nil
}