From 3f84d644ccb733de152dc99ea2f2bdb02ced6c34 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Tue, 16 Feb 2021 17:32:26 +0100 Subject: [PATCH] Add paging info in search API --- .../routes/api/SearchApi.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/scala/ch.epfl.scala.index.server/routes/api/SearchApi.scala b/server/src/main/scala/ch.epfl.scala.index.server/routes/api/SearchApi.scala index 664ffc043..d45426329 100644 --- a/server/src/main/scala/ch.epfl.scala.index.server/routes/api/SearchApi.scala +++ b/server/src/main/scala/ch.epfl.scala.index.server/routes/api/SearchApi.scala @@ -28,6 +28,10 @@ object SearchApi { implicit val formatReleaseOptions: OFormat[ReleaseOptions] = Json.format[ReleaseOptions] + implicit val formatResult: OFormat[Result] = + Json.format[Result] + + case class Result(currentPage: Int, pageTotal: Int, items: Seq[Project]) case class Project( organization: String, repository: String, @@ -164,7 +168,13 @@ class SearchApi( searchParams(user) { params => val result = dataRepository .findProjects(params) - .map(page => page.items.map(convertProject(params.cli))) + .map { page => + SearchApi.Result( + currentPage = page.pagination.current, + pageTotal = page.pagination.pageCount, + items = page.items.map(convertProject(params.cli)) + ) + } complete(result) } }