From 3ff17c2c0e1d1146761a07f5f4d552f4b2fc2812 Mon Sep 17 00:00:00 2001 From: Ke Chen Date: Thu, 11 Jul 2024 14:23:37 +0800 Subject: [PATCH] feat: put routes add equivalent patch routes --- apis/account.go | 1 + apis/routes.go | 3 ++ apis/shamir.go | 1 + apis/user.go | 1 + docs/docs.go | 134 +++++++++++++++++++++++++++++++++++++++++++--- docs/swagger.json | 131 ++++++++++++++++++++++++++++++++++++++++++-- docs/swagger.yaml | 92 ++++++++++++++++++++++++++++--- 7 files changed, 343 insertions(+), 20 deletions(-) diff --git a/apis/account.go b/apis/account.go index 8083554..809b15e 100644 --- a/apis/account.go +++ b/apis/account.go @@ -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 "验证码错误" diff --git a/apis/routes.go b/apis/routes.go index df37b3b..7eba13e 100644 --- a/apis/routes.go +++ b/apis/routes.go @@ -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) @@ -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/_modify", ModifyUser) // shamir routes.Get("/shamir/status", GetShamirStatus) @@ -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) diff --git a/apis/shamir.go b/apis/shamir.go index 6330547..5d32c10 100644 --- a/apis/shamir.go +++ b/apis/shamir.go @@ -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 diff --git a/apis/user.go b/apis/user.go index 9d5d292..188f5bb 100644 --- a/apis/user.go +++ b/apis/user.go @@ -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 "不是管理员" diff --git a/docs/docs.go b/docs/docs.go index 728d9fc..7ab6435 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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" @@ -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": { @@ -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": { @@ -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", @@ -1442,6 +1549,9 @@ const docTemplate = `{ }, "apis.LoginRequest": { "type": "object", + "required": [ + "password" + ], "properties": { "email": { "description": "email in email blacklist", @@ -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": { @@ -1587,6 +1697,9 @@ const docTemplate = `{ }, "apis.RegisterRequest": { "type": "object", + "required": [ + "password" + ], "properties": { "email": { "description": "email in email blacklist", @@ -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": { diff --git a/docs/swagger.json b/docs/swagger.json index 4fc43c8..c7b9795 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -314,6 +314,50 @@ } } } + }, + "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": { @@ -703,6 +747,29 @@ } } } + }, + "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": { @@ -1166,6 +1233,47 @@ } } }, + "/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", @@ -1435,6 +1543,9 @@ }, "apis.LoginRequest": { "type": "object", + "required": [ + "password" + ], "properties": { "email": { "description": "email in email blacklist", @@ -1468,11 +1579,11 @@ "type": "string" }, "answer": { - "description": "答案描述,单选、判断、多选\n如果是单选题,则只有一个答案\n如果是多选题,则有一个或多个答案\n如果是判断题,则只有一个答案,且只能是 true 或者 false", + "description": "答案索引,单选、判断、多选,从 0 开始", "type": "array", "minItems": 1, "items": { - "type": "string" + "type": "integer" } }, "group": { @@ -1580,6 +1691,9 @@ }, "apis.RegisterRequest": { "type": "object", + "required": [ + "password" + ], "properties": { "email": { "description": "email in email blacklist", @@ -1791,12 +1905,19 @@ "field": { "type": "string" }, - "tag": { + "message": { "type": "string" }, - "value": { + "param": { "type": "string" - } + }, + "struct_field": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "value": {} } }, "common.HttpError": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0cc9580..000934a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -73,6 +73,8 @@ definitions: password: minLength: 8 type: string + required: + - password type: object apis.PGPMessageResponse: properties: @@ -87,13 +89,9 @@ definitions: description: 题目解析,预留,可选 type: string answer: - description: |- - 答案描述,单选、判断、多选 - 如果是单选题,则只有一个答案 - 如果是多选题,则有一个或多个答案 - 如果是判断题,则只有一个答案,且只能是 true 或者 false + description: 答案索引,单选、判断、多选,从 0 开始 items: - type: string + type: integer minItems: 1 type: array group: @@ -186,6 +184,8 @@ definitions: type: string verification: type: string + required: + - password type: object apis.ShamirStatusResponse: properties: @@ -318,10 +318,15 @@ definitions: properties: field: type: string - tag: + message: + type: string + param: type: string - value: + struct_field: + type: string + tag: type: string + value: {} type: object common.HttpError: properties: @@ -517,6 +522,35 @@ paths: tags: - token /register: + patch: + consumes: + - application/json + description: reset password, reset jwt credential + parameters: + - description: json + in: body + name: json + required: true + schema: + $ref: '#/definitions/apis.RegisterRequest' + produces: + - application/json + 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' + summary: reset password + tags: + - account post: consumes: - application/json @@ -841,6 +875,21 @@ paths: tags: - shamir /shamir/refresh: + patch: + responses: + "204": + description: No Content + "403": + description: 非管理员 + schema: + $ref: '#/definitions/common.MessageResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.MessageResponse' + summary: trigger for refresh uploaded shares + tags: + - shamir put: responses: "204": @@ -1052,6 +1101,33 @@ paths: summary: modify user tags: - user + /users/{user_id}/_modify: + patch: + description: modify user, owner or admin + parameters: + - description: UserID + in: path + name: user_id + required: true + type: integer + produces: + - application/json + 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' + summary: modify user + tags: + - user /users/admin: get: produces: