Skip to content

Commit

Permalink
fix(sde): modify solar system query to not assume planets are always …
Browse files Browse the repository at this point in the history
…present, this ensures abyssal systems are now included in the universe
  • Loading branch information
updraft0 committed Jul 4, 2024
1 parent 19729ae commit caf920b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ object Endpoints:
.out(jsonBody[SolarSystem])
.description("Get static data for a given solar system")

val getSolarSystemById =
reference.get
.in("system" / "id" / path[Long]("solarSystemId"))
.out(jsonBody[SolarSystem])
.description("Get static data for a given solar system (by id)")

val getAllSolarSystems =
reference.get
.in("all" / "systems")
Expand Down
5 changes: 5 additions & 0 deletions requests/reference.http
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ GET {{api}}/reference/system/Rens

###

# @name GetRefSolarSystemById
GET {{api}}/reference/system/id/32000041

###

# Used by the client to pre-load static reference data (to avoid balooning request sizes)
# @name GetRefAll
GET {{api}}/reference/all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class SolarSystemWithGates(sys: model.SolarSystem, gates: Array[StargateBot
*/
object ReferenceQueries:
import ctx.{*, given}
import auth.given_MappedEncoding_Long_SystemId
import auth.given
import map.given
import map.schema.*
import sde.schema.*
Expand Down Expand Up @@ -68,19 +68,25 @@ object ReferenceQueries:
)

def getSolarSystemByName(name: String): Result[List[protocol.SolarSystem]] =
getSolarSystemsByName(Some(name))
getSolarSystemsByName(Some(name), None)

def getSolarSystemsByName(name: Option[String]): Result[List[protocol.SolarSystem]] =
def getSolarSystemById(id: SystemId): Result[List[protocol.SolarSystem]] =
getSolarSystemsByName(None, Some(id))

def getSolarSystemsByName(name: Option[String], id: Option[SystemId]): Result[List[protocol.SolarSystem]] =
run(quote {
(for
sys <- solarSystem.filter(s => lift(name).forall(_ == s.name))
sys <- solarSystem.filter(s =>
infix"(${lift(name).forall(_ == s.name)})".asCondition &&
infix"(${lift(id).forall(_ == s.id)})".asCondition
)
reg <- region.join(_.id == sys.regionId)
ptj <- (solarSystemPlanet
.join(itemType)
.on(_.typeId == _.id)
.leftJoin(itemName)
.on(_._1.id == _.id))
.join(_._1._1.systemId == sys.id)
.leftJoin(_._1._1.systemId == sys.id)
stj <- (npcStation
.join(npcCorporation)
.on(_.ownerId == _.id)
Expand All @@ -99,17 +105,18 @@ object ReferenceQueries:
(
sys,
reg,
jsonGroupArrayDistinct[protocol.Planet](
jsonGroupArrayFilterNullDistinct[protocol.Planet](
jsonObject4(
"idx",
ptj._1._1.idx,
ptj.map(_._1._1.idx),
"name",
ptj._2.map(_.name),
ptj.map(_._2.map(_.name)),
"typeName",
ptj._1._2.name,
ptj.map(_._1._2.name),
"typeId",
ptj._1._1.typeId
)
ptj.map(_._1._1.typeId)
),
ptj.map(_._1._1.idx)
),
jsonGroupArrayFilterNullDistinct[protocol.Station](
jsonObject8(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.updraft0.controltower.server.endpoints

import org.updraft0.controltower.build.BuildInfo
import org.updraft0.controltower.constant.SystemId
import org.updraft0.controltower.protocol.*
import org.updraft0.controltower.server.Server.EndpointEnv
import org.updraft0.controltower.server.db.ReferenceQueries
Expand All @@ -20,6 +21,14 @@ def getSolarSystem = Endpoints.getSolarSystem.zServerLogic { name =>
}
}

def getSolarSystemById = Endpoints.getSolarSystemById.zServerLogic { id =>
ReferenceQueries.getSolarSystemById(SystemId(id)).flatMapError(logDbError).flatMap {
case Nil => ZIO.fail(StatusCode.NotFound -> "")
case ss :: Nil => ZIO.succeed(ss)
case _ => ZIO.fail(StatusCode.InternalServerError -> "BUG: non-unique solar system")
}
}

def getVersion = Endpoints.getVersion.zServerLogic(_ =>
getLatestVersion
.flatMapError(logDbError)
Expand Down Expand Up @@ -50,7 +59,7 @@ def getAllReference = Endpoints.getAllReference.zServerLogic(_ =>
)

def getAllSolarSystems = Endpoints.getAllSolarSystems.zServerLogic(_ =>
(getLatestVersion <&> ReferenceQueries.getSolarSystemsByName(None))
(getLatestVersion <&> ReferenceQueries.getSolarSystemsByName(None, None))
.flatMapError(logDbError)
.flatMap((versionOpt, solarSystems) =>
versionOpt
Expand All @@ -72,6 +81,7 @@ def getSignaturesInGroup =
def allReferenceEndpoints: List[ZServerEndpoint[EndpointEnv, Any]] =
List(
getSolarSystem.widen[EndpointEnv],
getSolarSystemById.widen[EndpointEnv],
getVersion.widen[EndpointEnv],
getAllReference.widen[EndpointEnv],
getAllSolarSystems.widen[EndpointEnv],
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ $box-height: 40px;
color: $red;
}

.system-class-pochven {
.system-class-pochven, .system-class-void, .system-class-abyssal20, .system-class-abyssal21, .system-class-abyssal22, .system-class-abyssal22 {
color: $red-dark;
}

Expand Down

0 comments on commit caf920b

Please sign in to comment.