Skip to content

Commit

Permalink
Add search page data in search api result
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Feb 16, 2021
1 parent 36d2ead commit ab6f480
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.softwaremill.session.SessionOptions.{refreshable, usingCookies}
import play.api.libs.json._

import scala.concurrent.ExecutionContext
import akka.http.scaladsl.model.HttpHeader

object SearchApi {
implicit val formatProject: OFormat[Project] =
Expand All @@ -32,8 +31,16 @@ object SearchApi {
case class Project(
organization: String,
repository: String,
logo: Option[String] = None,
artifacts: List[String] = Nil
logo: Option[String],
stars: Option[Int],
forks: Option[Int],
contributorCount: Option[Int],
topics: Set[String],
artifacts: List[String],
scalaVersion: List[String],
scalaJsVersion: List[String],
scalaNativeVersion: List[String],
sbtVersion: List[String]
)

case class ReleaseOptions(
Expand Down Expand Up @@ -214,13 +221,23 @@ class SearchApi(
}
}

private def convertProject(cli: Boolean)(project: Project): SearchApi.Project = {
private def convertProject(
cli: Boolean
)(project: Project): SearchApi.Project = {
val artifacts = if (cli) project.cliArtifacts.toList else project.artifacts
SearchApi.Project(
project.organization,
project.repository,
project.github.flatMap(_.logo.map(_.target)),
project.artifacts
project.github.flatMap(_.stars),
project.github.flatMap(_.forks),
project.github.map(_.contributorCount),
project.github.map(_.topics).getOrElse(Set.empty),
project.artifacts,
project.scalaVersion,
project.sbtVersion,
project.scalaJsVersion,
project.scalaNativeVersion
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package object routes {
(
"q" ? "*",
"page".as[Int] ? 1,
"total".as[Int] ? SearchParams.resultsPerPage,
"total".as[Int] ? SearchParams.resultsPerPage,
"sort".?,
"topics".as[String].*,
"targetTypes".as[String].*,
Expand All @@ -20,7 +20,7 @@ package object routes {
"sbtVersions".as[String].*,
"contributingSearch".as[Boolean] ? false,
"cli".as[Boolean] ? false,
"you".?,
"you".?
)
).tmap {
case (
Expand All @@ -36,7 +36,7 @@ package object routes {
sbtVersions,
contributingSearch,
cli,
you,
you
) =>
val userRepos = you
.flatMap(_ => user.map(_.repos))
Expand Down

0 comments on commit ab6f480

Please sign in to comment.