Commit 746d6cdc by Torkel Ödegaard

refactoring: changed name on compare command to make properties more explainatory

parent 9c140184
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
......@@ -323,34 +324,34 @@ func GetDashboardVersion(c *middleware.Context) Response {
return Json(200, dashVersionMeta)
}
func createCompareDashboardVersionCommand(c *middleware.Context) (m.CompareDashboardVersionsCommand, error) {
cmd := m.CompareDashboardVersionsCommand{}
func createCompareDashboardVersionCommand(c *middleware.Context) (*m.CompareDashboardVersionsCommand, error) {
cmd := &m.CompareDashboardVersionsCommand{}
dashboardIdStr := c.Params(":dashboardId")
dashboardId, err := strconv.Atoi(dashboardIdStr)
if err != nil {
return cmd, err
dashId := c.ParamsInt64(":dashboardId")
if dashId == 0 {
return nil, errors.New("Missing dashboardId")
}
versionStrings := strings.Split(c.Params(":versions"), "...")
if len(versionStrings) != 2 {
return cmd, fmt.Errorf("bad format: urls should be in the format /versions/0...1")
return nil, fmt.Errorf("bad format: urls should be in the format /versions/0...1")
}
originalDash, err := strconv.Atoi(versionStrings[0])
BaseVersion, err := strconv.Atoi(versionStrings[0])
if err != nil {
return cmd, fmt.Errorf("bad format: first argument is not of type int")
return nil, fmt.Errorf("bad format: first argument is not of type int")
}
newDash, err := strconv.Atoi(versionStrings[1])
newVersion, err := strconv.Atoi(versionStrings[1])
if err != nil {
return cmd, fmt.Errorf("bad format: second argument is not of type int")
return nil, fmt.Errorf("bad format: second argument is not of type int")
}
cmd.DashboardId = int64(dashboardId)
cmd.DashboardId = dashId
cmd.OrgId = c.OrgId
cmd.Original = originalDash
cmd.New = newDash
cmd.BaseVersion = BaseVersion
cmd.NewVersion = newVersion
return cmd, nil
}
......@@ -360,6 +361,7 @@ func CompareDashboardVersions(c *middleware.Context) Response {
if err != nil {
return ApiError(500, err.Error(), err)
}
cmd.DiffType = m.DiffDelta
if err := bus.Dispatch(&cmd); err != nil {
......@@ -376,8 +378,8 @@ func CompareDashboardVersions(c *middleware.Context) Response {
return Json(200, util.DynMap{
"meta": util.DynMap{
"original": cmd.Original,
"new": cmd.New,
"baseVersion": cmd.BaseVersion,
"newVersion": cmd.NewVersion,
},
"delta": deltaMap,
})
......@@ -392,7 +394,7 @@ func CompareDashboardVersionsJSON(c *middleware.Context) Response {
}
cmd.DiffType = m.DiffJSON
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.Dispatch(cmd); err != nil {
return ApiError(500, err.Error(), err)
}
......@@ -406,9 +408,10 @@ func CompareDashboardVersionsBasic(c *middleware.Context) Response {
if err != nil {
return ApiError(500, err.Error(), err)
}
cmd.DiffType = m.DiffBasic
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.Dispatch(cmd); err != nil {
return ApiError(500, err.Error(), err)
}
......
......@@ -86,8 +86,8 @@ type GetDashboardVersionsQuery struct {
type CompareDashboardVersionsCommand struct {
OrgId int64
DashboardId int64
Original int
New int
BaseVersion int
NewVersion int
DiffType DiffType
Delta []byte `json:"delta"`
......
......@@ -30,17 +30,17 @@ func init() {
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// assigning the delta of the diff to the `Delta` field.
func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) error {
original, err := getDashboardVersion(cmd.DashboardId, cmd.Original)
baseVersion, err := getDashboardVersion(cmd.DashboardId, cmd.BaseVersion)
if err != nil {
return err
}
newDashboard, err := getDashboardVersion(cmd.DashboardId, cmd.New)
newVersion, err := getDashboardVersion(cmd.DashboardId, cmd.NewVersion)
if err != nil {
return err
}
left, jsonDiff, err := getDiff(original, newDashboard)
left, jsonDiff, err := getDiff(baseVersion, newVersion)
if err != nil {
return err
}
......
......@@ -117,8 +117,8 @@ func TestCompareDashboardVersions(t *testing.T) {
cmd := m.CompareDashboardVersionsCommand{
DashboardId: savedDash.Id,
Original: query.Result[0].Version,
New: query.Result[1].Version,
BaseVersion: query.Result[0].Version,
NewVersion: query.Result[1].Version,
DiffType: m.DiffDelta,
}
......@@ -130,8 +130,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey("Compare two versions that are the same", func() {
cmd := m.CompareDashboardVersionsCommand{
DashboardId: savedDash.Id,
Original: savedDash.Version,
New: savedDash.Version,
BaseVersion: savedDash.Version,
NewVersion: savedDash.Version,
DiffType: m.DiffDelta,
}
......@@ -143,8 +143,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey("Compare two versions that don't exist", func() {
cmd := m.CompareDashboardVersionsCommand{
DashboardId: savedDash.Id,
Original: 123,
New: 456,
BaseVersion: 123,
NewVersion: 456,
DiffType: m.DiffDelta,
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment