feat: add tenant content management features for superadmin
- Implemented API endpoints for listing tenant contents and updating content status.
- Added Swagger documentation for new endpoints:
- GET /super/v1/tenants/{tenantID}/contents
- PATCH /super/v1/tenants/{tenantID}/contents/{contentID}/status
- Created DTOs for content item and status update form.
- Enhanced frontend to support content management in the tenant detail page.
- Added search and filter functionalities for tenant contents.
- Implemented unpublish functionality with confirmation dialog.
- Updated service layer to handle new content management logic.
This commit is contained in:
44
backend/app/http/super/dto/content.go
Normal file
44
backend/app/http/super/dto/content.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
// TenantContentFilter defines list query filters for tenant contents (superadmin).
|
||||
type TenantContentFilter struct {
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
requests.SortQueryFilter `json:",inline" query:",inline"`
|
||||
|
||||
Keyword *string `json:"keyword,omitempty" query:"keyword"`
|
||||
|
||||
Status *consts.ContentStatus `json:"status,omitempty" query:"status"`
|
||||
Visibility *consts.ContentVisibility `json:"visibility,omitempty" query:"visibility"`
|
||||
|
||||
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||
|
||||
PublishedAtFrom *time.Time `json:"published_at_from,omitempty" query:"published_at_from"`
|
||||
PublishedAtTo *time.Time `json:"published_at_to,omitempty" query:"published_at_to"`
|
||||
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
|
||||
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
|
||||
}
|
||||
|
||||
func (f *TenantContentFilter) KeywordTrimmed() string {
|
||||
if f == nil || f.Keyword == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(*f.Keyword)
|
||||
}
|
||||
|
||||
type SuperTenantContentItem struct {
|
||||
Content *models.Content `json:"content,omitempty"`
|
||||
Price *models.ContentPrice `json:"price,omitempty"`
|
||||
Owner *SuperUserLite `json:"owner,omitempty"`
|
||||
|
||||
StatusDescription string `json:"status_description,omitempty"`
|
||||
VisibilityDescription string `json:"visibility_description,omitempty"`
|
||||
}
|
||||
8
backend/app/http/super/dto/content_status.go
Normal file
8
backend/app/http/super/dto/content_status.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package dto
|
||||
|
||||
import "quyun/v2/pkg/consts"
|
||||
|
||||
type SuperTenantContentStatusUpdateForm struct {
|
||||
// Status supports: unpublished (下架) / blocked (封禁)
|
||||
Status consts.ContentStatus `json:"status" validate:"required,oneof=unpublished blocked"`
|
||||
}
|
||||
@@ -87,6 +87,12 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
r.tenant.detail,
|
||||
PathParam[int64]("tenantID"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /super/v1/tenants/:tenantID<int>/contents -> tenant.contents")
|
||||
router.Get("/super/v1/tenants/:tenantID<int>/contents"[len(r.Path()):], DataFunc2(
|
||||
r.tenant.contents,
|
||||
PathParam[int64]("tenantID"),
|
||||
Query[dto.TenantContentFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /super/v1/tenants/:tenantID<int>/users -> tenant.users")
|
||||
router.Get("/super/v1/tenants/:tenantID<int>/users"[len(r.Path()):], DataFunc2(
|
||||
r.tenant.users,
|
||||
@@ -103,6 +109,13 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantExpireUpdateForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status -> tenant.updateContentStatus")
|
||||
router.Patch("/super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status"[len(r.Path()):], DataFunc3(
|
||||
r.tenant.updateContentStatus,
|
||||
PathParam[int64]("tenantID"),
|
||||
PathParam[int64]("contentID"),
|
||||
Body[dto.SuperTenantContentStatusUpdateForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID<int>/status -> tenant.updateStatus")
|
||||
router.Patch("/super/v1/tenants/:tenantID<int>/status"[len(r.Path()):], Func2(
|
||||
r.tenant.updateStatus,
|
||||
|
||||
30
backend/app/http/super/tenant_content.go
Normal file
30
backend/app/http/super/tenant_content.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// contents
|
||||
//
|
||||
// @Summary 租户内容列表(平台侧)
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantID path int64 true "TenantID"
|
||||
// @Param filter query dto.TenantContentFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=dto.SuperTenantContentItem}
|
||||
//
|
||||
// @Router /super/v1/tenants/:tenantID<int>/contents [get]
|
||||
// @Bind tenantID path
|
||||
// @Bind filter query
|
||||
func (*tenant) contents(ctx fiber.Ctx, tenantID int64, filter *dto.TenantContentFilter) (*requests.Pager, error) {
|
||||
if filter == nil {
|
||||
filter = &dto.TenantContentFilter{}
|
||||
}
|
||||
filter.Pagination.Format()
|
||||
return services.Content.SuperTenantContentsPage(ctx, tenantID, filter)
|
||||
}
|
||||
47
backend/app/http/super/tenant_content_status.go
Normal file
47
backend/app/http/super/tenant_content_status.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// updateContentStatus
|
||||
//
|
||||
// @Summary 更新租户内容状态(平台侧:下架/封禁)
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantID path int64 true "TenantID"
|
||||
// @Param contentID path int64 true "ContentID"
|
||||
// @Param form body dto.SuperTenantContentStatusUpdateForm true "Form"
|
||||
// @Success 200 {object} models.Content
|
||||
//
|
||||
// @Router /super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status [patch]
|
||||
// @Bind tenantID path
|
||||
// @Bind contentID path
|
||||
// @Bind form body
|
||||
func (*tenant) updateContentStatus(
|
||||
ctx fiber.Ctx,
|
||||
tenantID int64,
|
||||
contentID int64,
|
||||
form *dto.SuperTenantContentStatusUpdateForm,
|
||||
) (*models.Content, error) {
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
claims, ok := ctx.Locals(consts.CtxKeyClaims).(*jwt.Claims)
|
||||
if !ok || claims == nil || claims.UserID <= 0 {
|
||||
return nil, errorx.ErrTokenInvalid
|
||||
}
|
||||
|
||||
return services.Content.SuperUpdateTenantContentStatus(ctx, claims.UserID, tenantID, contentID, form.Status, time.Now())
|
||||
}
|
||||
Reference in New Issue
Block a user