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

36 lines
1.1 KiB
Go
Raw Normal View History

2021-01-19 20:50:48 +00:00
package db
import (
log "github.com/sirupsen/logrus"
"reichard.io/imagini/internal/models"
)
func (dbm *DBManager) CreateMediaItem (mediaItem models.MediaItem) (models.MediaItem, error) {
log.Info("[db] Creating media item: ", mediaItem.RelPath)
err := dbm.db.Create(&mediaItem).Error
return mediaItem, err
}
func (dbm *DBManager) MediaItemsFromAlbum(user models.User, album models.Album) ([]models.MediaItem, error) {
var mediaItems []models.MediaItem
// db.Table("media_albums").
// Select("media_item.*").
// Joins("INNER JOIN media_items ON media_albums.ID = media_items.Albums").
// Where("media_albums.album_id = ? AND media_items.User = ?", albumID, userID).
err := dbm.db.
//Where("album = ? AND user = ?", albumID, userID).
Find(&mediaItems).Error
return mediaItems, err
// db.Raw(`
// SELECT
// MediaItems.*
// FROM
// MediaAlbums
// INNER JOIN MediaItems ON MediaAlbums.mediaID = MediaItems.mediaID
// WHERE MediaAlbums.albumID = ? AND MediaItems.userID = ?`, albumID, userID)
}