Last active
July 5, 2018 15:56
-
-
Save sfosdal/87e8b95c2d06eaa1b53021c4acd69a15 to your computer and use it in GitHub Desktop.
Revisions
-
sfosdal revised this gist
Jul 5, 2018 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,17 @@ import com.apptentive.profile.routes.Paging._ import scala.util._ object Paging { val DefaultPageSize: Int = 100 val ValidPageSizes: Range = 1 to 4000 } case class Paging(startsAfter: Option[UUID] = None, size: Int = DefaultPageSize) trait Pagination { def extractPaging: Directive1[Paging] = { parameterMap.flatMap { params => val size = Try(params.get("page_size").map(_.toInt).get) val startsAfter = Try(params.get("starts_after").map(fromString)) @@ -27,10 +33,3 @@ trait Pagination { } } -
sfosdal revised this gist
Jul 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import akka.http.scaladsl.server.Directive1 import akka.http.scaladsl.server.Directives._ import com.apptentive.profile.routes.Paging._ import scala.util._ trait Pagination { -
sfosdal created this gist
Jul 5, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ package com.apptentive.profile.routes import java.util.UUID import java.util.UUID.fromString import akka.http.scaladsl.server.Directive1 import akka.http.scaladsl.server.Directives._ import com.apptentive.profile.routes.Paging._ import scala.util.{Failure, Success, Try} trait Pagination { def extractPaging: Directive1[Paging] = { parameterMap.flatMap { params => // extraction val size = Try(params.get("page_size").map(_.toInt).get) val startsAfter = Try(params.get("starts_after").map(fromString)) (size, startsAfter) match { case (Failure(_), _) | (_, Failure(_)) | (Success(s), _) if !ValidPageSizes.contains(s) => reject case (_, _) => provide(Paging(startsAfter.getOrElse(None), size.getOrElse(DefaultPageSize))) } } } } object Paging { val DefaultPageSize: Int = 100 val ValidPageSizes: Range = 1 to 4000 } case class Paging(startsAfter: Option[UUID] = None, size: Int = DefaultPageSize)