feat: 重构内容和订单列表接口,使用过滤器结构体简化参数传递;更新相关服务和测试用例

This commit is contained in:
2025-12-29 15:41:48 +08:00
parent fba77afec1
commit 9d598e7f9b
11 changed files with 286 additions and 232 deletions

View File

@@ -50,11 +50,9 @@ func (c *Creator) Dashboard(ctx fiber.Ctx) (*dto.DashboardStats, error) {
// @Param genre query string false "Genre"
// @Param keyword query string false "Keyword"
// @Success 200 {array} dto.ContentItem
// @Bind status query
// @Bind genre query
// @Bind keyword query
func (c *Creator) ListContents(ctx fiber.Ctx, status, genre, keyword string) ([]dto.ContentItem, error) {
return services.Creator.ListContents(ctx.Context(), status, genre, keyword)
// @Bind filter query
func (c *Creator) ListContents(ctx fiber.Ctx, filter *dto.CreatorContentListFilter) ([]dto.ContentItem, error) {
return services.Creator.ListContents(ctx.Context(), filter)
}
// Create/Publish content
@@ -115,10 +113,9 @@ func (c *Creator) DeleteContent(ctx fiber.Ctx, id string) error {
// @Param status query string false "Status"
// @Param keyword query string false "Keyword"
// @Success 200 {array} dto.Order
// @Bind status query
// @Bind keyword query
func (c *Creator) ListOrders(ctx fiber.Ctx, status, keyword string) ([]dto.Order, error) {
return services.Creator.ListOrders(ctx.Context(), status, keyword)
// @Bind filter query
func (c *Creator) ListOrders(ctx fiber.Ctx, filter *dto.CreatorOrderListFilter) ([]dto.Order, error) {
return services.Creator.ListOrders(ctx.Context(), filter)
}
// Process refund

View File

@@ -4,10 +4,10 @@ import "quyun/v2/app/requests"
type ContentListFilter struct {
requests.Pagination
Keyword string `query:"keyword"`
Genre string `query:"genre"`
TenantID string `query:"tenantId"`
Sort string `query:"sort"`
Keyword *string `query:"keyword"`
Genre *string `query:"genre"`
TenantID *string `query:"tenantId"`
Sort *string `query:"sort"`
}
type ContentItem struct {

View File

@@ -1,5 +1,7 @@
package dto
import "quyun/v2/app/requests"
type ApplyForm struct {
Name string `json:"name"`
Bio string `json:"bio"`
@@ -37,6 +39,19 @@ type ContentUpdateForm struct {
MediaIDs []string `json:"media_ids"`
}
type CreatorContentListFilter struct {
requests.Pagination
Status *string `query:"status"`
Genre *string `query:"genre"`
Keyword *string `query:"keyword"`
}
type CreatorOrderListFilter struct {
requests.Pagination
Status *string `query:"status"`
Keyword *string `query:"keyword"`
}
type RefundForm struct {
Action string `json:"action"` // accept, reject
Reason string `json:"reason"`
@@ -63,15 +78,3 @@ type WithdrawForm struct {
Method string `json:"method"` // wallet, external
AccountID string `json:"account_id"`
}
// Re-export or Wrap
// Since ContentItem and Order are in the same package 'dto',
// we don't need type aliases unless we want to rename them.
// If creator.go uses them, it can use dto.ContentItem directly.
// But creator.go is in `v1` (package v1) and imports `dto`.
// So it uses `dto.ContentItem`.
// So we don't need aliases here if the original types are in this package.
// However, if the originals were in `content/dto` and `user/dto` and we moved them to `v1/dto` (this package),
// then we just have them defined in `content.go` (dto) and `user.go` (dto).
// So aliases are not needed if they are in the same package.

View File

@@ -1,9 +1,31 @@
package dto
import (
"quyun/v2/app/requests"
"quyun/v2/pkg/consts"
)
// Filters
type UserListFilter struct {
requests.Pagination
Username *string `query:"username"`
}
type TenantListFilter struct {
requests.Pagination
Name *string `query:"name"`
}
type SuperContentListFilter struct {
requests.Pagination
// Add filters if needed, currently list signature is just pagination in super.go service
}
type SuperOrderListFilter struct {
requests.Pagination
// Add filters if needed
}
// SuperUserLite 用于平台用户列表的轻量级用户信息
type SuperUserLite struct {
ID int64 `json:"id"`

View File

@@ -111,21 +111,18 @@ func (r *Routes) Register(router fiber.Router) {
QueryParam[string]("id"),
))
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc3(
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc1(
r.creator.ListContents,
QueryParam[string]("status"),
QueryParam[string]("genre"),
QueryParam[string]("keyword"),
Query[dto.CreatorContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
router.Get("/v1/creator/dashboard"[len(r.Path()):], DataFunc0(
r.creator.Dashboard,
))
r.log.Debugf("Registering route: Get /v1/creator/orders -> creator.ListOrders")
router.Get("/v1/creator/orders"[len(r.Path()):], DataFunc2(
router.Get("/v1/creator/orders"[len(r.Path()):], DataFunc1(
r.creator.ListOrders,
QueryParam[string]("status"),
QueryParam[string]("keyword"),
Query[dto.CreatorOrderListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/creator/payout-accounts -> creator.ListPayoutAccounts")
router.Get("/v1/creator/payout-accounts"[len(r.Path()):], DataFunc0(
@@ -178,16 +175,14 @@ func (r *Routes) Register(router fiber.Router) {
r.super.CheckToken,
))
r.log.Debugf("Registering route: Get /v1/contents -> super.ListContents")
router.Get("/v1/contents"[len(r.Path()):], DataFunc2(
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
r.super.ListContents,
QueryParam[int]("page"),
QueryParam[int]("limit"),
Query[dto.SuperContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/orders -> super.ListOrders")
router.Get("/v1/orders"[len(r.Path()):], DataFunc2(
router.Get("/v1/orders"[len(r.Path()):], DataFunc1(
r.super.ListOrders,
QueryParam[int]("page"),
QueryParam[int]("limit"),
Query[dto.SuperOrderListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/orders/:id -> super.GetOrder")
router.Get("/v1/orders/:id"[len(r.Path()):], DataFunc1(
@@ -199,11 +194,9 @@ func (r *Routes) Register(router fiber.Router) {
r.super.OrderStatistics,
))
r.log.Debugf("Registering route: Get /v1/tenants -> super.ListTenants")
router.Get("/v1/tenants"[len(r.Path()):], DataFunc3(
router.Get("/v1/tenants"[len(r.Path()):], DataFunc1(
r.super.ListTenants,
QueryParam[int]("page"),
QueryParam[int]("limit"),
QueryParam[string]("name"),
Query[dto.TenantListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/tenants/:id -> super.GetTenant")
router.Get("/v1/tenants/:id"[len(r.Path()):], DataFunc1(
@@ -215,11 +208,9 @@ func (r *Routes) Register(router fiber.Router) {
r.super.TenantStatuses,
))
r.log.Debugf("Registering route: Get /v1/users -> super.ListUsers")
router.Get("/v1/users"[len(r.Path()):], DataFunc3(
router.Get("/v1/users"[len(r.Path()):], DataFunc1(
r.super.ListUsers,
QueryParam[int]("page"),
QueryParam[int]("limit"),
QueryParam[string]("username"),
Query[dto.UserListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/users/:id -> super.GetUser")
router.Get("/v1/users/:id"[len(r.Path()):], DataFunc1(

View File

@@ -15,294 +15,308 @@ type Super struct{}
//
// @Router /v1/auth/login [post]
// @Summary Login
// @Tags Super
// @Description Login
// @Tags Auth
// @Accept json
// @Produce json
// @Param form body dto.LoginForm true "Login form"
// @Success 200 {object} dto.LoginResponse
// @Bind form body
func (s *Super) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
func (c *Super) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
return services.Super.Login(ctx.Context(), form)
}
// Check Token
//
// @Router /v1/auth/token [get]
// @Summary Check Token
// @Tags Super
// @Summary Check token
// @Description Check token
// @Tags Auth
// @Accept json
// @Produce json
// @Success 200 {object} dto.LoginResponse
func (s *Super) CheckToken(ctx fiber.Ctx) (*dto.LoginResponse, error) {
func (c *Super) CheckToken(ctx fiber.Ctx) (*dto.LoginResponse, error) {
return services.Super.CheckToken(ctx.Context())
}
// List Users
// List users
//
// @Router /v1/users [get]
// @Summary User list
// @Tags Super
// @Summary List users
// @Description List users
// @Tags User
// @Accept json
// @Produce json
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Param username query string false "Username"
// @Success 200 {object} requests.Pager{items=[]dto.UserItem}
// @Bind page query
// @Bind limit query
// @Bind username query
func (s *Super) ListUsers(ctx fiber.Ctx, page, limit int, username string) (*requests.Pager, error) {
return services.Super.ListUsers(ctx.Context(), page, limit, username)
// @Bind filter query
func (c *Super) ListUsers(ctx fiber.Ctx, filter *dto.UserListFilter) (*requests.Pager, error) {
return services.Super.ListUsers(ctx.Context(), filter)
}
// Get User
// Get user
//
// @Router /v1/users/:id [get]
// @Summary Get User
// @Tags Super
// @Summary Get user
// @Description Get user
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param id path int64 true "User ID"
// @Success 200 {object} dto.UserItem
// @Bind id path
func (s *Super) GetUser(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
func (c *Super) GetUser(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
return services.Super.GetUser(ctx.Context(), id)
}
// Update User Status
// Update user status
//
// @Router /v1/users/:id/status [patch]
// @Summary Update user status
// @Tags Super
// @Description Update user status
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param form body dto.UserStatusUpdateForm true "Form"
// @Success 200
// @Param id path int64 true "User ID"
// @Param form body dto.UserStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (s *Super) UpdateUserStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
func (c *Super) UpdateUserStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
return services.Super.UpdateUserStatus(ctx.Context(), id, form)
}
// Update User Roles
// Update user roles
//
// @Router /v1/users/:id/roles [patch]
// @Summary Update user roles
// @Tags Super
// @Description Update user roles
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param form body dto.UserRolesUpdateForm true "Form"
// @Success 200
// @Param id path int64 true "User ID"
// @Param form body dto.UserRolesUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (s *Super) UpdateUserRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
func (c *Super) UpdateUserRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
return services.Super.UpdateUserRoles(ctx.Context(), id, form)
}
// List Tenants
// List tenants
//
// @Router /v1/tenants [get]
// @Summary Tenant list
// @Tags Super
// @Summary List tenants
// @Description List tenants
// @Tags Tenant
// @Accept json
// @Produce json
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Param name query string false "Name"
// @Success 200 {object} requests.Pager{items=[]dto.TenantItem}
// @Bind page query
// @Bind limit query
// @Bind name query
func (s *Super) ListTenants(ctx fiber.Ctx, page, limit int, name string) (*requests.Pager, error) {
return services.Super.ListTenants(ctx.Context(), page, limit, name)
// @Bind filter query
func (c *Super) ListTenants(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pager, error) {
return services.Super.ListTenants(ctx.Context(), filter)
}
// Create Tenant
// Create tenant
//
// @Router /v1/tenants [post]
// @Summary Create Tenant
// @Tags Super
// @Summary Create tenant
// @Description Create tenant
// @Tags Tenant
// @Accept json
// @Produce json
// @Param form body dto.TenantCreateForm true "Form"
// @Success 200
// @Param form body dto.TenantCreateForm true "Create form"
// @Success 200 {string} string "Created"
// @Bind form body
func (s *Super) CreateTenant(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
func (c *Super) CreateTenant(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
return services.Super.CreateTenant(ctx.Context(), form)
}
// Get Tenant
// Get tenant
//
// @Router /v1/tenants/:id [get]
// @Summary Get Tenant
// @Tags Super
// @Summary Get tenant
// @Description Get tenant
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param id path int64 true "Tenant ID"
// @Success 200 {object} dto.TenantItem
// @Bind id path
func (s *Super) GetTenant(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
func (c *Super) GetTenant(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
return services.Super.GetTenant(ctx.Context(), id)
}
// Update Tenant Status
// Update tenant status
//
// @Router /v1/tenants/:id/status [patch]
// @Summary Update Tenant Status
// @Tags Super
// @Summary Update tenant status
// @Description Update tenant status
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param form body dto.TenantStatusUpdateForm true "Form"
// @Success 200
// @Param id path int64 true "Tenant ID"
// @Param form body dto.TenantStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (s *Super) UpdateTenantStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUpdateForm) error {
func (c *Super) UpdateTenantStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUpdateForm) error {
return services.Super.UpdateTenantStatus(ctx.Context(), id, form)
}
// Update Tenant Expire
// Update tenant expire
//
// @Router /v1/tenants/:id [patch]
// @Summary Update Tenant Expire
// @Tags Super
// @Summary Update tenant expire
// @Description Update tenant expire
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param form body dto.TenantExpireUpdateForm true "Form"
// @Success 200
// @Param id path int64 true "Tenant ID"
// @Param form body dto.TenantExpireUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (s *Super) UpdateTenantExpire(ctx fiber.Ctx, id int64, form *dto.TenantExpireUpdateForm) error {
func (c *Super) UpdateTenantExpire(ctx fiber.Ctx, id int64, form *dto.TenantExpireUpdateForm) error {
return services.Super.UpdateTenantExpire(ctx.Context(), id, form)
}
// List Contents
// List contents
//
// @Router /v1/contents [get]
// @Summary Content list
// @Tags Super
// @Summary List contents
// @Description List contents
// @Tags Content
// @Accept json
// @Produce json
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Success 200 {object} requests.Pager{items=[]dto.SuperTenantContentItem}
// @Bind page query
// @Bind limit query
func (s *Super) ListContents(ctx fiber.Ctx, page, limit int) (*requests.Pager, error) {
return services.Super.ListContents(ctx.Context(), page, limit)
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.AdminContentItem}
// @Bind filter query
func (c *Super) ListContents(ctx fiber.Ctx, filter *dto.SuperContentListFilter) (*requests.Pager, error) {
return services.Super.ListContents(ctx.Context(), filter)
}
// Update Content Status
// Update content status
//
// @Router /v1/tenants/:tenantID/contents/:contentID/status [patch]
// @Summary Update Content Status
// @Tags Super
// @Summary Update content status
// @Description Update content status
// @Tags Content
// @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
// @Param tenantID path int64 true "Tenant ID"
// @Param contentID path int64 true "Content ID"
// @Param form body dto.SuperTenantContentStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind tenantID path
// @Bind contentID path
// @Bind form body
func (s *Super) UpdateContentStatus(ctx fiber.Ctx, tenantID, contentID int64, form *dto.SuperTenantContentStatusUpdateForm) error {
func (c *Super) UpdateContentStatus(ctx fiber.Ctx, tenantID, contentID int64, form *dto.SuperTenantContentStatusUpdateForm) error {
return services.Super.UpdateContentStatus(ctx.Context(), tenantID, contentID, form)
}
// List Orders
// List orders
//
// @Router /v1/orders [get]
// @Summary Order list
// @Tags Super
// @Summary List orders
// @Description List orders
// @Tags Order
// @Accept json
// @Produce json
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.SuperOrderItem}
// @Bind page query
// @Bind limit query
func (s *Super) ListOrders(ctx fiber.Ctx, page, limit int) (*requests.Pager, error) {
return services.Super.ListOrders(ctx.Context(), page, limit)
// @Bind filter query
func (c *Super) ListOrders(ctx fiber.Ctx, filter *dto.SuperOrderListFilter) (*requests.Pager, error) {
return services.Super.ListOrders(ctx.Context(), filter)
}
// Get Order
// Get order
//
// @Router /v1/orders/:id [get]
// @Summary Get Order
// @Tags Super
// @Summary Get order
// @Description Get order
// @Tags Order
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param id path int64 true "Order ID"
// @Success 200 {object} dto.SuperOrderDetail
// @Bind id path
func (s *Super) GetOrder(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
func (c *Super) GetOrder(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
return services.Super.GetOrder(ctx.Context(), id)
}
// Refund Order
// Refund order
//
// @Router /v1/orders/:id/refund [post]
// @Summary Refund Order
// @Tags Super
// @Summary Refund order
// @Description Refund order
// @Tags Order
// @Accept json
// @Produce json
// @Param id path int64 true "ID"
// @Param form body dto.SuperOrderRefundForm true "Form"
// @Success 200
// @Param id path int64 true "Order ID"
// @Param form body dto.SuperOrderRefundForm true "Refund form"
// @Success 200 {string} string "Refunded"
// @Bind id path
// @Bind form body
func (s *Super) RefundOrder(ctx fiber.Ctx, id int64, form *dto.SuperOrderRefundForm) error {
func (c *Super) RefundOrder(ctx fiber.Ctx, id int64, form *dto.SuperOrderRefundForm) error {
return services.Super.RefundOrder(ctx.Context(), id, form)
}
// Order Statistics
// Order statistics
//
// @Router /v1/orders/statistics [get]
// @Summary Order Statistics
// @Tags Super
// @Summary Order statistics
// @Description Order statistics
// @Tags Order
// @Accept json
// @Produce json
// @Success 200 {object} dto.OrderStatisticsResponse
func (s *Super) OrderStatistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
func (c *Super) OrderStatistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
return services.Super.OrderStatistics(ctx.Context())
}
// User Statistics
// User statistics
//
// @Router /v1/users/statistics [get]
// @Summary User Statistics
// @Tags Super
// @Summary User statistics
// @Description User statistics
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} dto.UserStatistics
func (s *Super) UserStatistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
func (c *Super) UserStatistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
return services.Super.UserStatistics(ctx.Context())
}
// User Statuses
// User statuses
//
// @Router /v1/users/statuses [get]
// @Summary User Statuses Enum
// @Tags Super
// @Summary User statuses
// @Description User statuses
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
func (s *Super) UserStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
func (c *Super) UserStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
return services.Super.UserStatuses(ctx.Context())
}
// Tenant Statuses
// Tenant statuses
//
// @Router /v1/tenants/statuses [get]
// @Summary Tenant Statuses Enum
// @Tags Super
// @Summary Tenant statuses
// @Description Tenant statuses
// @Tags Tenant
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
func (s *Super) TenantStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
func (c *Super) TenantStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
return services.Super.TenantStatuses(ctx.Context())
}