Skip to content

Commit

Permalink
Merge pull request #9 from stjernegard/paginate-non-content-models
Browse files Browse the repository at this point in the history
Allow paginate(for:) on non-Content Models
  • Loading branch information
anthonycastelli authored Jun 26, 2018
2 parents be3a121 + 074f79a commit 91658b8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/Pagination/QueryBuilder+Paginatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension QueryBuilder where Result: Paginatable, Result.Database == Database {
}
}

extension QueryBuilder where Result: Paginatable & Content, Result.Database == Database {
extension QueryBuilder where Result: Paginatable, Result.Database == Database {
/// Returns a page-based response using page number from the request data
public func paginate(for req: Request, pageKey: String = Pagination.defaultPageKey, perPageKey: String = Pagination.defaultPerPageKey, _ sorts: [Result.Database.QuerySort] = Result.defaultPageSorts) throws -> Future<Page<Result>> {
let page = try req.query.get(Int?.self, at: pageKey) ?? 1
Expand All @@ -57,7 +57,9 @@ extension QueryBuilder where Result: Paginatable & Content, Result.Database == D
}
return try self.paginate(page: page, per: per, sorts)
}
}

extension QueryBuilder where Result: Paginatable & Content, Result.Database == Database {
/// Returns a paginated response using page number from the request data
public func paginate(for req: Request) throws -> Future<Paginated<Result>> {
return try self.paginate(for: req).map(to: Paginated<Result>.self) { $0.response() }
Expand Down

0 comments on commit 91658b8

Please sign in to comment.