feat: 重构内容和订单列表接口,使用过滤器结构体简化参数传递;更新相关服务和测试用例
This commit is contained in:
@@ -23,14 +23,14 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
|
||||
// Filters
|
||||
q = q.Where(tbl.Status.Eq(consts.ContentStatusPublished))
|
||||
if filter.Keyword != "" {
|
||||
q = q.Where(tbl.Title.Like("%" + filter.Keyword + "%"))
|
||||
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||
q = q.Where(tbl.Title.Like("%" + *filter.Keyword + "%"))
|
||||
}
|
||||
if filter.Genre != "" {
|
||||
q = q.Where(tbl.Genre.Eq(filter.Genre))
|
||||
if filter.Genre != nil && *filter.Genre != "" {
|
||||
q = q.Where(tbl.Genre.Eq(*filter.Genre))
|
||||
}
|
||||
if filter.TenantID != "" {
|
||||
tid := cast.ToInt64(filter.TenantID)
|
||||
if filter.TenantID != nil && *filter.TenantID != "" {
|
||||
tid := cast.ToInt64(*filter.TenantID)
|
||||
q = q.Where(tbl.TenantID.Eq(tid))
|
||||
}
|
||||
|
||||
@@ -38,7 +38,12 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
q = q.Preload(tbl.Author)
|
||||
|
||||
// Sort
|
||||
switch filter.Sort {
|
||||
sort := "latest"
|
||||
if filter.Sort != nil && *filter.Sort != "" {
|
||||
sort = *filter.Sort
|
||||
}
|
||||
|
||||
switch sort {
|
||||
case "hot":
|
||||
q = q.Order(tbl.Views.Desc())
|
||||
case "price_asc":
|
||||
@@ -48,7 +53,6 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
}
|
||||
|
||||
// Pagination
|
||||
// Use embedded pagination directly
|
||||
filter.Pagination.Format()
|
||||
total, err := q.Count()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user