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

This commit is contained in:
Sofia Papagiannaki
2022-07-27 09:54:37 -04:00
committed by GitHub
parent c968b76279
commit 7ba076de10
76 changed files with 6022 additions and 6161 deletions
+91 -6
View File
@@ -47,7 +47,14 @@ func (hs *HTTPServer) SetHomeDashboard(c *models.ReqContext) response.Response {
return response.Success("Home dashboard set")
}
// GET /api/user/preferences
// swagger:route GET /user/preferences user_preferences getUserPreferences
//
// Get user preferences.
//
// Responses:
// 200: getPreferencesResponse
// 401: unauthorisedError
// 500: internalServerError
func (hs *HTTPServer) GetUserPreferences(c *models.ReqContext) response.Response {
return hs.getPreferencesFor(c.Req.Context(), c.OrgId, c.UserId, 0)
}
@@ -88,7 +95,17 @@ func (hs *HTTPServer) getPreferencesFor(ctx context.Context, orgID, userID, team
return response.JSON(http.StatusOK, &dto)
}
// PUT /api/user/preferences
// swagger:route PUT /user/preferences user_preferences updateUserPreferences
//
// Update user preferences.
//
// Omitting a key (`theme`, `homeDashboardId`, `timezone`) will cause the current value to be replaced with the system default value.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 500: internalServerError
func (hs *HTTPServer) UpdateUserPreferences(c *models.ReqContext) response.Response {
dtoCmd := dtos.UpdatePrefsCmd{}
if err := web.Bind(c.Req, &dtoCmd); err != nil {
@@ -133,7 +150,15 @@ func (hs *HTTPServer) updatePreferencesFor(ctx context.Context, orgID, userID, t
return response.Success("Preferences updated")
}
// PATCH /api/user/preferences
// swagger:route PATCH /user/preferences user_preferences patchUserPreferences
//
// Patch user preferences.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 500: internalServerError
func (hs *HTTPServer) PatchUserPreferences(c *models.ReqContext) response.Response {
dtoCmd := dtos.PatchPrefsCmd{}
if err := web.Bind(c.Req, &dtoCmd); err != nil {
@@ -179,12 +204,29 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
return response.Success("Preferences updated")
}
// GET /api/org/preferences
// swagger:route GET /org/preferences org_preferences getOrgPreferences
//
// Get Current Org Prefs.
//
// Responses:
// 200: getPreferencesResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) GetOrgPreferences(c *models.ReqContext) response.Response {
return hs.getPreferencesFor(c.Req.Context(), c.OrgId, 0, 0)
}
// PUT /api/org/preferences
// swagger:route PUT /org/preferences org_preferences updateOrgPreferences
//
// Update Current Org Prefs.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) UpdateOrgPreferences(c *models.ReqContext) response.Response {
dtoCmd := dtos.UpdatePrefsCmd{}
if err := web.Bind(c.Req, &dtoCmd); err != nil {
@@ -194,7 +236,16 @@ func (hs *HTTPServer) UpdateOrgPreferences(c *models.ReqContext) response.Respon
return hs.updatePreferencesFor(c.Req.Context(), c.OrgId, 0, 0, &dtoCmd)
}
// PATCH /api/org/preferences
// swagger:route PATCH /org/preferences org_preferences patchOrgPreferences
//
// Patch Current Org Prefs.
//
// Responses:
// 200: okResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (hs *HTTPServer) PatchOrgPreferences(c *models.ReqContext) response.Response {
dtoCmd := dtos.PatchPrefsCmd{}
if err := web.Bind(c.Req, &dtoCmd); err != nil {
@@ -202,3 +253,37 @@ func (hs *HTTPServer) PatchOrgPreferences(c *models.ReqContext) response.Respons
}
return hs.patchPreferencesFor(c.Req.Context(), c.OrgId, 0, 0, &dtoCmd)
}
// swagger:parameters updateUserPreferences
type UpdateUserPreferencesParams struct {
// in:body
// required:true
Body dtos.UpdatePrefsCmd `json:"body"`
}
// swagger:parameters updateOrgPreferences
type UpdateOrgPreferencesParams struct {
// in:body
// required:true
Body dtos.UpdatePrefsCmd `json:"body"`
}
// swagger:response getPreferencesResponse
type GetPreferencesResponse struct {
// in:body
Body dtos.Prefs `json:"body"`
}
// swagger:parameters patchUserPreferences
type PatchUserPreferencesParams struct {
// in:body
// required:true
Body dtos.PatchPrefsCmd `json:"body"`
}
// swagger:parameters patchOrgPreferences
type PatchOrgPreferencesParams struct {
// in:body
// required:true
Body dtos.PatchPrefsCmd `json:"body"`
}