Skip to content

Commit

Permalink
Use a more descritive page_size instead of size (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh authored Apr 18, 2024
2 parents 28de783 + dba2fb4 commit 1b4c87d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions modules/backend/src/main/scala/service.player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class PlayerServiceImpl(db: Db)(using Logger[IO]) extends PlayerService[IO]:
blitzMax: Option[Rating],
name: Option[String],
page: Option[PageNumber],
size: Option[Int]
pageSize: Option[Int]
): IO[GetPlayersOutput] =
val _size = size.getOrElse(Models.Pagination.defaultLimit)
val _page = page.flatMap(_.value.toIntOption).getOrElse(Models.Pagination.firstPage)
val paging = Models.Pagination.fromPageAndSize(_page, _size)
val _order = order.map(_.to[Models.Order]).getOrElse(Models.Order.Desc)
val _sortBy = sortBy.map(_.to[Models.SortBy]).getOrElse(Models.SortBy.Name)
val sorting = Models.Sorting(_sortBy, _order)
val _pageSize = pageSize.getOrElse(Models.Pagination.defaultLimit)
val _page = page.flatMap(_.value.toIntOption).getOrElse(Models.Pagination.firstPage)
val paging = Models.Pagination.fromPageAndSize(_page, _pageSize)
val _order = order.map(_.to[Models.Order]).getOrElse(Models.Order.Desc)
val _sortBy = sortBy.map(_.to[Models.SortBy]).getOrElse(Models.SortBy.Name)
val sorting = Models.Sorting(_sortBy, _order)
val filter = Models.Filter(
isActive,
Models.RatingRange(standardMin.map(_.value), standardMax.map(_.value)),
Expand All @@ -48,7 +48,8 @@ class PlayerServiceImpl(db: Db)(using Logger[IO]) extends PlayerService[IO]:
error"Error in getPlayers with $filter, $e" *>
IO.raiseError(InternalServerError("Internal server error"))
.map(_.map(_.transform))
.map(xs => GetPlayersOutput(xs, Option.when(xs.size == _size)(PageNumber(paging.nextPage.toString()))))
.map: xs =>
GetPlayersOutput(xs, Option.when(xs.size == _pageSize)(PageNumber(paging.nextPage.toString())))

override def getPlayerById(id: PlayerId): IO[Player] =
db.playerById(id.value)
Expand Down
6 changes: 3 additions & 3 deletions modules/smithy/src/main/smithy/players.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ service PlayerService {
}

@readonly
@paginated(inputToken: "page", outputToken: "nextPage", pageSize: "size")
@paginated(inputToken: "page", outputToken: "nextPage", pageSize: "pageSize")
@http(method: "GET", uri: "/api/players", code: 200)
operation GetPlayers {
input: GetPlayersInput,
Expand Down Expand Up @@ -60,9 +60,9 @@ structure GetPlayersByIdsOutput {
structure GetPlayersInput with [SortingMixin, FilterMixin] {
@httpQuery("page")
page: PageNumber
@httpQuery("size")
@httpQuery("page_size")
@range(min: 1, max: 100)
size: Integer
pageSize: Integer
}

structure GetPlayersOutput {
Expand Down

0 comments on commit 1b4c87d

Please sign in to comment.