tenant: add invites and join requests
This commit is contained in:
66
backend/app/http/tenant/dto/tenant_join_admin.go
Normal file
66
backend/app/http/tenant/dto/tenant_join_admin.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
// AdminTenantInviteCreateForm 租户管理员创建邀请码的请求参数。
|
||||
type AdminTenantInviteCreateForm struct {
|
||||
// Code 邀请码(可选):为空时由后端生成;建议只包含数字/字母,便于人工输入。
|
||||
Code string `json:"code"`
|
||||
|
||||
// MaxUses 最大可使用次数(可选):0 表示不限次数;大于 0 时用尽后自动失效。
|
||||
MaxUses *int `json:"max_uses"`
|
||||
|
||||
// ExpiresAt 过期时间(可选):为空表示不过期;到期后不可再使用。
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
|
||||
// Remark 备注(可选):用于审计记录生成目的/投放渠道等。
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
// AdminTenantInviteDisableForm 租户管理员禁用邀请码的请求参数。
|
||||
type AdminTenantInviteDisableForm struct {
|
||||
// Reason 禁用原因(可选):用于审计与追溯。
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// AdminTenantInviteListFilter 租户管理员分页查询邀请码列表的过滤条件。
|
||||
type AdminTenantInviteListFilter struct {
|
||||
requests.Pagination
|
||||
|
||||
// Status 按状态过滤(可选):active/disabled/expired。
|
||||
Status *consts.TenantInviteStatus `query:"status" json:"status"`
|
||||
|
||||
// Code 按邀请码模糊过滤(可选):支持部分匹配(like)。
|
||||
Code *string `query:"code" json:"code"`
|
||||
}
|
||||
|
||||
// CodeTrimmed 对 code 进行空白与大小写处理,便于统一查询。
|
||||
func (f *AdminTenantInviteListFilter) CodeTrimmed() string {
|
||||
if f == nil || f.Code == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.ToLower(strings.TrimSpace(*f.Code))
|
||||
}
|
||||
|
||||
// AdminTenantJoinRequestListFilter 租户管理员分页查询加入申请的过滤条件。
|
||||
type AdminTenantJoinRequestListFilter struct {
|
||||
requests.Pagination
|
||||
|
||||
// UserID 按申请人用户ID过滤(可选)。
|
||||
UserID *int64 `query:"user_id" json:"user_id"`
|
||||
|
||||
// Status 按申请状态过滤(可选):pending/approved/rejected。
|
||||
Status *consts.TenantJoinRequestStatus `query:"status" json:"status"`
|
||||
}
|
||||
|
||||
// AdminTenantJoinRequestDecideForm 租户管理员通过/拒绝加入申请的请求参数。
|
||||
type AdminTenantJoinRequestDecideForm struct {
|
||||
// Reason 审核说明(可选):用于审计记录通过/拒绝原因。
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
@@ -60,17 +60,21 @@ func Provide(opts ...opt.Option) error {
|
||||
order *order,
|
||||
orderAdmin *orderAdmin,
|
||||
orderMe *orderMe,
|
||||
tenantInviteAdmin *tenantInviteAdmin,
|
||||
tenantJoinAdmin *tenantJoinAdmin,
|
||||
tenantUserAdmin *tenantUserAdmin,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
content: content,
|
||||
contentAdmin: contentAdmin,
|
||||
me: me,
|
||||
middlewares: middlewares,
|
||||
order: order,
|
||||
orderAdmin: orderAdmin,
|
||||
orderMe: orderMe,
|
||||
tenantUserAdmin: tenantUserAdmin,
|
||||
content: content,
|
||||
contentAdmin: contentAdmin,
|
||||
me: me,
|
||||
middlewares: middlewares,
|
||||
order: order,
|
||||
orderAdmin: orderAdmin,
|
||||
orderMe: orderMe,
|
||||
tenantInviteAdmin: tenantInviteAdmin,
|
||||
tenantJoinAdmin: tenantJoinAdmin,
|
||||
tenantUserAdmin: tenantUserAdmin,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
@@ -80,6 +84,20 @@ func Provide(opts ...opt.Option) error {
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*tenantInviteAdmin, error) {
|
||||
obj := &tenantInviteAdmin{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*tenantJoinAdmin, error) {
|
||||
obj := &tenantJoinAdmin{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*tenantUserAdmin, error) {
|
||||
obj := &tenantUserAdmin{}
|
||||
|
||||
|
||||
@@ -24,13 +24,15 @@ type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
middlewares *middlewares.Middlewares
|
||||
// Controller instances
|
||||
content *content
|
||||
contentAdmin *contentAdmin
|
||||
me *me
|
||||
order *order
|
||||
orderAdmin *orderAdmin
|
||||
orderMe *orderMe
|
||||
tenantUserAdmin *tenantUserAdmin
|
||||
content *content
|
||||
contentAdmin *contentAdmin
|
||||
me *me
|
||||
order *order
|
||||
orderAdmin *orderAdmin
|
||||
orderMe *orderMe
|
||||
tenantInviteAdmin *tenantInviteAdmin
|
||||
tenantJoinAdmin *tenantJoinAdmin
|
||||
tenantUserAdmin *tenantUserAdmin
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
@@ -185,6 +187,53 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
Local[*models.User]("user"),
|
||||
PathParam[int64]("orderID"),
|
||||
))
|
||||
// Register routes for controller: tenantInviteAdmin
|
||||
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/admin/invites -> tenantInviteAdmin.adminInviteList")
|
||||
router.Get("/t/:tenantCode/v1/admin/invites"[len(r.Path()):], DataFunc3(
|
||||
r.tenantInviteAdmin.adminInviteList,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
Query[dto.AdminTenantInviteListFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /t/:tenantCode/v1/admin/invites/:inviteID/disable -> tenantInviteAdmin.adminDisableInvite")
|
||||
router.Patch("/t/:tenantCode/v1/admin/invites/:inviteID/disable"[len(r.Path()):], DataFunc4(
|
||||
r.tenantInviteAdmin.adminDisableInvite,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
PathParam[int64]("inviteID"),
|
||||
Body[dto.AdminTenantInviteDisableForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/invites -> tenantInviteAdmin.adminCreateInvite")
|
||||
router.Post("/t/:tenantCode/v1/admin/invites"[len(r.Path()):], DataFunc3(
|
||||
r.tenantInviteAdmin.adminCreateInvite,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
Body[dto.AdminTenantInviteCreateForm]("form"),
|
||||
))
|
||||
// Register routes for controller: tenantJoinAdmin
|
||||
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/admin/join-requests -> tenantJoinAdmin.adminJoinRequests")
|
||||
router.Get("/t/:tenantCode/v1/admin/join-requests"[len(r.Path()):], DataFunc3(
|
||||
r.tenantJoinAdmin.adminJoinRequests,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
Query[dto.AdminTenantJoinRequestListFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/join-requests/:requestID/approve -> tenantJoinAdmin.adminApproveJoinRequest")
|
||||
router.Post("/t/:tenantCode/v1/admin/join-requests/:requestID/approve"[len(r.Path()):], DataFunc4(
|
||||
r.tenantJoinAdmin.adminApproveJoinRequest,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
PathParam[int64]("requestID"),
|
||||
Body[dto.AdminTenantJoinRequestDecideForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/join-requests/:requestID/reject -> tenantJoinAdmin.adminRejectJoinRequest")
|
||||
router.Post("/t/:tenantCode/v1/admin/join-requests/:requestID/reject"[len(r.Path()):], DataFunc4(
|
||||
r.tenantJoinAdmin.adminRejectJoinRequest,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
PathParam[int64]("requestID"),
|
||||
Body[dto.AdminTenantJoinRequestDecideForm]("form"),
|
||||
))
|
||||
// Register routes for controller: tenantUserAdmin
|
||||
r.log.Debugf("Registering route: Delete /t/:tenantCode/v1/admin/users/:userID -> tenantUserAdmin.adminRemoveUser")
|
||||
router.Delete("/t/:tenantCode/v1/admin/users/:userID"[len(r.Path()):], Func3(
|
||||
|
||||
134
backend/app/http/tenant/tenant_invite_admin.go
Normal file
134
backend/app/http/tenant/tenant_invite_admin.go
Normal file
@@ -0,0 +1,134 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// tenantInviteAdmin 提供“租户管理员管理邀请码”的相关接口。
|
||||
//
|
||||
// @provider
|
||||
type tenantInviteAdmin struct{}
|
||||
|
||||
// adminCreateInvite
|
||||
//
|
||||
// @Summary 创建邀请码(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param form body dto.AdminTenantInviteCreateForm true "Form"
|
||||
// @Success 200 {object} models.TenantInvite
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/invites [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind form body
|
||||
func (*tenantInviteAdmin) adminCreateInvite(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
form *dto.AdminTenantInviteCreateForm,
|
||||
) (*models.TenantInvite, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
}).Info("tenant.admin.invites.create")
|
||||
|
||||
return services.Tenant.AdminCreateInvite(ctx.Context(), tenant.ID, tenantUser.UserID, form)
|
||||
}
|
||||
|
||||
// adminInviteList
|
||||
//
|
||||
// @Summary 邀请码列表(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param filter query dto.AdminTenantInviteListFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=models.TenantInvite}
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/invites [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind filter query
|
||||
func (*tenantInviteAdmin) adminInviteList(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
filter *dto.AdminTenantInviteListFilter,
|
||||
) (*requests.Pager, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.AdminTenantInviteListFilter{}
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"status": filter.Status,
|
||||
"code": filter.CodeTrimmed(),
|
||||
}).Info("tenant.admin.invites.list")
|
||||
|
||||
return services.Tenant.AdminInvitePage(ctx.Context(), tenant.ID, filter)
|
||||
}
|
||||
|
||||
// adminDisableInvite
|
||||
//
|
||||
// @Summary 禁用邀请码(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param inviteID path int64 true "InviteID"
|
||||
// @Param form body dto.AdminTenantInviteDisableForm true "Form"
|
||||
// @Success 200 {object} models.TenantInvite
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/invites/:inviteID/disable [patch]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind inviteID path
|
||||
// @Bind form body
|
||||
func (*tenantInviteAdmin) adminDisableInvite(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
inviteID int64,
|
||||
form *dto.AdminTenantInviteDisableForm,
|
||||
) (*models.TenantInvite, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if inviteID <= 0 {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("invite_id must be > 0")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"invite_id": inviteID,
|
||||
"disable_time": time.Now(),
|
||||
}).Info("tenant.admin.invites.disable")
|
||||
|
||||
return services.Tenant.AdminDisableInvite(ctx.Context(), tenant.ID, tenantUser.UserID, inviteID, form.Reason)
|
||||
}
|
||||
142
backend/app/http/tenant/tenant_join_admin.go
Normal file
142
backend/app/http/tenant/tenant_join_admin.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// tenantJoinAdmin 提供“租户管理员审核加入申请”的相关接口。
|
||||
//
|
||||
// @provider
|
||||
type tenantJoinAdmin struct{}
|
||||
|
||||
// adminJoinRequests
|
||||
//
|
||||
// @Summary 加入申请列表(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param filter query dto.AdminTenantJoinRequestListFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=models.TenantJoinRequest}
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/join-requests [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind filter query
|
||||
func (*tenantJoinAdmin) adminJoinRequests(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
filter *dto.AdminTenantJoinRequestListFilter,
|
||||
) (*requests.Pager, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.AdminTenantJoinRequestListFilter{}
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"status": filter.Status,
|
||||
"query_uid": filter.UserID,
|
||||
}).Info("tenant.admin.join_requests.list")
|
||||
|
||||
return services.Tenant.AdminJoinRequestPage(ctx.Context(), tenant.ID, filter)
|
||||
}
|
||||
|
||||
// adminApproveJoinRequest
|
||||
//
|
||||
// @Summary 通过加入申请(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param requestID path int64 true "RequestID"
|
||||
// @Param form body dto.AdminTenantJoinRequestDecideForm true "Form"
|
||||
// @Success 200 {object} models.TenantJoinRequest
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/join-requests/:requestID/approve [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind requestID path
|
||||
// @Bind form body
|
||||
func (*tenantJoinAdmin) adminApproveJoinRequest(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
requestID int64,
|
||||
form *dto.AdminTenantJoinRequestDecideForm,
|
||||
) (*models.TenantJoinRequest, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if requestID <= 0 {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("request_id must be > 0")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"request_id": requestID,
|
||||
"decide_time": time.Now(),
|
||||
}).Info("tenant.admin.join_requests.approve")
|
||||
|
||||
return services.Tenant.AdminApproveJoinRequest(ctx.Context(), tenant.ID, tenantUser.UserID, requestID, form.Reason)
|
||||
}
|
||||
|
||||
// adminRejectJoinRequest
|
||||
//
|
||||
// @Summary 拒绝加入申请(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param requestID path int64 true "RequestID"
|
||||
// @Param form body dto.AdminTenantJoinRequestDecideForm true "Form"
|
||||
// @Success 200 {object} models.TenantJoinRequest
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/join-requests/:requestID/reject [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind requestID path
|
||||
// @Bind form body
|
||||
func (*tenantJoinAdmin) adminRejectJoinRequest(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
requestID int64,
|
||||
form *dto.AdminTenantJoinRequestDecideForm,
|
||||
) (*models.TenantJoinRequest, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if requestID <= 0 {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("request_id must be > 0")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"request_id": requestID,
|
||||
"decide_time": time.Now(),
|
||||
}).Info("tenant.admin.join_requests.reject")
|
||||
|
||||
return services.Tenant.AdminRejectJoinRequest(ctx.Context(), tenant.ID, tenantUser.UserID, requestID, form.Reason)
|
||||
}
|
||||
13
backend/app/http/tenantjoin/dto/join.go
Normal file
13
backend/app/http/tenantjoin/dto/join.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package dto
|
||||
|
||||
// JoinByInviteForm 用户通过邀请码加入租户的请求参数。
|
||||
type JoinByInviteForm struct {
|
||||
// InviteCode 邀请码:由租户管理员生成;用户提交后加入对应租户。
|
||||
InviteCode string `json:"invite_code"`
|
||||
}
|
||||
|
||||
// JoinRequestCreateForm 用户提交加入租户申请的请求参数(无邀请码场景)。
|
||||
type JoinRequestCreateForm struct {
|
||||
// Reason 申请原因(可选):用于向租户管理员说明申请加入的目的。
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
87
backend/app/http/tenantjoin/join.go
Normal file
87
backend/app/http/tenantjoin/join.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package tenantjoin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenantjoin/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// join 提供“非成员加入租户”的相关接口(邀请码加入 / 申请加入)。
|
||||
//
|
||||
// @provider
|
||||
type join struct{}
|
||||
|
||||
// joinByInvite
|
||||
//
|
||||
// @Summary 通过邀请码加入租户
|
||||
// @Tags TenantJoin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param form body dto.JoinByInviteForm true "Form"
|
||||
// @Success 200 {object} models.TenantUser
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/join/invite [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind claims local key(claims)
|
||||
// @Bind form body
|
||||
func (*join) joinByInvite(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
claims *jwt.Claims,
|
||||
form *dto.JoinByInviteForm,
|
||||
) (*models.TenantUser, error) {
|
||||
if tenant == nil || claims == nil {
|
||||
return nil, errorx.ErrInternalError.WithMsg("context missing")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": claims.UserID,
|
||||
}).Info("tenantjoin.join_by_invite")
|
||||
|
||||
return services.Tenant.JoinByInvite(ctx.Context(), tenant.ID, claims.UserID, form.InviteCode)
|
||||
}
|
||||
|
||||
// createJoinRequest
|
||||
//
|
||||
// @Summary 提交加入租户申请
|
||||
// @Tags TenantJoin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param form body dto.JoinRequestCreateForm true "Form"
|
||||
// @Success 200 {object} models.TenantJoinRequest
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/join/request [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind claims local key(claims)
|
||||
// @Bind form body
|
||||
func (*join) createJoinRequest(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
claims *jwt.Claims,
|
||||
form *dto.JoinRequestCreateForm,
|
||||
) (*models.TenantJoinRequest, error) {
|
||||
if tenant == nil || claims == nil {
|
||||
return nil, errorx.ErrInternalError.WithMsg("context missing")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": claims.UserID,
|
||||
}).Info("tenantjoin.create_join_request")
|
||||
|
||||
return services.Tenant.CreateJoinRequest(ctx.Context(), tenant.ID, claims.UserID, form)
|
||||
}
|
||||
37
backend/app/http/tenantjoin/provider.gen.go
Executable file
37
backend/app/http/tenantjoin/provider.gen.go
Executable file
@@ -0,0 +1,37 @@
|
||||
package tenantjoin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/middlewares"
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.ipao.vip/atom/opt"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func() (*join, error) {
|
||||
obj := &join{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
join *join,
|
||||
middlewares *middlewares.Middlewares,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
join: join,
|
||||
middlewares: middlewares,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
63
backend/app/http/tenantjoin/routes.gen.go
Normal file
63
backend/app/http/tenantjoin/routes.gen.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Code generated by atomctl. DO NOT EDIT.
|
||||
|
||||
// Package tenantjoin provides HTTP route definitions and registration
|
||||
// for the quyun/v2 application.
|
||||
package tenantjoin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/tenantjoin/dto"
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
// for all controllers in the tenantjoin module.
|
||||
//
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
middlewares *middlewares.Middlewares
|
||||
// Controller instances
|
||||
join *join
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
func (r *Routes) Prepare() error {
|
||||
r.log = log.WithField("module", "routes.tenantjoin")
|
||||
r.log.Info("Initializing routes module")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns the unique identifier for this routes provider.
|
||||
func (r *Routes) Name() string {
|
||||
return "tenantjoin"
|
||||
}
|
||||
|
||||
// Register registers all HTTP routes with the provided fiber router.
|
||||
// Each route is registered with its corresponding controller action and parameter bindings.
|
||||
func (r *Routes) Register(router fiber.Router) {
|
||||
// Register routes for controller: join
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/join/invite -> join.joinByInvite")
|
||||
router.Post("/t/:tenantCode/v1/join/invite"[len(r.Path()):], DataFunc3(
|
||||
r.join.joinByInvite,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*jwt.Claims]("claims"),
|
||||
Body[dto.JoinByInviteForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/join/request -> join.createJoinRequest")
|
||||
router.Post("/t/:tenantCode/v1/join/request"[len(r.Path()):], DataFunc3(
|
||||
r.join.createJoinRequest,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*jwt.Claims]("claims"),
|
||||
Body[dto.JoinRequestCreateForm]("form"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
12
backend/app/http/tenantjoin/routes.manual.go
Normal file
12
backend/app/http/tenantjoin/routes.manual.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package tenantjoin
|
||||
|
||||
func (r *Routes) Path() string {
|
||||
return "/t/:tenantCode/v1"
|
||||
}
|
||||
|
||||
func (r *Routes) Middlewares() []any {
|
||||
return []any{
|
||||
r.middlewares.TenantResolve,
|
||||
r.middlewares.TenantAuth,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user