fix: search issues
This commit is contained in:
@@ -111,36 +111,38 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
|
||||
tbl := table.Medias
|
||||
stmt := tbl.
|
||||
SELECT(tbl.AllColumns).
|
||||
WHERE(tbl.TenantID.EQ(Int(tenantId))).
|
||||
ORDER_BY(tbl.ID.DESC())
|
||||
|
||||
cond := tbl.TenantID.EQ(Int(tenantId))
|
||||
if filter.Title != nil && *filter.Title != "" {
|
||||
stmt = stmt.WHERE(tbl.Title.LIKE(String("%" + *filter.Title + "%")))
|
||||
cond = cond.AND(tbl.Title.LIKE(String("%" + *filter.Title + "%")))
|
||||
}
|
||||
|
||||
if filter.Bought != nil && *filter.Bought {
|
||||
if len(boughtIDs) > 0 {
|
||||
stmt = stmt.
|
||||
WHERE(tbl.ID.IN(lo.Map(boughtIDs, func(item int64, _ int) Expression {
|
||||
cond = cond.
|
||||
AND(tbl.ID.IN(lo.Map(boughtIDs, func(item int64, _ int) Expression {
|
||||
return Int(item)
|
||||
})...))
|
||||
}
|
||||
} else {
|
||||
stmt = stmt.WHERE(tbl.Publish.EQ(Bool(true)))
|
||||
cond = cond.AND(tbl.Publish.EQ(Bool(true)))
|
||||
}
|
||||
|
||||
if filter.OffsetID > 0 {
|
||||
if filter.Action == 0 {
|
||||
stmt = stmt.WHERE(tbl.ID.LT(Int(filter.OffsetID)))
|
||||
cond = cond.AND(tbl.ID.LT(Int(filter.OffsetID)))
|
||||
stmt = stmt.LIMIT(10)
|
||||
}
|
||||
|
||||
if filter.Action == 1 {
|
||||
stmt = stmt.WHERE(tbl.ID.GT(Int(filter.OffsetID)))
|
||||
cond = cond.AND(tbl.ID.GT(Int(filter.OffsetID)))
|
||||
}
|
||||
} else {
|
||||
stmt = stmt.LIMIT(10)
|
||||
}
|
||||
|
||||
stmt = stmt.WHERE(cond)
|
||||
log.Debug(stmt.DebugSql())
|
||||
|
||||
var dest []model.Medias
|
||||
|
||||
Reference in New Issue
Block a user