Files
quyun-v2/backend/app/http/super/user.go

109 lines
2.7 KiB
Go

package super
import (
"quyun/v2/app/http/super/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
_ "quyun/v2/database/models"
"quyun/v2/pkg/consts"
"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)
}
// tenants
//
// @Summary 用户加入的租户列表
// @Tags Super
// @Accept json
// @Produce json
// @Param userID path int64 true "UserID"
// @Param filter query dto.UserTenantPageFilter true "Filter"
// @Success 200 {object} requests.Pager{items=dto.UserTenantItem}
//
// @Router /super/v1/users/:userID/tenants [get]
// @Bind userID path
// @Bind filter query
func (*user) tenants(ctx fiber.Ctx, userID int64, filter *dto.UserTenantPageFilter) (*requests.Pager, error) {
return services.User.TenantsPage(ctx, userID, 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)
}
// updateRoles
//
// @Summary 更新用户角色
// @Tags Super
// @Accept json
// @Produce json
// @Param userID path int64 true "UserID"
// @Param form body dto.UserRolesUpdateForm true "Form"
//
// @Router /super/v1/users/:userID/roles [patch]
// @Bind userID path
// @Bind form body
func (*user) updateRoles(ctx fiber.Ctx, userID int64, form *dto.UserRolesUpdateForm) error {
return services.User.UpdateRoles(ctx, userID, form.Roles)
}
// 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 consts.UserStatusItems(), nil
}
// statistics
//
// @Summary 用户统计信息
// @Tags Super
// @Accept json
// @Produce json
// @Success 200 {array} dto.UserStatistics
//
// @Router /super/v1/users/statistics [get]
// @Bind userID path
// @Bind form body
func (*user) statistics(ctx fiber.Ctx) ([]*dto.UserStatistics, error) {
return services.User.Statistics(ctx)
}