add sort direction support

project_pack
p31729568 5 years ago
parent da8ed2187a
commit 737e992d04

@ -21,6 +21,7 @@ module Mobile
optional :category, type: String, desc: '类型' optional :category, type: String, desc: '类型'
optional :keyword, type: String, desc: '搜索关键字' optional :keyword, type: String, desc: '搜索关键字'
optional :sort_by, type: String, desc: '排序' optional :sort_by, type: String, desc: '排序'
optional :sort_direction, type: String, desc: '排序方向'
optional :page, type: Integer, desc: '页数' optional :page, type: Integer, desc: '页数'
optional :per_page, type: Integer, desc: '分页大小' optional :per_page, type: Integer, desc: '分页大小'
end end
@ -34,11 +35,10 @@ module Mobile
count = packages.count count = packages.count
if params[:sort_by] == 'price' direction = params[:sort_direction] == 'asc' ? 'asc' : 'desc'
packages = packages.order('min_price desc') sort = params[:sort_by] == 'price' ? 'min_price' : 'published_at'
else packages = packages.order("#{sort} #{direction}")
packages = packages.order('published_at desc')
end
packages = paginate packages.includes(:creator, :attachments, bidding_users: :user) packages = paginate packages.includes(:creator, :attachments, bidding_users: :user)
present :count, count present :count, count

Loading…
Cancel
Save