diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-06-19 06:32:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-19 06:32:45 +0800 |
commit | 43c7a2e7b1c7fb8aa2347d82ad0a6886d6fad9c2 (patch) | |
tree | c98c2e1159ee02eb52282811f28a4c31ad222c67 /routers/api/v1/user | |
parent | 17baf1af10de025a47ade1f16f1e5c51646d7fcf (diff) | |
download | gitea-43c7a2e7b1c7fb8aa2347d82ad0a6886d6fad9c2.tar.gz gitea-43c7a2e7b1c7fb8aa2347d82ad0a6886d6fad9c2.zip |
Refactor names (#31405)
This PR only does "renaming":
* `Route` should be `Router` (and chi router is also called "router")
* `Params` should be `PathParam` (to distingush it from URL query param, and to match `FormString`)
* Use lower case for private functions to avoid exposing or abusing
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r-- | routers/api/v1/user/action.go | 14 | ||||
-rw-r--r-- | routers/api/v1/user/app.go | 8 | ||||
-rw-r--r-- | routers/api/v1/user/gpg_key.go | 4 | ||||
-rw-r--r-- | routers/api/v1/user/helper.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/hook.go | 6 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 6 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 2 |
7 files changed, 21 insertions, 21 deletions
diff --git a/routers/api/v1/user/action.go b/routers/api/v1/user/action.go index bf78c2c864..22707196f4 100644 --- a/routers/api/v1/user/action.go +++ b/routers/api/v1/user/action.go @@ -49,7 +49,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) { opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) - _, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.Params("secretname"), opt.Data) + _, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data) if err != nil { if errors.Is(err, util.ErrInvalidArgument) { ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err) @@ -91,7 +91,7 @@ func DeleteSecret(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.Params("secretname")) + err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname")) if err != nil { if errors.Is(err, util.ErrInvalidArgument) { ctx.Error(http.StatusBadRequest, "DeleteSecret", err) @@ -138,7 +138,7 @@ func CreateVariable(ctx *context.APIContext) { opt := web.GetForm(ctx).(*api.CreateVariableOption) ownerID := ctx.Doer.ID - variableName := ctx.Params("variablename") + variableName := ctx.PathParam("variablename") v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{ OwnerID: ownerID, @@ -198,7 +198,7 @@ func UpdateVariable(ctx *context.APIContext) { v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{ OwnerID: ctx.Doer.ID, - Name: ctx.Params("variablename"), + Name: ctx.PathParam("variablename"), }) if err != nil { if errors.Is(err, util.ErrNotExist) { @@ -210,7 +210,7 @@ func UpdateVariable(ctx *context.APIContext) { } if opt.Name == "" { - opt.Name = ctx.Params("variablename") + opt.Name = ctx.PathParam("variablename") } if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil { if errors.Is(err, util.ErrInvalidArgument) { @@ -247,7 +247,7 @@ func DeleteVariable(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.Params("variablename")); err != nil { + if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("variablename")); err != nil { if errors.Is(err, util.ErrInvalidArgument) { ctx.Error(http.StatusBadRequest, "DeleteVariableByName", err) } else if errors.Is(err, util.ErrNotExist) { @@ -284,7 +284,7 @@ func GetVariable(ctx *context.APIContext) { v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{ OwnerID: ctx.Doer.ID, - Name: ctx.Params("variablename"), + Name: ctx.PathParam("variablename"), }) if err != nil { if errors.Is(err, util.ErrNotExist) { diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index 88e314ed31..60354b1f26 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -160,7 +160,7 @@ func DeleteAccessToken(ctx *context.APIContext) { // "422": // "$ref": "#/responses/error" - token := ctx.Params(":id") + token := ctx.PathParam(":id") tokenID, _ := strconv.ParseInt(token, 0, 64) if tokenID == 0 { @@ -300,7 +300,7 @@ func DeleteOauth2Application(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/notFound" - appID := ctx.ParamsInt64(":id") + appID := ctx.PathParamInt64(":id") if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil { if auth_model.IsErrOAuthApplicationNotFound(err) { ctx.NotFound() @@ -332,7 +332,7 @@ func GetOauth2Application(ctx *context.APIContext) { // "$ref": "#/responses/OAuth2Application" // "404": // "$ref": "#/responses/notFound" - appID := ctx.ParamsInt64(":id") + appID := ctx.PathParamInt64(":id") app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID) if err != nil { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { @@ -376,7 +376,7 @@ func UpdateOauth2Application(ctx *context.APIContext) { // "$ref": "#/responses/OAuth2Application" // "404": // "$ref": "#/responses/notFound" - appID := ctx.ParamsInt64(":id") + appID := ctx.PathParamInt64(":id") data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions) diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index 5a2f995e1b..ba5c0fdc45 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -116,7 +116,7 @@ func GetGPGKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.ParamsInt64(":id")) + key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64(":id")) if err != nil { if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.NotFound() @@ -280,7 +280,7 @@ func DeleteGPGKey(ctx *context.APIContext) { return } - if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil { + if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64(":id")); err != nil { if asymkey_model.IsErrGPGKeyAccessDenied(err) { ctx.Error(http.StatusForbidden, "", "You do not have access to this key") } else { diff --git a/routers/api/v1/user/helper.go b/routers/api/v1/user/helper.go index 8b5c64e291..23a526cd67 100644 --- a/routers/api/v1/user/helper.go +++ b/routers/api/v1/user/helper.go @@ -12,7 +12,7 @@ import ( // GetUserByParamsName get user by name func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User { - username := ctx.Params(name) + username := ctx.PathParam(name) user, err := user_model.GetUserByName(ctx, username) if err != nil { if user_model.IsErrUserNotExist(err) { diff --git a/routers/api/v1/user/hook.go b/routers/api/v1/user/hook.go index 9d9ca5bf01..b4605c8a29 100644 --- a/routers/api/v1/user/hook.go +++ b/routers/api/v1/user/hook.go @@ -57,7 +57,7 @@ func GetHook(ctx *context.APIContext) { // "200": // "$ref": "#/responses/Hook" - hook, err := utils.GetOwnerHook(ctx, ctx.Doer.ID, ctx.ParamsInt64("id")) + hook, err := utils.GetOwnerHook(ctx, ctx.Doer.ID, ctx.PathParamInt64("id")) if err != nil { return } @@ -129,7 +129,7 @@ func EditHook(ctx *context.APIContext) { ctx, ctx.Doer, web.GetForm(ctx).(*api.EditHookOption), - ctx.ParamsInt64("id"), + ctx.PathParamInt64("id"), ) } @@ -154,6 +154,6 @@ func DeleteHook(ctx *context.APIContext) { utils.DeleteOwnerHook( ctx, ctx.Doer, - ctx.ParamsInt64("id"), + ctx.PathParamInt64("id"), ) } diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index d9456e7ec6..e4278c2ec0 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -55,7 +55,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) { var count int fingerprint := ctx.FormString("fingerprint") - username := ctx.Params("username") + username := ctx.PathParam("username") if fingerprint != "" { var userID int64 // Unrestricted @@ -179,7 +179,7 @@ func GetPublicKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.ParamsInt64(":id")) + key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64(":id")) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.NotFound() @@ -274,7 +274,7 @@ func DeletePublicKey(ctx *context.APIContext) { return } - id := ctx.ParamsInt64(":id") + id := ctx.PathParamInt64(":id") externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 09147cd2ae..fedad87fc4 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -113,7 +113,7 @@ func GetInfo(ctx *context.APIContext) { if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { // fake ErrUserNotExist error message to not leak information about existence - ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")}) + ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam(":username")}) return } ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer)) |