Skip to content

Commit

Permalink
empty values are returned as null
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Oct 22, 2024
1 parent 1b14464 commit b899dd6
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/scala/org/fathomnet/worms/WormsDetails.scala
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 src/main/scala/org/fathomnet/worms/api/DetailEndpoints.scala
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)

}

0 comments on commit b899dd6

Please sign in to comment.