Commit 22c001c8 by bergquist

fix(playlist): implement api according to new standard

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