Commit 22c001c8 by bergquist

fix(playlist): implement api according to new standard

parent d15b0bf4
...@@ -174,12 +174,12 @@ func Register(r *macaron.Macaron) { ...@@ -174,12 +174,12 @@ func Register(r *macaron.Macaron) {
// Playlist // Playlist
r.Group("/playlists", func() { r.Group("/playlists", func() {
r.Get("/", SearchPlaylists) r.Get("/", wrap(SearchPlaylists))
r.Get("/:id", ValidateOrgPlaylist, GetPlaylist) r.Get("/:id", ValidateOrgPlaylist, wrap(GetPlaylist))
r.Get("/:id/dashboards", ValidateOrgPlaylist, GetPlaylistDashboards) r.Get("/:id/dashboards", ValidateOrgPlaylist, wrap(GetPlaylistDashboards))
r.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, DeletePlaylist) r.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, wrap(DeletePlaylist))
r.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistQuery{}), ValidateOrgPlaylist, UpdatePlaylist) r.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistQuery{}), ValidateOrgPlaylist, wrap(UpdatePlaylist))
r.Post("/", reqEditorRole, bind(m.CreatePlaylistQuery{}), CreatePlaylist) r.Post("/", reqEditorRole, bind(m.CreatePlaylistQuery{}), wrap(CreatePlaylist))
}) })
// Search // Search
......
...@@ -22,7 +22,7 @@ func ValidateOrgPlaylist(c *middleware.Context) { ...@@ -22,7 +22,7 @@ func ValidateOrgPlaylist(c *middleware.Context) {
} }
} }
func SearchPlaylists(c *middleware.Context) { func SearchPlaylists(c *middleware.Context) Response {
query := c.Query("query") query := c.Query("query")
limit := c.QueryInt("limit") limit := c.QueryInt("limit")
...@@ -38,66 +38,60 @@ func SearchPlaylists(c *middleware.Context) { ...@@ -38,66 +38,60 @@ func SearchPlaylists(c *middleware.Context) {
err := bus.Dispatch(&searchQuery) err := bus.Dispatch(&searchQuery)
if err != nil { if err != nil {
c.JsonApiErr(500, "Search failed", err) return ApiError(500, "Search failed", err)
return
} }
c.JSON(200, searchQuery.Result) return Json(200, searchQuery.Result)
} }
func GetPlaylist(c *middleware.Context) { func GetPlaylist(c *middleware.Context) Response {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
cmd := m.GetPlaylistByIdQuery{Id: id} cmd := m.GetPlaylistByIdQuery{Id: id}
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Playlist not found", err) return ApiError(500, "Playlist not found", err)
return
} }
c.JSON(200, cmd.Result) return Json(200, cmd.Result)
} }
func GetPlaylistDashboards(c *middleware.Context) { func GetPlaylistDashboards(c *middleware.Context) Response {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
query := m.GetPlaylistDashboardsQuery{Id: id} query := m.GetPlaylistDashboardsQuery{Id: id}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
c.JsonApiErr(500, "Playlist not found", err) return ApiError(500, "Playlist not found", err)
return
} }
c.JSON(200, query.Result) return Json(200, query.Result)
} }
func DeletePlaylist(c *middleware.Context) { func DeletePlaylist(c *middleware.Context) Response {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
cmd := m.DeletePlaylistQuery{Id: id} cmd := m.DeletePlaylistQuery{Id: id}
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to delete playlist", err) return ApiError(500, "Failed to delete playlist", err)
return
} }
c.JSON(200, "") return Json(200, "")
} }
func CreatePlaylist(c *middleware.Context, query m.CreatePlaylistQuery) { func CreatePlaylist(c *middleware.Context, query m.CreatePlaylistQuery) Response {
query.OrgId = c.OrgId query.OrgId = c.OrgId
err := bus.Dispatch(&query) err := bus.Dispatch(&query)
if err != nil { if err != nil {
c.JsonApiErr(500, "Failed to create playlist", err) return ApiError(500, "Failed to create playlist", err)
return
} }
c.JSON(200, query.Result) return Json(200, query.Result)
} }
func UpdatePlaylist(c *middleware.Context, query m.UpdatePlaylistQuery) { func UpdatePlaylist(c *middleware.Context, query m.UpdatePlaylistQuery) Response {
err := bus.Dispatch(&query) err := bus.Dispatch(&query)
if err != nil { if err != nil {
c.JsonApiErr(500, "Failed to save playlist", err) return ApiError(500, "Failed to save playlist", err)
return
} }
c.JSON(200, query.Result) return Json(200, query.Result)
} }
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