Skip to content

Commit 5e089b2

Browse files
committed
feat: add APi Routes
1 parent 2e531fe commit 5e089b2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: services/core/db/metadata-db.go

+12
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,15 @@ func (db Database) UpdateWidgetDashboards(widgetID string, dashboardIDs []string
290290
// Replace the dashboards associated with the widget
291291
return db.orm.Model(&widget).Association("Dashboards").Replace(dashboards)
292292
}
293+
294+
// get all public widgets
295+
func (db Database) GetAllPublicWidgets() ([]models.Widget, error) {
296+
var widgets []models.Widget
297+
err := db.orm.
298+
Where("is_public = ?", true).
299+
Find(&widgets).Error
300+
if err != nil {
301+
return nil, err
302+
}
303+
return widgets, nil
304+
}

Diff for: services/core/http_routes.go

+20
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ func (h *HttpHandler) Register(r *echo.Echo) {
121121
v4.POST("/layout/set", httpserver.AuthorizeHandler(h.SetUserLayout, api3.ViewerRole))
122122
v4.POST("/layout/change-privacy", httpserver.AuthorizeHandler(h.ChangePrivacy, api3.ViewerRole))
123123
v4.GET("/layout/public", httpserver.AuthorizeHandler(h.GetPublicLayouts, api3.ViewerRole))
124+
v4.POST("/layout/widget/get", httpserver.AuthorizeHandler(h.GetUserWidgets, api3.ViewerRole))
125+
v4.POST("/layout/widget/get/public", httpserver.AuthorizeHandler(h.GetAllPublicWidgets, api3.ViewerRole))
126+
v4.GET("/layout/widget/get/:id", httpserver.AuthorizeHandler(h.GetWidget, api3.ViewerRole))
127+
v4.DELETE("/layout/widget/delete/:id", httpserver.AuthorizeHandler(h.DeleteUserWidget, api3.ViewerRole))
128+
v4.POST("/layout/update/widget", httpserver.AuthorizeHandler(h.UpdateDashboardWidgets, api3.ViewerRole))
129+
v4.POST("/layout/widget/update", httpserver.AuthorizeHandler(h.UpdateWidgetDashboards, api3.ViewerRole))
130+
131+
132+
v4.POST("/layout/widget/set", httpserver.AuthorizeHandler(h.SetUserWidget, api3.ViewerRole))
124133
// Chatbot
125134
v4.GET("/chatbot/agents", httpserver.AuthorizeHandler(h.GetAgents, api3.ViewerRole))
126135
v4.POST("/chatbot/generate-query", httpserver.AuthorizeHandler(h.GenerateQuery, api3.ViewerRole))
@@ -1857,3 +1866,14 @@ func (h *HttpHandler) UpdateWidgetDashboards(echoCtx echo.Context) error {
18571866

18581867
return echoCtx.NoContent(http.StatusOK)
18591868
}
1869+
1870+
// GetAllPublicWidgets returns all public widgets
1871+
func (h *HttpHandler) GetAllPublicWidgets(echoCtx echo.Context) error {
1872+
widgets, err := h.db.GetAllPublicWidgets()
1873+
if err != nil {
1874+
h.logger.Error("failed to fetch public widgets", zap.Error(err))
1875+
return echo.NewHTTPError(http.StatusInternalServerError, "failed to fetch public widgets")
1876+
}
1877+
1878+
return echoCtx.JSON(http.StatusOK, widgets)
1879+
}

0 commit comments

Comments
 (0)