From 22e288bf98323b58325708d718aab63d46eba1b1 Mon Sep 17 00:00:00 2001 From: Rogee Date: Sat, 20 Dec 2025 11:52:08 +0800 Subject: [PATCH] feat: update phone validation --- backend_v1/app/http/auth.go | 28 +++++++++++++++---- backend_v1/app/http/provider.gen.go | 7 +++++ backend_v1/app/http/routes.gen.go | 8 ++++++ backend_v1/docs/docs.go | 43 +++++++++++++++-------------- backend_v1/docs/swagger.json | 43 +++++++++++++++-------------- backend_v1/docs/swagger.yaml | 27 ++++++++++-------- 6 files changed, 100 insertions(+), 56 deletions(-) diff --git a/backend_v1/app/http/auth.go b/backend_v1/app/http/auth.go index 953f93f..69772f5 100644 --- a/backend_v1/app/http/auth.go +++ b/backend_v1/app/http/auth.go @@ -18,11 +18,11 @@ type auth struct{} // @Summary 手机验证 // @Tags Auth // @Produce json -// @Success 200 {object} requests.Pager{items=PostItem} "成功" -// @Router /v1/auth/:phone [post] -// @Bind phone path -func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error { - _, err := services.Users.FindByPhone(ctx, phone) +// @Success 200 {object} any "成功" +// @Router /v1/auth/phone [post] +// @Bind phone body +func (ctl *posts) Phone(ctx fiber.Ctx, form *PhoneValidation) error { + _, err := services.Users.FindByPhone(ctx, form.Phone) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return errors.New("手机号未注册,请联系管理员开通") @@ -32,3 +32,21 @@ func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error { // TODO: send sms return nil } + +type PhoneValidation struct { + Phone string `json:"phone,omitempty"` + Code *string `json:"code,omitempty"` +} + +// Validate +// +// @Summary 手机验证 +// @Tags Auth +// @Produce json +// @Success 200 {object} any "成功" +// @Router /v1/auth/validate [post] +// @Bind phone body +func (ctl *posts) Validate(ctx fiber.Ctx, form *PhoneValidation) error { + // TODO: send sms + return nil +} diff --git a/backend_v1/app/http/provider.gen.go b/backend_v1/app/http/provider.gen.go index 7ad428e..5f13578 100755 --- a/backend_v1/app/http/provider.gen.go +++ b/backend_v1/app/http/provider.gen.go @@ -13,6 +13,13 @@ import ( ) func Provide(opts ...opt.Option) error { + if err := container.Container.Provide(func() (*auth, error) { + obj := &auth{} + + return obj, nil + }); err != nil { + return err + } if err := container.Container.Provide(func( app *app.Config, job *job.Job, diff --git a/backend_v1/app/http/routes.gen.go b/backend_v1/app/http/routes.gen.go index 107868c..3b2c75e 100644 --- a/backend_v1/app/http/routes.gen.go +++ b/backend_v1/app/http/routes.gen.go @@ -78,6 +78,14 @@ func (r *Routes) Register(router fiber.Router) { Query[ListQuery]("query"), Local[*models.User]("user"), )) + r.log.Debugf("Registering route: Post /v1/auth/phone -> posts.Phone") + router.Post("/v1/auth/phone"[len(r.Path()):], Func0( + r.posts.Phone, + )) + r.log.Debugf("Registering route: Post /v1/auth/validate -> posts.Validate") + router.Post("/v1/auth/validate"[len(r.Path()):], Func0( + r.posts.Validate, + )) r.log.Debugf("Registering route: Post /v1/posts/:id/buy -> posts.Buy") router.Post("/v1/posts/:id/buy"[len(r.Path()):], DataFunc2( r.posts.Buy, diff --git a/backend_v1/docs/docs.go b/backend_v1/docs/docs.go index b6a0be2..9622c27 100644 --- a/backend_v1/docs/docs.go +++ b/backend_v1/docs/docs.go @@ -698,7 +698,7 @@ const docTemplate = `{ } } }, - "/v1/auth/{phone}": { + "/v1/auth/phone": { "post": { "produces": [ "application/json" @@ -710,21 +710,24 @@ const docTemplate = `{ "responses": { "200": { "description": "成功", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/requests.Pager" - }, - { - "type": "object", - "properties": { - "items": { - "$ref": "#/definitions/http.PostItem" - } - } - } - ] - } + "schema": {} + } + } + } + }, + "/v1/auth/validate": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "手机验证", + "responses": { + "200": { + "description": "成功", + "schema": {} } } } @@ -1379,10 +1382,7 @@ const docTemplate = `{ "type": "integer" }, "metas": { - "type": "array", - "items": { - "type": "integer" - } + "$ref": "#/definitions/types.JSONType-fields_MediaMetas" }, "mime_type": { "type": "string" @@ -1589,6 +1589,9 @@ const docTemplate = `{ "types.JSONType-array_string": { "type": "object" }, + "types.JSONType-fields_MediaMetas": { + "type": "object" + }, "types.JSONType-fields_OrderMeta": { "type": "object" }, diff --git a/backend_v1/docs/swagger.json b/backend_v1/docs/swagger.json index 986147c..f8746cf 100644 --- a/backend_v1/docs/swagger.json +++ b/backend_v1/docs/swagger.json @@ -692,7 +692,7 @@ } } }, - "/v1/auth/{phone}": { + "/v1/auth/phone": { "post": { "produces": [ "application/json" @@ -704,21 +704,24 @@ "responses": { "200": { "description": "成功", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/requests.Pager" - }, - { - "type": "object", - "properties": { - "items": { - "$ref": "#/definitions/http.PostItem" - } - } - } - ] - } + "schema": {} + } + } + } + }, + "/v1/auth/validate": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "手机验证", + "responses": { + "200": { + "description": "成功", + "schema": {} } } } @@ -1373,10 +1376,7 @@ "type": "integer" }, "metas": { - "type": "array", - "items": { - "type": "integer" - } + "$ref": "#/definitions/types.JSONType-fields_MediaMetas" }, "mime_type": { "type": "string" @@ -1583,6 +1583,9 @@ "types.JSONType-array_string": { "type": "object" }, + "types.JSONType-fields_MediaMetas": { + "type": "object" + }, "types.JSONType-fields_OrderMeta": { "type": "object" }, diff --git a/backend_v1/docs/swagger.yaml b/backend_v1/docs/swagger.yaml index fbaca07..ee4e1da 100644 --- a/backend_v1/docs/swagger.yaml +++ b/backend_v1/docs/swagger.yaml @@ -229,9 +229,7 @@ definitions: id: type: integer metas: - items: - type: integer - type: array + $ref: '#/definitions/types.JSONType-fields_MediaMetas' mime_type: type: string name: @@ -367,6 +365,8 @@ definitions: type: object types.JSONType-array_string: type: object + types.JSONType-fields_MediaMetas: + type: object types.JSONType-fields_OrderMeta: type: object types.JSONType-fields_UserAuthToken: @@ -830,20 +830,25 @@ paths: summary: 调整用户余额 tags: - Admin Users - /v1/auth/{phone}: + /v1/auth/phone: post: produces: - application/json responses: "200": description: 成功 - schema: - allOf: - - $ref: '#/definitions/requests.Pager' - - properties: - items: - $ref: '#/definitions/http.PostItem' - type: object + schema: {} + summary: 手机验证 + tags: + - Auth + /v1/auth/validate: + post: + produces: + - application/json + responses: + "200": + description: 成功 + schema: {} summary: 手机验证 tags: - Auth