feat: 添加用户和租户状态管理功能,包括状态列表和状态更新接口
This commit is contained in:
@@ -3,6 +3,7 @@ package dto
|
||||
import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
type UserPageFilter struct {
|
||||
@@ -18,3 +19,7 @@ type UserItem struct {
|
||||
|
||||
StatusDescription string `json:"status_description,omitempty"`
|
||||
}
|
||||
|
||||
type UserStatusUpdateForm struct {
|
||||
Status consts.UserStatus `json:"status" validate:"required,oneof=normal disabled"`
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
r.tenant.list,
|
||||
Query[dto.TenantFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /super/v1/tenants/statuses -> tenant.statusList")
|
||||
router.Get("/super/v1/tenants/statuses", DataFunc0(
|
||||
r.tenant.statusList,
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID -> tenant.updateExpire")
|
||||
router.Patch("/super/v1/tenants/:tenantID", Func2(
|
||||
r.tenant.updateExpire,
|
||||
@@ -70,6 +74,16 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
r.user.list,
|
||||
Query[dto.UserPageFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /super/v1/users/statuses -> user.statusList")
|
||||
router.Get("/super/v1/users/statuses", DataFunc0(
|
||||
r.user.statusList,
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/users/:userID/status -> user.updateStatus")
|
||||
router.Patch("/super/v1/users/:userID/status", Func2(
|
||||
r.user.updateStatus,
|
||||
PathParam[int64]("userID"),
|
||||
Body[dto.UserStatusUpdateForm]("form"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -63,3 +65,20 @@ func (*tenant) updateExpire(ctx fiber.Ctx, tenantID int64, form *dto.TenantExpir
|
||||
func (*tenant) updateStatus(ctx fiber.Ctx, tenantID int64, form *dto.TenantStatusUpdateForm) error {
|
||||
return services.Tenant.UpdateStatus(ctx, tenantID, form.Status)
|
||||
}
|
||||
|
||||
// statusList
|
||||
//
|
||||
// @Summary 租户状态列表
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} requests.KV
|
||||
//
|
||||
// @Router /super/v1/tenants/statuses [get]
|
||||
// @Bind userID path
|
||||
// @Bind form body
|
||||
func (*tenant) statusList(ctx fiber.Ctx) ([]requests.KV, error) {
|
||||
return lo.Map(consts.TenantStatusValues(), func(item consts.TenantStatus, _ int) requests.KV {
|
||||
return requests.NewKV(item.String(), item.Description())
|
||||
}), nil
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
_ "quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -26,3 +28,36 @@ type user struct{}
|
||||
func (*user) list(ctx fiber.Ctx, filter *dto.UserPageFilter) (*requests.Pager, error) {
|
||||
return services.User.Page(ctx, filter)
|
||||
}
|
||||
|
||||
// updateStatus
|
||||
//
|
||||
// @Summary 更新用户状态
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param userID path int64 true "UserID"
|
||||
// @Param form body dto.UserStatusUpdateForm true "Form"
|
||||
//
|
||||
// @Router /super/v1/users/:userID/status [patch]
|
||||
// @Bind userID path
|
||||
// @Bind form body
|
||||
func (*user) updateStatus(ctx fiber.Ctx, userID int64, form *dto.UserStatusUpdateForm) error {
|
||||
return services.User.UpdateStatus(ctx, userID, form.Status)
|
||||
}
|
||||
|
||||
// statusList
|
||||
//
|
||||
// @Summary 用户状态列表
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} requests.KV
|
||||
//
|
||||
// @Router /super/v1/users/statuses [get]
|
||||
// @Bind userID path
|
||||
// @Bind form body
|
||||
func (*user) statusList(ctx fiber.Ctx) ([]requests.KV, error) {
|
||||
return lo.Map(consts.UserStatusValues(), func(item consts.UserStatus, _ int) requests.KV {
|
||||
return requests.NewKV(item.String(), item.Description())
|
||||
}), nil
|
||||
}
|
||||
|
||||
10
backend/app/requests/label.go
Normal file
10
backend/app/requests/label.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package requests
|
||||
|
||||
type KV struct {
|
||||
Key string `json:"key,omitempty"`
|
||||
Value any `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
func NewKV(k string, v any) KV {
|
||||
return KV{Key: k, Value: v}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
@@ -88,3 +89,21 @@ func (t *user) Page(ctx context.Context, filter *dto.UserPageFilter) (*requests.
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateStatus
|
||||
func (t *user) UpdateStatus(ctx context.Context, userID int64, status consts.UserStatus) error {
|
||||
logrus.WithField("user_id", userID).WithField("status", status).Info("update user status")
|
||||
|
||||
m, err := t.FindByID(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.Status = status
|
||||
_, err = m.Update(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -117,6 +117,31 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/tenants/statuses": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "租户状态列表",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/requests.KV"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/tenants/{tenantID}": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
@@ -250,6 +275,65 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/users/statuses": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "用户状态列表",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/requests.KV"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/users/{userID}/status": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "更新用户状态",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "UserID",
|
||||
"name": "userID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Form",
|
||||
"name": "form",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.UserStatusUpdateForm"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
@@ -452,6 +536,25 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.UserStatusUpdateForm": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"status"
|
||||
],
|
||||
"properties": {
|
||||
"status": {
|
||||
"enum": [
|
||||
"normal",
|
||||
"disabled"
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.UserStatus"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"gorm.DeletedAt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -558,6 +661,15 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"requests.KV": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
"requests.Pager": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -111,6 +111,31 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/tenants/statuses": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "租户状态列表",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/requests.KV"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/tenants/{tenantID}": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
@@ -244,6 +269,65 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/users/statuses": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "用户状态列表",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/requests.KV"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/super/v1/users/{userID}/status": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "更新用户状态",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "UserID",
|
||||
"name": "userID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Form",
|
||||
"name": "form",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.UserStatusUpdateForm"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
@@ -446,6 +530,25 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.UserStatusUpdateForm": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"status"
|
||||
],
|
||||
"properties": {
|
||||
"status": {
|
||||
"enum": [
|
||||
"normal",
|
||||
"disabled"
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.UserStatus"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"gorm.DeletedAt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -552,6 +655,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"requests.KV": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
"requests.Pager": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -134,6 +134,17 @@ definitions:
|
||||
verified_at:
|
||||
type: string
|
||||
type: object
|
||||
dto.UserStatusUpdateForm:
|
||||
properties:
|
||||
status:
|
||||
allOf:
|
||||
- $ref: '#/definitions/consts.UserStatus'
|
||||
enum:
|
||||
- normal
|
||||
- disabled
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
gorm.DeletedAt:
|
||||
properties:
|
||||
time:
|
||||
@@ -204,6 +215,12 @@ definitions:
|
||||
verified_at:
|
||||
type: string
|
||||
type: object
|
||||
requests.KV:
|
||||
properties:
|
||||
key:
|
||||
type: string
|
||||
value: {}
|
||||
type: object
|
||||
requests.Pager:
|
||||
properties:
|
||||
items: {}
|
||||
@@ -332,6 +349,22 @@ paths:
|
||||
summary: 更新租户状态
|
||||
tags:
|
||||
- Super
|
||||
/super/v1/tenants/statuses:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/requests.KV'
|
||||
type: array
|
||||
summary: 租户状态列表
|
||||
tags:
|
||||
- Super
|
||||
/super/v1/users:
|
||||
get:
|
||||
consumes:
|
||||
@@ -370,6 +403,45 @@ paths:
|
||||
summary: 租户列表
|
||||
tags:
|
||||
- Super
|
||||
/super/v1/users/{userID}/status:
|
||||
patch:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: UserID
|
||||
format: int64
|
||||
in: path
|
||||
name: userID
|
||||
required: true
|
||||
type: integer
|
||||
- description: Form
|
||||
in: body
|
||||
name: form
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.UserStatusUpdateForm'
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
summary: 更新用户状态
|
||||
tags:
|
||||
- Super
|
||||
/super/v1/users/statuses:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/requests.KV'
|
||||
type: array
|
||||
summary: 用户状态列表
|
||||
tags:
|
||||
- Super
|
||||
securityDefinitions:
|
||||
BasicAuth:
|
||||
type: basic
|
||||
|
||||
Reference in New Issue
Block a user