Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more descritive page_size instead of size #32

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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