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

This commit is contained in:
2025-12-29 15:04:55 +08:00
parent 8c4bc55f45
commit fba77afec1
14 changed files with 65 additions and 60 deletions

View File

@@ -25,17 +25,12 @@ type Content struct{}
// @Param sort query string false "Sort order" Enums(latest, hot, price_asc)
// @Param page query int false "Page number"
// @Success 200 {object} requests.Pager{items=[]dto.ContentItem}
// @Bind keyword query
// @Bind genre query
// @Bind tenantId query
// @Bind sort query
// @Bind page query
// @Bind filter query
func (c *Content) List(
ctx fiber.Ctx,
keyword, genre, tenantId, sort string,
page int,
filter *dto.ContentListFilter,
) (*requests.Pager, error) {
return services.Content.List(ctx.Context(), keyword, genre, tenantId, sort, page)
return services.Content.List(ctx.Context(), filter)
}
// Get content detail

View File

@@ -1,5 +1,15 @@
package dto
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"`
}
type ContentItem struct {
ID string `json:"id"`
Title string `json:"title"`

View File

@@ -69,13 +69,9 @@ func (r *Routes) Register(router fiber.Router) {
))
// Register routes for controller: Content
r.log.Debugf("Registering route: Get /v1/contents -> content.List")
router.Get("/v1/contents"[len(r.Path()):], DataFunc5(
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
r.content.List,
QueryParam[string]("keyword"),
QueryParam[string]("genre"),
QueryParam[string]("tenantId"),
QueryParam[string]("sort"),
QueryParam[int]("page"),
Query[dto.ContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/contents/:id -> content.Get")
router.Get("/v1/contents/:id"[len(r.Path()):], DataFunc1(