-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/scala/org/fathomnet/worms/api/DetailEndpoints.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
} |