mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 11:12:58 +08:00
Query history: Create API to add query to query history (#44479)
* 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
This commit is contained in:
31
pkg/services/queryhistory/api.go
Normal file
31
pkg/services/queryhistory/api.go
Normal file
@ -0,0 +1,31 @@
|
||||
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")
|
||||
}
|
Reference in New Issue
Block a user