mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Refactor api handlers to use web.Bind (#42199)
* Chore: Refactor api handlers to use web.Bind * fix comments * fix comment * trying to fix most of the tests and force routing.Wrap type check * fix library panels tests * fix frontend logging tests * allow passing nil as a response to skip writing * return nil instead of the response * rewrite login handler function types * remove handlerFuncCtx * make linter happy * remove old bindings from the libraryelements * restore comments
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
@@ -30,7 +31,11 @@ func GetPendingOrgInvites(c *models.ReqContext) response.Response {
|
||||
return response.JSON(200, query.Result)
|
||||
}
|
||||
|
||||
func AddOrgInvite(c *models.ReqContext, inviteDto dtos.AddInviteForm) response.Response {
|
||||
func AddOrgInvite(c *models.ReqContext) response.Response {
|
||||
inviteDto := dtos.AddInviteForm{}
|
||||
if err := web.Bind(c.Req, &inviteDto); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
if !inviteDto.Role.IsValid() {
|
||||
return response.Error(400, "Invalid role specified", nil)
|
||||
}
|
||||
@@ -165,7 +170,11 @@ func GetInviteInfoByCode(c *models.ReqContext) response.Response {
|
||||
})
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) CompleteInvite(c *models.ReqContext, completeInvite dtos.CompleteInviteForm) response.Response {
|
||||
func (hs *HTTPServer) CompleteInvite(c *models.ReqContext) response.Response {
|
||||
completeInvite := dtos.CompleteInviteForm{}
|
||||
if err := web.Bind(c.Req, &completeInvite); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
query := models.GetTempUserByCodeQuery{Code: completeInvite.InviteCode}
|
||||
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user