chore(dashboard version service): make method sigs more consistent (#60736)
The DashboardVersion struct is the database object; the DashboardVersionDTO is the object that should be sent to the API layer. In the future I'd like to move DashboardVersion to dashverimpl and un-export it, but there are a few places that Insert directly into that table, not all of which are test fixtures, so that should wait until we clean up at least the DashboardService's use of it.
This commit is contained in:
@@ -12,6 +12,10 @@ var (
|
||||
ErrNoVersionsForDashboardID = errors.New("no dashboard versions found for the given DashboardId")
|
||||
)
|
||||
|
||||
// DashboardVersion represents a dashboard version in the database. Ideally this
|
||||
// will be moved into dashverimpl and unexported, but there are a few test
|
||||
// fixtures that insert DashboardVersions directly into a database which must be
|
||||
// refactored first.
|
||||
type DashboardVersion struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'" db:"id"`
|
||||
DashboardID int64 `json:"dashboardId" xorm:"dashboard_id" db:"dashboard_id"`
|
||||
@@ -26,6 +30,22 @@ type DashboardVersion struct {
|
||||
Data *simplejson.Json `json:"data" db:"data"`
|
||||
}
|
||||
|
||||
// ToDTO converts a DashboardVersion to a DashboardVersionDTO.
|
||||
func (v *DashboardVersion) ToDTO(dashUid string) *DashboardVersionDTO {
|
||||
return &DashboardVersionDTO{
|
||||
ID: v.ID,
|
||||
DashboardID: v.DashboardID,
|
||||
DashboardUID: dashUid,
|
||||
ParentVersion: v.ParentVersion,
|
||||
RestoredFrom: v.RestoredFrom,
|
||||
Version: v.Version,
|
||||
Created: v.Created,
|
||||
CreatedBy: v.CreatedBy,
|
||||
Message: v.Message,
|
||||
Data: v.Data,
|
||||
}
|
||||
}
|
||||
|
||||
type GetDashboardVersionQuery struct {
|
||||
DashboardID int64
|
||||
OrgID int64
|
||||
@@ -45,22 +65,21 @@ type ListDashboardVersionsQuery struct {
|
||||
}
|
||||
|
||||
type DashboardVersionDTO struct {
|
||||
ID int64 `json:"id" xorm:"id" db:"id"`
|
||||
DashboardID int64 `json:"dashboardId" xorm:"dashboard_id" db:"dashboard_id"`
|
||||
DashboardUID string `json:"dashboardUid" xorm:"dashboard_uid" db:"dashboard_uid"`
|
||||
ParentVersion int `json:"parentVersion" db:"parent_version"`
|
||||
RestoredFrom int `json:"restoredFrom" db:"restored_from"`
|
||||
Version int `json:"version" db:"version"`
|
||||
Created time.Time `json:"created" db:"created"`
|
||||
// Since we get created by with left join user table, this can be null technically,
|
||||
// but in reality it will always be set, when database is not corrupted.
|
||||
CreatedBy *string `json:"createdBy" db:"created_by_login"`
|
||||
Message string `json:"message" db:"message"`
|
||||
ID int64 `json:"id"`
|
||||
DashboardID int64 `json:"dashboardId"`
|
||||
DashboardUID string `json:"dashboardUid"`
|
||||
ParentVersion int `json:"parentVersion"`
|
||||
RestoredFrom int `json:"restoredFrom"`
|
||||
Version int `json:"version"`
|
||||
Created time.Time `json:"created"`
|
||||
CreatedBy int64 `json:"createdBy"`
|
||||
Message string `json:"message"`
|
||||
Data *simplejson.Json `json:"data" db:"data"`
|
||||
}
|
||||
|
||||
// DashboardVersionMeta extends the dashboard version model with the names
|
||||
// DashboardVersionMeta extends the DashboardVersionDTO with the names
|
||||
// associated with the UserIds, overriding the field with the same name from
|
||||
// the DashboardVersion model.
|
||||
// the DashboardVersionDTO model.
|
||||
type DashboardVersionMeta struct {
|
||||
ID int64 `json:"id"`
|
||||
DashboardID int64 `json:"dashboardId"`
|
||||
|
||||
Reference in New Issue
Block a user