feat: filter image-search linked shopee products (#279)
This commit is contained in:
@@ -34,8 +34,18 @@ func (handler Handler) List(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var imageSearchLinked *bool
|
||||
if raw := strings.TrimSpace(c.Query("imageSearchLinked")); raw != "" {
|
||||
value, parseErr := strconv.ParseBool(raw)
|
||||
if parseErr != nil {
|
||||
writeError(c, invalidRequest("imageSearchLinked 必须是布尔值"))
|
||||
return
|
||||
}
|
||||
imageSearchLinked = &value
|
||||
}
|
||||
response, err := service.List(c.Request.Context(), ListRequest{
|
||||
Page: page, PageSize: pageSize, Keyword: c.Query("keyword"), Status: strings.TrimSpace(c.Query("status")),
|
||||
ImageSearchLinked: imageSearchLinked,
|
||||
})
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
|
||||
@@ -231,7 +231,8 @@ type ListRequest struct {
|
||||
// Status filters by lifecycle: "" (default) live only, "deleted" soft-deleted
|
||||
// only. There is no "all" value: mixing live and deleted rows in one page
|
||||
// would defeat the point of the filter (#40 prototype: 全部(不含已删除)).
|
||||
Status string
|
||||
Status string
|
||||
ImageSearchLinked *bool
|
||||
}
|
||||
|
||||
func (service *Service) List(ctx context.Context, request ListRequest) (ListResponse, error) {
|
||||
@@ -257,6 +258,9 @@ func (service *Service) List(ctx context.Context, request ListRequest) (ListResp
|
||||
like := "%" + request.Keyword + "%"
|
||||
query = query.Where("shopee_item_id LIKE ? OR title LIKE ? OR shop_name LIKE ?", like, like, like)
|
||||
}
|
||||
if request.ImageSearchLinked != nil {
|
||||
query = query.Where("image_search_linked = ?", *request.ImageSearchLinked)
|
||||
}
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return ListResponse{}, internalError(err)
|
||||
|
||||
Reference in New Issue
Block a user