85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package super
|
|
|
|
import (
|
|
"quyun/v2/app/errorx"
|
|
"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
|
|
type tenant struct{}
|
|
|
|
// list
|
|
//
|
|
// @Summary 租户列表
|
|
// @Tags Super
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param filter query dto.TenantFilter true "Filter"
|
|
// @Success 200 {object} requests.Pager{items=dto.TenantItem}
|
|
//
|
|
// @Router /super/v1/tenants [get]
|
|
// @Bind filter query
|
|
func (*tenant) list(ctx fiber.Ctx, filter *dto.TenantFilter) (*requests.Pager, error) {
|
|
return services.Tenant.Pager(ctx, filter)
|
|
}
|
|
|
|
// updateExpire
|
|
//
|
|
// @Summary 更新过期时间
|
|
// @Tags Super
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param tenantID path int64 true "TenantID"
|
|
// @Param form body dto.TenantExpireUpdateForm true "Form"
|
|
//
|
|
// @Router /super/v1/tenants/:tenantID [patch]
|
|
// @Bind tenantID path
|
|
// @Bind form body
|
|
func (*tenant) updateExpire(ctx fiber.Ctx, tenantID int64, form *dto.TenantExpireUpdateForm) error {
|
|
duration, err := form.ParseDuration()
|
|
if err != nil {
|
|
return errorx.Wrap(err).WithMsg("时间解析出错")
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
// 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
|
|
}
|