package super import ( "quyun/v2/app/errorx" "quyun/v2/app/http/super/dto" tenantdto "quyun/v2/app/http/tenant/dto" "quyun/v2/app/requests" "quyun/v2/app/services" "quyun/v2/database/models" "quyun/v2/pkg/consts" "github.com/gofiber/fiber/v3" ) // @provider type tenant struct{} // detail // // @Summary 租户详情 // @Tags Super // @Accept json // @Produce json // @Param tenantID path int64 true "TenantID" // @Success 200 {object} dto.TenantItem // // @Router /super/v1/tenants/:tenantID [get] // @Bind tenantID path func (*tenant) detail(ctx fiber.Ctx, tenantID int64) (*dto.TenantItem, error) { return services.Tenant.SuperDetail(ctx, tenantID) } // 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) } // create // // @Summary 创建租户并设置租户管理员 // @Tags Super // @Accept json // @Produce json // @Param form body dto.TenantCreateForm true "Form" // @Success 200 {object} models.Tenant // // @Router /super/v1/tenants [post] // @Bind form body func (*tenant) create(ctx fiber.Ctx, form *dto.TenantCreateForm) (*models.Tenant, error) { return services.Tenant.SuperCreateTenant(ctx, form) } // users // // @Summary 租户成员列表(平台侧) // @Tags Super // @Accept json // @Produce json // @Param tenantID path int64 true "TenantID" // @Param filter query tenantdto.AdminTenantUserListFilter true "Filter" // @Success 200 {object} requests.Pager{items=dto.SuperTenantUserItem} // // @Router /super/v1/tenants/:tenantID/users [get] // @Bind tenantID path // @Bind filter query func (*tenant) users(ctx fiber.Ctx, tenantID int64, filter *tenantdto.AdminTenantUserListFilter) (*requests.Pager, error) { return services.Tenant.SuperTenantUsersPage(ctx, tenantID, 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 consts.TenantStatusItems(), nil }