Skip to content

Commit

Permalink
feat: put routes add equivalent patch routes
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYiJun committed Jul 11, 2024
1 parent d6692f7 commit 3ff17c2
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 20 deletions.
1 change: 1 addition & 0 deletions apis/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func register(c *fiber.Ctx, email, password string, batch bool) error {
// @Accept json
// @Produce json
// @Router /register [put]
// @Router /register [patch]
// @Param json body RegisterRequest true "json"
// @Success 200 {object} TokenResponse
// @Failure 400 {object} common.MessageResponse "验证码错误"
Expand Down
3 changes: 3 additions & 0 deletions apis/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func RegisterRoutes(app *fiber.App) {
routes.Get("/verify/apikey", VerifyWithApikey)
routes.Post("/register", Register)
routes.Put("/register", ChangePassword)
routes.Patch("/register", ChangePassword)
routes.Delete("/users/me", DeleteUser)
routes.Delete("/users/:id", DeleteUserByID)

Expand All @@ -52,6 +53,7 @@ func RegisterRoutes(app *fiber.App) {
routes.Get("/users/:id", GetUserByID)
routes.Get("/users", ListUsers)
routes.Put("/users/:id", ModifyUser)
routes.Patch("/users/:id<int>/_modify", ModifyUser)

// shamir
routes.Get("/shamir/status", GetShamirStatus)
Expand All @@ -61,6 +63,7 @@ func RegisterRoutes(app *fiber.App) {
routes.Post("/shamir/key", UploadPublicKey)
routes.Post("/shamir/update", UpdateShamir)
routes.Put("/shamir/refresh", RefreshShamir)
routes.Patch("/shamir/refresh", RefreshShamir)
routes.Post("/shamir/decrypt", UploadUserShares)
routes.Get("/shamir/decrypt/:id", GetDecryptedUserEmail)
routes.Get("/shamir/decrypt/status/:id", GetDecryptStatusbyUserID)
Expand Down
1 change: 1 addition & 0 deletions apis/shamir.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func UpdateShamir(c *fiber.Ctx) error {
// @Summary trigger for refresh uploaded shares
// @Tags shamir
// @Router /shamir/refresh [put]
// @Router /shamir/refresh [patch]
// @Success 204
// @Failure 403 {object} common.MessageResponse "非管理员"
// @failure 500 {object} common.MessageResponse
Expand Down
1 change: 1 addition & 0 deletions apis/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func ListAdmin(c *fiber.Ctx) error {
// @Tags user
// @Produce json
// @Router /users/{user_id} [put]
// @Router /users/{user_id}/_modify [patch]
// @Param user_id path int true "UserID"
// @Success 201 {object} User
// @Failure 403 {object} common.MessageResponse "不是管理员"
Expand Down
134 changes: 127 additions & 7 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -321,6 +320,50 @@ const docTemplate = `{
}
}
}
},
"patch": {
"description": "reset password, reset jwt credential",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"account"
],
"summary": "reset password",
"parameters": [
{
"description": "json",
"name": "json",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apis.RegisterRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/apis.TokenResponse"
}
},
"400": {
"description": "验证码错误",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
}
}
}
},
"/register/questions": {
Expand Down Expand Up @@ -710,6 +753,29 @@ const docTemplate = `{
}
}
}
},
"patch": {
"tags": [
"shamir"
],
"summary": "trigger for refresh uploaded shares",
"responses": {
"204": {
"description": "No Content"
},
"403": {
"description": "非管理员",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
}
}
}
},
"/shamir/shares": {
Expand Down Expand Up @@ -1173,6 +1239,47 @@ const docTemplate = `{
}
}
},
"/users/{user_id}/_modify": {
"patch": {
"description": "modify user, owner or admin",
"produces": [
"application/json"
],
"tags": [
"user"
],
"summary": "modify user",
"parameters": [
{
"type": "integer",
"description": "UserID",
"name": "user_id",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/models.User"
}
},
"403": {
"description": "不是管理员",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/common.MessageResponse"
}
}
}
}
},
"/verify/apikey": {
"get": {
"description": "verify with email in query, return verification code",
Expand Down Expand Up @@ -1442,6 +1549,9 @@ const docTemplate = `{
},
"apis.LoginRequest": {
"type": "object",
"required": [
"password"
],
"properties": {
"email": {
"description": "email in email blacklist",
Expand Down Expand Up @@ -1475,11 +1585,11 @@ const docTemplate = `{
"type": "string"
},
"answer": {
"description": "答案描述,单选、判断、多选\n如果是单选题,则只有一个答案\n如果是多选题,则有一个或多个答案\n如果是判断题,则只有一个答案,且只能是 true 或者 false",
"description": "答案索引,单选、判断、多选,从 0 开始",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
"type": "integer"
}
},
"group": {
Expand Down Expand Up @@ -1587,6 +1697,9 @@ const docTemplate = `{
},
"apis.RegisterRequest": {
"type": "object",
"required": [
"password"
],
"properties": {
"email": {
"description": "email in email blacklist",
Expand Down Expand Up @@ -1798,12 +1911,19 @@ const docTemplate = `{
"field": {
"type": "string"
},
"tag": {
"message": {
"type": "string"
},
"value": {
"param": {
"type": "string"
}
},
"struct_field": {
"type": "string"
},
"tag": {
"type": "string"
},
"value": {}
}
},
"common.HttpError": {
Expand Down
Loading

0 comments on commit 3ff17c2

Please sign in to comment.