Added support for delete dashboard
This commit is contained in:
@@ -8,25 +8,49 @@ import (
|
||||
|
||||
func init() {
|
||||
addRoutes(func(self *HttpServer) {
|
||||
self.router.GET("/api/dashboards/:id", self.auth(), self.getDashboard)
|
||||
self.router.GET("/api/dashboards/:slug", self.auth(), self.getDashboard)
|
||||
self.router.GET("/api/search/", self.auth(), self.search)
|
||||
self.router.POST("/api/dashboard", self.auth(), self.postDashboard)
|
||||
self.router.DELETE("/api/dashboard/:slug", self.auth(), self.deleteDashboard)
|
||||
})
|
||||
}
|
||||
|
||||
func (self *HttpServer) getDashboard(c *gin.Context) {
|
||||
id := c.Params.ByName("id")
|
||||
slug := c.Params.ByName("slug")
|
||||
accountId, err := c.Get("accountId")
|
||||
|
||||
dash, err := self.store.GetDashboard(id, accountId.(int))
|
||||
dash, err := self.store.GetDashboard(slug, accountId.(int))
|
||||
if err != nil {
|
||||
c.JSON(404, newErrorResponse("Dashboard not found"))
|
||||
return
|
||||
}
|
||||
|
||||
dash.Data["id"] = dash.Id
|
||||
|
||||
c.JSON(200, dash.Data)
|
||||
}
|
||||
|
||||
func (self *HttpServer) deleteDashboard(c *gin.Context) {
|
||||
slug := c.Params.ByName("slug")
|
||||
accountId, err := c.Get("accountId")
|
||||
|
||||
dash, err := self.store.GetDashboard(slug, accountId.(int))
|
||||
if err != nil {
|
||||
c.JSON(404, newErrorResponse("Dashboard not found"))
|
||||
return
|
||||
}
|
||||
|
||||
err = self.store.DeleteDashboard(slug, accountId.(int))
|
||||
if err != nil {
|
||||
c.JSON(500, newErrorResponse("Failed to delete dashboard: "+err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
var resp = map[string]interface{}{"title": dash.Title}
|
||||
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
|
||||
func (self *HttpServer) search(c *gin.Context) {
|
||||
query := c.Params.ByName("q")
|
||||
accountId, err := c.Get("accountId")
|
||||
|
||||
Reference in New Issue
Block a user