feat: tenant-scoped routing and portal navigation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
@@ -14,7 +15,7 @@ type Tenant struct{}
|
||||
|
||||
// List creator contents
|
||||
//
|
||||
// @Router /v1/creators/:id<int>/contents [get]
|
||||
// @Router /t/:tenantCode/v1/creators/:id<int>/contents [get]
|
||||
// @Summary List creator contents
|
||||
// @Description List contents of a specific creator
|
||||
// @Tags TenantPublic
|
||||
@@ -27,16 +28,20 @@ type Tenant struct{}
|
||||
// @Bind id path
|
||||
// @Bind filter query
|
||||
func (t *Tenant) ListContents(ctx fiber.Ctx, id int64, filter *dto.ContentListFilter) (*requests.Pager, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return nil, errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.ContentListFilter{}
|
||||
}
|
||||
filter.TenantID = &id
|
||||
return services.Content.List(ctx, filter)
|
||||
filter.TenantID = &tenantID
|
||||
return services.Content.List(ctx, tenantID, filter)
|
||||
}
|
||||
|
||||
// List tenants (search)
|
||||
//
|
||||
// @Router /v1/tenants [get]
|
||||
// @Router /t/:tenantCode/v1/tenants [get]
|
||||
// @Summary List tenants
|
||||
// @Description Search tenants
|
||||
// @Tags TenantPublic
|
||||
@@ -48,12 +53,13 @@ func (t *Tenant) ListContents(ctx fiber.Ctx, id int64, filter *dto.ContentListFi
|
||||
// @Success 200 {object} requests.Pager
|
||||
// @Bind filter query
|
||||
func (t *Tenant) List(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pager, error) {
|
||||
return services.Tenant.List(ctx, filter)
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Tenant.List(ctx, tenantID, filter)
|
||||
}
|
||||
|
||||
// Get tenant public profile
|
||||
//
|
||||
// @Router /v1/tenants/:id<int> [get]
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int> [get]
|
||||
// @Summary Get tenant profile
|
||||
// @Description Get tenant public profile
|
||||
// @Tags TenantPublic
|
||||
@@ -68,12 +74,16 @@ func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id int64) (*dto.TenantPro
|
||||
if user != nil {
|
||||
uid = user.ID
|
||||
}
|
||||
return services.Tenant.GetPublicProfile(ctx, uid, id)
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return nil, errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
return services.Tenant.GetPublicProfile(ctx, tenantID, uid)
|
||||
}
|
||||
|
||||
// Follow a tenant
|
||||
//
|
||||
// @Router /v1/tenants/:id<int>/follow [post]
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int>/follow [post]
|
||||
// @Summary Follow tenant
|
||||
// @Description Follow a tenant
|
||||
// @Tags TenantPublic
|
||||
@@ -84,12 +94,16 @@ func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id int64) (*dto.TenantPro
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
return services.Tenant.Follow(ctx, user.ID, id)
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
return services.Tenant.Follow(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
// Unfollow a tenant
|
||||
//
|
||||
// @Router /v1/tenants/:id<int>/follow [delete]
|
||||
// @Router /t/:tenantCode/v1/tenants/:id<int>/follow [delete]
|
||||
// @Summary Unfollow tenant
|
||||
// @Description Unfollow a tenant
|
||||
// @Tags TenantPublic
|
||||
@@ -100,5 +114,9 @@ func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
return services.Tenant.Unfollow(ctx, user.ID, id)
|
||||
tenantID := getTenantID(ctx)
|
||||
if tenantID > 0 && id != tenantID {
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
return services.Tenant.Unfollow(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user