mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 21:12:37 +08:00

* Create config to enable/disable query history * Create add to query history functionality * Add documentation * Add test * Refactor * Add test * Fix built errors and linting errors * Refactor * Remove old tests * Refactor, adjust based on feedback, add new test * Update default value
32 lines
973 B
Go
32 lines
973 B
Go
package queryhistory
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
func (s *QueryHistoryService) registerAPIEndpoints() {
|
|
s.RouteRegister.Group("/api/query-history", func(entities routing.RouteRegister) {
|
|
entities.Post("/", middleware.ReqSignedIn, routing.Wrap(s.createHandler))
|
|
})
|
|
}
|
|
|
|
func (s *QueryHistoryService) createHandler(c *models.ReqContext) response.Response {
|
|
cmd := CreateQueryInQueryHistoryCommand{}
|
|
if err := web.Bind(c.Req, &cmd); err != nil {
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
}
|
|
|
|
err := s.CreateQueryInQueryHistory(c.Req.Context(), c.SignedInUser, cmd)
|
|
if err != nil {
|
|
return response.Error(500, "Failed to create query history", err)
|
|
}
|
|
|
|
return response.Success("Query successfully added to query history")
|
|
}
|