diff --git a/src/main/scala/org/fathomnet/worms/WormsDetails.scala b/src/main/scala/org/fathomnet/worms/WormsDetails.scala new file mode 100644 index 0000000..73d2a26 --- /dev/null +++ b/src/main/scala/org/fathomnet/worms/WormsDetails.scala @@ -0,0 +1,39 @@ +/* + * Copyright (c) Monterey Bay Aquarium Research Institute 2022 + * + * worms-server code is licensed under the MIT license. + */ + +package org.fathomnet.worms + +import org.fathomnet.worms.io.WormsConcept + +case class WormsDetails( + name: String, + rank: String, + aphiaId: Long, + parentAphiaId: Option[Long] = None, + alternateNames: Seq[String] = Seq.empty, + isMarine: Option[Boolean] = None, + isFreshwater: Option[Boolean] = None, + isTerrestrial: Option[Boolean] = None, + isExtinct: Option[Boolean] = None, + isBrackish: Option[Boolean] = None +) { + +} + +object WormsDetails: + def from(acceptedName: String, wormsConcept: WormsConcept): WormsDetails = + WormsDetails( + name = acceptedName, + rank = wormsConcept.rank, + aphiaId = wormsConcept.id, + parentAphiaId = wormsConcept.parentId, + alternateNames = wormsConcept.names.filterNot(_.isPrimary).map(_.name), + isMarine = wormsConcept.isMarine, + isFreshwater = wormsConcept.isFreshwater, + isTerrestrial = wormsConcept.isTerrestrial, + isExtinct = wormsConcept.isExtinct, + isBrackish = wormsConcept.isBrackish + ) diff --git a/src/main/scala/org/fathomnet/worms/api/DetailEndpoints.scala b/src/main/scala/org/fathomnet/worms/api/DetailEndpoints.scala new file mode 100644 index 0000000..84910fa --- /dev/null +++ b/src/main/scala/org/fathomnet/worms/api/DetailEndpoints.scala @@ -0,0 +1,40 @@ +/* + * Copyright (c) Monterey Bay Aquarium Research Institute 2022 + * + * worms-server code is licensed under the MIT license. + */ + +package org.fathomnet.worms.api + +import scala.concurrent.ExecutionContext +import org.fathomnet.worms.WormsDetails + +import sttp.tapir.generic.auto.* +import sttp.tapir.json.circe.* +import sttp.tapir.server.ServerEndpoint +import sttp.tapir.{query, PublicEndpoint, *} +import org.fathomnet.worms.etc.circe.CirceCodecs.given +import scala.concurrent.Future +import org.fathomnet.worms.StateController + +class DetailEndpoints(using ec: ExecutionContext) extends Endpoints { + + + private val tag = "Details" + + val detailsEndpoint = + baseEndpoint + .get + .in("details") + .in(path[String]("name")) + .out(jsonBody[WormsDetails]) + .description("Returns details about a worms taxa.") + .tag(tag) + + val detailsServerEndpoint: ServerEndpoint[Any, Future] = + detailsEndpoint.serverLogic((name: String) => Future(StateController.details(name))) + + + override def all: List[ServerEndpoint[Any, Future]] = List(detailsServerEndpoint) + +}