feat: add tenant membership flow
This commit is contained in:
@@ -120,3 +120,67 @@ func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
}
|
||||
return services.Tenant.Unfollow(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
// Apply to join a tenant
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int>/join [post]
|
||||
// @Summary Apply to join tenant
|
||||
// @Description Submit join request for a tenant
|
||||
// @Tags TenantPublic
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int64 true "Tenant ID"
|
||||
// @Param form body dto.TenantJoinApplyForm true "Join form"
|
||||
// @Success 200 {string} string "Applied"
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (t *Tenant) ApplyJoin(ctx fiber.Ctx, id int64, form *dto.TenantJoinApplyForm) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
userID := getUserID(ctx)
|
||||
return services.Tenant.ApplyJoin(ctx, id, userID, form)
|
||||
}
|
||||
|
||||
// Cancel join request
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int>/join [delete]
|
||||
// @Summary Cancel join request
|
||||
// @Description Cancel join request for a tenant
|
||||
// @Tags TenantPublic
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int64 true "Tenant ID"
|
||||
// @Success 200 {string} string "Canceled"
|
||||
// @Bind id path
|
||||
func (t *Tenant) CancelJoin(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
userID := getUserID(ctx)
|
||||
return services.Tenant.CancelJoin(ctx, id, userID)
|
||||
}
|
||||
|
||||
// Accept tenant invite
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int>/invites/accept [post]
|
||||
// @Summary Accept tenant invite
|
||||
// @Description Accept a tenant invite by code
|
||||
// @Tags TenantPublic
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int64 true "Tenant ID"
|
||||
// @Param form body dto.TenantInviteAcceptForm true "Invite form"
|
||||
// @Success 200 {string} string "Accepted"
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (t *Tenant) AcceptInvite(ctx fiber.Ctx, id int64, form *dto.TenantInviteAcceptForm) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
userID := getUserID(ctx)
|
||||
return services.Tenant.AcceptInvite(ctx, id, userID, form)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user