Chore: Move swagger definitions to the handlers (#52643)

This commit is contained in:
Sofia Papagiannaki
2022-07-27 16:54:37 +03:00
committed by GitHub
parent c968b76279
commit 7ba076de10
76 changed files with 6022 additions and 6161 deletions
+250 -9
View File
@@ -15,12 +15,31 @@ import (
"github.com/grafana/grafana/pkg/web"
)
// GET /api/org
// swagger:route GET /org org getCurrentOrg
//
// Get current Organization
//
// Responses:
// 200: getCurrentOrgResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) GetCurrentOrg(c *models.ReqContext) response.Response {
return hs.getOrgHelper(c.Req.Context(), c.OrgId)
}
// GET /api/orgs/:orgId
// swagger:route GET /orgs/{org_id} orgs getOrgByID
//
// Get Organization by ID.
//
// Security:
// - basic:
//
// Responses:
// 200: getOrgByIDResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) GetOrgByID(c *models.ReqContext) response.Response {
orgId, err := strconv.ParseInt(web.Params(c.Req)[":orgId"], 10, 64)
if err != nil {
@@ -29,7 +48,18 @@ func (hs *HTTPServer) GetOrgByID(c *models.ReqContext) response.Response {
return hs.getOrgHelper(c.Req.Context(), orgId)
}
// GET /api/orgs/name/:name
// swagger:route GET /orgs/name/{org_name} orgs getOrgByName
//
// Get Organization by ID.
//
// Security:
// - basic:
//
// Responses:
// 200: getOrgByNameResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
org, err := hs.SQLStore.GetOrgByName(web.Params(c.Req)[":name"])
if err != nil {
@@ -82,7 +112,18 @@ func (hs *HTTPServer) getOrgHelper(ctx context.Context, orgID int64) response.Re
return response.JSON(http.StatusOK, &result)
}
// POST /api/orgs
// swagger:route POST /orgs orgs createOrg
//
// Create Organization.
//
// Only works if [users.allow_org_create](https://grafana.com/docs/grafana/latest/administration/configuration/#allow_org_create) is set.
//
// Responses:
// 200: createOrgResponse
// 401: unauthorisedError
// 403: forbiddenError
// 409: conflictError
// 500: internalServerError
func (hs *HTTPServer) CreateOrg(c *models.ReqContext) response.Response {
cmd := models.CreateOrgCommand{}
if err := web.Bind(c.Req, &cmd); err != nil {
@@ -109,7 +150,16 @@ func (hs *HTTPServer) CreateOrg(c *models.ReqContext) response.Response {
})
}
// PUT /api/org
// swagger:route PUT /org org updateCurrentOrg
//
// Update current Organization.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) UpdateCurrentOrg(c *models.ReqContext) response.Response {
form := dtos.UpdateOrgForm{}
if err := web.Bind(c.Req, &form); err != nil {
@@ -118,7 +168,19 @@ func (hs *HTTPServer) UpdateCurrentOrg(c *models.ReqContext) response.Response {
return hs.updateOrgHelper(c.Req.Context(), form, c.OrgId)
}
// PUT /api/orgs/:orgId
// swagger:route PUT /orgs/{org_id} orgs updateOrg
//
// Update Organization.
//
// Security:
// - basic:
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) UpdateOrg(c *models.ReqContext) response.Response {
form := dtos.UpdateOrgForm{}
if err := web.Bind(c.Req, &form); err != nil {
@@ -143,7 +205,16 @@ func (hs *HTTPServer) updateOrgHelper(ctx context.Context, form dtos.UpdateOrgFo
return response.Success("Organization updated")
}
// PUT /api/org/address
// swagger:route PUT /org/address org updateCurrentOrgAddress
//
// Update current Organization's address.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) UpdateCurrentOrgAddress(c *models.ReqContext) response.Response {
form := dtos.UpdateOrgAddressForm{}
if err := web.Bind(c.Req, &form); err != nil {
@@ -152,7 +223,16 @@ func (hs *HTTPServer) UpdateCurrentOrgAddress(c *models.ReqContext) response.Res
return hs.updateOrgAddressHelper(c.Req.Context(), form, c.OrgId)
}
// PUT /api/orgs/:orgId/address
// swagger:route PUT /orgs/{org_id}/address orgs updateOrgAddress
//
// Update Organization's address.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) UpdateOrgAddress(c *models.ReqContext) response.Response {
form := dtos.UpdateOrgAddressForm{}
if err := web.Bind(c.Req, &form); err != nil {
@@ -185,7 +265,20 @@ func (hs *HTTPServer) updateOrgAddressHelper(ctx context.Context, form dtos.Upda
return response.Success("Address updated")
}
// DELETE /api/orgs/:orgId
// swagger:route DELETE /orgs/{org_id} orgs deleteOrgByID
//
// Delete Organization.
//
// Security:
// - basic:
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 404: notFoundError
// 500: internalServerError
func (hs *HTTPServer) DeleteOrgByID(c *models.ReqContext) response.Response {
orgID, err := strconv.ParseInt(web.Params(c.Req)[":orgId"], 10, 64)
if err != nil {
@@ -205,6 +298,19 @@ func (hs *HTTPServer) DeleteOrgByID(c *models.ReqContext) response.Response {
return response.Success("Organization deleted")
}
// swagger:route GET /orgs orgs searchOrgs
//
// Search all Organizations
//
// Security:
// - basic:
//
// Responses:
// 200: searchOrgsResponse
// 401: unauthorisedError
// 403: forbiddenError
// 409: conflictError
// 500: internalServerError
func (hs *HTTPServer) SearchOrgs(c *models.ReqContext) response.Response {
perPage := c.QueryInt("perpage")
if perPage <= 0 {
@@ -226,3 +332,138 @@ func (hs *HTTPServer) SearchOrgs(c *models.ReqContext) response.Response {
return response.JSON(http.StatusOK, query.Result)
}
// swagger:parameters updateCurrentOrgAddress
type UpdateCurrentOrgAddressParams struct {
// in:body
// required:true
Body dtos.UpdateOrgAddressForm `json:"body"`
}
// swagger:parameters updateCurrentOrgUser
type UpdateCurrentOrgUserParams struct {
// in:body
// required:true
Body models.UpdateOrgUserCommand `json:"body"`
// in:path
// required:true
UserID int64 `json:"user_id"`
}
// swagger:parameters updateCurrentOrg
type UpdateCurrentOrgParams struct {
// in:body
// required:true
Body dtos.UpdateOrgForm `json:"body"`
}
// swagger:parameters updateOrgAddress
type UpdateOrgAddressParams struct {
// in:body
// required:true
Body dtos.UpdateOrgAddressForm `json:"body"`
// in:path
// required:true
OrgID int64 `json:"org_id"`
}
// swagger:parameters getOrgByID
type GetOrgByIDParams struct {
// in:path
// required:true
OrgID int64 `json:"org_id"`
}
// swagger:parameters deleteOrgByID
type DeleteOrgByIDParams struct {
// in:path
// required:true
OrgID int64 `json:"org_id"`
}
// swagger:parameters updateOrg
type UpdateOrgParams struct {
// in:body
// required:true
Body dtos.UpdateOrgForm `json:"body"`
// in:path
// required:true
OrgID int64 `json:"org_id"`
}
// swagger:parameters getOrgByName
type GetOrgByNameParams struct {
// in:path
// required:true
OrgName string `json:"org_name"`
}
// swagger:parameters createOrg
type CreateOrgParams struct {
// in:body
// required:true
Body models.CreateOrgCommand `json:"body"`
}
// swagger:parameters searchOrgs
type SearchOrgParams struct {
// in:query
// required:false
// default: 1
Page int `json:"page"`
// Number of items per page
// The totalCount field in the response can be used for pagination list E.g. if totalCount is equal to 100 teams and the perpage parameter is set to 10 then there are 10 pages of teams.
// in:query
// required:false
// default: 1000
PerPage int `json:"perpage"`
Name string `json:"name"`
// If set it will return results where the query value is contained in the name field. Query values with spaces need to be URL encoded.
// required:false
Query string `json:"query"`
}
// swagger:response createOrgResponse
type CreateOrgResponse struct {
// The response message
// in: body
Body struct {
// ID Identifier of the created org.
// required: true
// example: 65
OrgID int64 `json:"orgId"`
// Message Message of the created org.
// required: true
// example: Data source added
Message string `json:"message"`
} `json:"body"`
}
// swagger:response searchOrgsResponse
type SearchOrgsResponse struct {
// The response message
// in: body
Body []*models.OrgDTO `json:"body"`
}
// swagger:response getCurrentOrgResponse
type GetCurrentOrgResponse struct {
// The response message
// in: body
Body models.OrgDetailsDTO `json:"body"`
}
// swagger:response getOrgByIDResponse
type GetOrgByIDResponse struct {
// The response message
// in: body
Body models.OrgDetailsDTO `json:"body"`
}
// swagger:response getOrgByNameResponse
type GetOrgByNameResponse struct {
// The response message
// in: body
Body models.OrgDetailsDTO `json:"body"`
}