grafana/pkg/models/playlist.go
Kristin Laemmert a33a023629
backend: add PlaylistUIDs to Playlist; remove playlist IDs from API (#49609)
* backend/api: refactor PlaylistId to PlaylistUid
* Add org_id to Get and Update playlist functions
Fix migration - no longer pad the uid; fix mysql syntax

The relevant tests are passing using postgres, mysql and the default sqllite backends, but there are a number of other failing tests when using postgres and myself so I'm not entirely confident with those results.

* fix bad query in GetPlaylistItem and add a test that would have caught the mistake in the first place. Reverted the playlist_uid column addition in playlist_item; it became unnecessary after this PR.

Added default value to the new UID column based on PR feedback.

* break this PRs migration into its own function

* Playlists: Update UI to use the updated API

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
2022-06-14 15:32:52 -04:00

102 lines
2.0 KiB
Go

package models
import (
"errors"
)
// Typed errors
var (
ErrPlaylistNotFound = errors.New("Playlist not found")
ErrPlaylistFailedGenerateUniqueUid = errors.New("failed to generate unique playlist UID")
)
// Playlist model
type Playlist struct {
Id int64 `json:"id"`
UID string `json:"uid" xorm:"uid"`
Name string `json:"name"`
Interval string `json:"interval"`
OrgId int64 `json:"-"`
}
type PlaylistDTO struct {
Id int64 `json:"id"`
UID string `json:"uid"`
Name string `json:"name"`
Interval string `json:"interval"`
OrgId int64 `json:"-"`
Items []PlaylistItemDTO `json:"items"`
}
type PlaylistItemDTO struct {
Id int64 `json:"id"`
PlaylistId int64 `json:"playlistid"`
Type string `json:"type"`
Title string `json:"title"`
Value string `json:"value"`
Order int `json:"order"`
}
type PlaylistItem struct {
Id int64
PlaylistId int64
Type string
Value string
Order int
Title string
}
type Playlists []*Playlist
//
// COMMANDS
//
type UpdatePlaylistCommand struct {
OrgId int64 `json:"-"`
UID string `json:"uid"`
Name string `json:"name" binding:"Required"`
Interval string `json:"interval"`
Items []PlaylistItemDTO `json:"items"`
Result *PlaylistDTO
}
type CreatePlaylistCommand struct {
Name string `json:"name" binding:"Required"`
Interval string `json:"interval"`
Items []PlaylistItemDTO `json:"items"`
OrgId int64 `json:"-"`
Result *Playlist
}
type DeletePlaylistCommand struct {
UID string
OrgId int64
}
//
// QUERIES
//
type GetPlaylistsQuery struct {
Name string
Limit int
OrgId int64
Result Playlists
}
type GetPlaylistByUidQuery struct {
UID string
OrgId int64
Result *Playlist
}
type GetPlaylistItemsByUidQuery struct {
PlaylistUID string
OrgId int64
Result *[]PlaylistItem
}