feat: add user_list
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
type TenantFilter struct {
|
||||
@@ -35,3 +36,7 @@ func (form *TenantExpireUpdateForm) ParseDuration() (time.Duration, error) {
|
||||
}
|
||||
return duration, nil
|
||||
}
|
||||
|
||||
type TenantStatusUpdateForm struct {
|
||||
Status consts.TenantStatus `json:"status" validate:"required,oneof=normal disabled"`
|
||||
}
|
||||
|
||||
20
backend/app/http/super/dto/user.go
Normal file
20
backend/app/http/super/dto/user.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
)
|
||||
|
||||
type UserPageFilter struct {
|
||||
requests.Pagination
|
||||
requests.SortQueryFilter
|
||||
|
||||
Username *string `query:"username"`
|
||||
TenantID *int64 `query:"tenant_id"`
|
||||
}
|
||||
|
||||
type UserItem struct {
|
||||
*models.User
|
||||
|
||||
StatusDescription string `json:"status_description,omitempty"`
|
||||
}
|
||||
@@ -26,13 +26,13 @@ func Provide(opts ...opt.Option) error {
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
authController *authController,
|
||||
staticController *staticController,
|
||||
tenant *tenant,
|
||||
user *user,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
authController: authController,
|
||||
staticController: staticController,
|
||||
tenant: tenant,
|
||||
authController: authController,
|
||||
tenant: tenant,
|
||||
user: user,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
@@ -56,5 +56,12 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*user, error) {
|
||||
obj := &user{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
@@ -21,9 +20,9 @@ import (
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
// Controller instances
|
||||
authController *authController
|
||||
staticController *staticController
|
||||
tenant *tenant
|
||||
authController *authController
|
||||
tenant *tenant
|
||||
user *user
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
@@ -59,8 +58,18 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantExpireUpdateForm]("form"),
|
||||
))
|
||||
|
||||
router.Get("/super/*", Func(r.staticController.static))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID/status -> tenant.updateStatus")
|
||||
router.Patch("/super/v1/tenants/:tenantID/status", Func2(
|
||||
r.tenant.updateStatus,
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantStatusUpdateForm]("form"),
|
||||
))
|
||||
// Register routes for controller: user
|
||||
r.log.Debugf("Registering route: Get /super/v1/users -> user.list")
|
||||
router.Get("/super/v1/users", DataFunc1(
|
||||
r.user.list,
|
||||
Query[dto.UserPageFilter]("filter"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type staticController struct{}
|
||||
|
||||
// Static
|
||||
//
|
||||
// @Tags Super
|
||||
// @Router /super/*
|
||||
func (ctl *staticController) static(ctx fiber.Ctx) error {
|
||||
root := "/home/rogee/Projects/quyun_v2/frontend/superadmin/dist/"
|
||||
param := ctx.Params("*")
|
||||
file := filepath.Join(root, param)
|
||||
// // Static
|
||||
// //
|
||||
// // @Tags Super
|
||||
// // @Router /super/*
|
||||
// func (ctl *staticController) static(ctx fiber.Ctx) error {
|
||||
// root := "/home/rogee/Projects/quyun_v2/frontend/superadmin/dist/"
|
||||
// param := ctx.Params("*")
|
||||
// file := filepath.Join(root, param)
|
||||
|
||||
// if file not exits use index.html
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
file = filepath.Join(root, "index.html")
|
||||
}
|
||||
// // if file not exits use index.html
|
||||
// if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
// file = filepath.Join(root, "index.html")
|
||||
// }
|
||||
|
||||
return ctx.SendFile(file)
|
||||
}
|
||||
// return ctx.SendFile(file)
|
||||
// }
|
||||
|
||||
@@ -47,3 +47,19 @@ func (*tenant) updateExpire(ctx fiber.Ctx, tenantID int64, form *dto.TenantExpir
|
||||
|
||||
return services.Tenant.AddExpireDuration(ctx, tenantID, duration)
|
||||
}
|
||||
|
||||
// updateStatus
|
||||
//
|
||||
// @Summary 更新租户状态
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantID path int64 true "TenantID"
|
||||
// @Param form body dto.TenantStatusUpdateForm true "Form"
|
||||
//
|
||||
// @Router /super/v1/tenants/:tenantID/status [patch]
|
||||
// @Bind tenantID path
|
||||
// @Bind form body
|
||||
func (*tenant) updateStatus(ctx fiber.Ctx, tenantID int64, form *dto.TenantStatusUpdateForm) error {
|
||||
return services.Tenant.UpdateStatus(ctx, tenantID, form.Status)
|
||||
}
|
||||
|
||||
28
backend/app/http/super/user.go
Normal file
28
backend/app/http/super/user.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
_ "quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type user struct{}
|
||||
|
||||
// list
|
||||
//
|
||||
// @Summary 租户列表
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param filter query dto.UserPageFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=dto.UserItem}
|
||||
//
|
||||
// @Router /super/v1/users [get]
|
||||
// @Bind filter query
|
||||
func (*user) list(ctx fiber.Ctx, filter *dto.UserPageFilter) (*requests.Pager, error) {
|
||||
return services.User.Page(ctx, filter)
|
||||
}
|
||||
Reference in New Issue
Block a user