483 lines
16 KiB
Swift
483 lines
16 KiB
Swift
import CasePaths
|
|
@_exported import CoreModels
|
|
import Foundation
|
|
import PsychrometricClient
|
|
@preconcurrency import URLRouting
|
|
|
|
// FIX: Move Routers into their respective model files, to reduce the size / complexity of this file
|
|
// and keep them closer to where changes may need made.
|
|
|
|
// swiftlint:disable type_body_length
|
|
public enum SiteRoute: Equatable, Sendable {
|
|
|
|
// case api(Api)
|
|
case health
|
|
case view(View)
|
|
|
|
public static let router = OneOf {
|
|
// Route(.case(Self.api)) {
|
|
// Api.router
|
|
// }
|
|
Route(.case(Self.health)) {
|
|
Path { "health" }
|
|
Method.get
|
|
}
|
|
Route(.case(Self.view)) {
|
|
View.router
|
|
}
|
|
}
|
|
}
|
|
|
|
// public extension SiteRoute {
|
|
//
|
|
// enum Api: Equatable, Sendable {
|
|
//
|
|
// case calculateAtticVentilation(AtticVentilation.Request)
|
|
// case calculateCapacitor(Capacitor.Request)
|
|
// case calculateDehumidifierSize(DehumidifierSize.Request)
|
|
// case calculateFilterPressureDrop(FilterPressureDrop.Request)
|
|
// case calculateHVACSystemPerformance(HVACSystemPerformance.Request)
|
|
// case calculateMoldRisk(MoldRisk.Request)
|
|
// case calculateRoomPressure(RoomPressure.Request)
|
|
//
|
|
// static let rootPath = Path { "api"; "v1" }
|
|
//
|
|
// public static let router = OneOf {
|
|
// Route(.case(Self.calculateAtticVentilation)) {
|
|
// Path { "api"; "v1"; "calculateAtticPressure" }
|
|
// Method.post
|
|
// Body(.json(AtticVentilation.Request.self))
|
|
// }
|
|
// Route(.case(Self.calculateCapacitor)) {
|
|
// Path { "api"; "v1"; "calculateRoomPressure" }
|
|
// Method.post
|
|
// OneOf {
|
|
// Body(.json(Capacitor.Request.SizeRequest.self))
|
|
// .map(.case(Capacitor.Request.size))
|
|
// Body(.json(Capacitor.Request.TestRequest.self))
|
|
// .map(.case(Capacitor.Request.test))
|
|
// }
|
|
// }
|
|
// Route(.case(Self.calculateDehumidifierSize)) {
|
|
// Path { "api"; "v1"; "calculateDehumidifierSize" }
|
|
// Method.post
|
|
// Body(.json(DehumidifierSize.Request.self))
|
|
// }
|
|
// Route(.case(Self.calculateFilterPressureDrop)) {
|
|
// Path { "api"; "v1"; "calculateFilterPressureDrop" }
|
|
// Method.post
|
|
// OneOf {
|
|
// Body(.json(FilterPressureDrop.Request.Basic.self))
|
|
// .map(.case(FilterPressureDrop.Request.basic))
|
|
// Body(.json(FilterPressureDrop.Request.FanLaw.self))
|
|
// .map(.case(FilterPressureDrop.Request.fanLaw))
|
|
// }
|
|
// }
|
|
// Route(.case(Self.calculateHVACSystemPerformance)) {
|
|
// Path { "api"; "v1"; "calculateHVACSystemPerformance" }
|
|
// Method.post
|
|
// Body(.json(HVACSystemPerformance.Request.self))
|
|
// }
|
|
// Route(.case(Self.calculateMoldRisk)) {
|
|
// Path { "api"; "v1"; "calculateMoldRisk" }
|
|
// Method.post
|
|
// Body(.json(MoldRisk.Request.self))
|
|
// }
|
|
// Route(.case(Self.calculateRoomPressure)) {
|
|
// Path { "api"; "v1"; "calculateRoomPressure" }
|
|
// Method.post
|
|
// OneOf {
|
|
// Body(.json(RoomPressure.Request.KnownAirflow.self))
|
|
// .map(.case(RoomPressure.Request.knownAirflow))
|
|
// Body(.json(RoomPressure.Request.MeasuredPressure.self))
|
|
// .map(.case(RoomPressure.Request.measuredPressure))
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
public extension SiteRoute {
|
|
enum View: Equatable, Sendable, Hashable {
|
|
|
|
case index
|
|
case atticVentilation(AtticVentilation)
|
|
case capacitor(Capacitor)
|
|
case dehumidifierSize(DehumidifierSize)
|
|
case feetOfHead(Self.FeetOfHead)
|
|
case filterPressureDrop(FilterPressureDrop)
|
|
case heatingBalancePoint(HeatingBalancePoint)
|
|
case hvacSystemPerformance(HVACSystemPerformance)
|
|
case hydronicSystemPressure(Self.HydronicSystemPressure)
|
|
case moldRisk(MoldRisk)
|
|
case psychrometrics(Self.Psychrometrics)
|
|
case roomPressure(RoomPressure)
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Method.get
|
|
}
|
|
Route(.case(Self.atticVentilation)) {
|
|
AtticVentilation.router
|
|
}
|
|
Route(.case(Self.capacitor)) {
|
|
Capacitor.router
|
|
}
|
|
Route(.case(Self.dehumidifierSize)) {
|
|
DehumidifierSize.router
|
|
}
|
|
Route(.case(Self.feetOfHead)) {
|
|
FeetOfHead.router
|
|
}
|
|
Route(.case(Self.filterPressureDrop)) {
|
|
FilterPressureDrop.router
|
|
}
|
|
Route(.case(Self.heatingBalancePoint)) {
|
|
HeatingBalancePoint.router
|
|
}
|
|
Route(.case(Self.hvacSystemPerformance)) {
|
|
HVACSystemPerformance.router
|
|
}
|
|
Route(.case(Self.hydronicSystemPressure)) {
|
|
HydronicSystemPressure.router
|
|
}
|
|
Route(.case(Self.moldRisk)) {
|
|
MoldRisk.router
|
|
}
|
|
Route(.case(Self.psychrometrics)) {
|
|
Self.Psychrometrics.router
|
|
}
|
|
Route(.case(Self.roomPressure)) {
|
|
RoomPressure.router
|
|
}
|
|
}
|
|
|
|
public enum AtticVentilation: Equatable, Sendable, Hashable {
|
|
case index
|
|
case submit(Routes.AtticVentilation.Request)
|
|
|
|
static let rootPath = "attic-ventilation"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
FormData {
|
|
Field("pressureDifferential") { Double.parser() }
|
|
Field("outdoorTemperature") { Double.parser() }
|
|
Field("outdoorDewpoint") { Double.parser() }
|
|
Field("atticTemperature") { Double.parser() }
|
|
Field("atticDewpoint") { Double.parser() }
|
|
Field("atticFloorArea") { Double.parser() }
|
|
Optionally { Field("existingIntakeArea") { Double.parser() } }
|
|
Optionally { Field("existingExhaustArea") { Double.parser() } }
|
|
}
|
|
.map(.memberwise(Routes.AtticVentilation.Request.init))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum Capacitor: Equatable, Sendable, Hashable {
|
|
case index(mode: Routes.Capacitor.Mode? = nil)
|
|
case submit(Routes.Capacitor.Request)
|
|
|
|
public static var index: Self { .index() }
|
|
|
|
static let rootPath = "capacitor-calculator"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
Query {
|
|
Optionally { Field("mode") { Routes.Capacitor.Mode.parser() } }
|
|
}
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
OneOf {
|
|
FormData {
|
|
Field("runningAmps") { Double.parser() }
|
|
Field("lineVoltage") { Double.parser() }
|
|
Field("powerFactor") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.Capacitor.Request.SizeRequest.init))
|
|
.map(.case(Routes.Capacitor.Request.size))
|
|
|
|
FormData {
|
|
Field("startWindingAmps") { Double.parser() }
|
|
Field("runToCommonVoltage") { Double.parser() }
|
|
Optionally {
|
|
Field("ratedCapacitorSize") { Int.parser() }
|
|
}
|
|
}
|
|
.map(.memberwise(Routes.Capacitor.Request.TestRequest.init))
|
|
.map(.case(Routes.Capacitor.Request.test))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum DehumidifierSize: Equatable, Sendable, Hashable {
|
|
case index
|
|
case submit(Routes.DehumidifierSize.Request)
|
|
|
|
static let rootPath = "dehumidifier-sizing"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
FormData {
|
|
Field("latentLoad") { Double.parser() }
|
|
Field("temperature") { Double.parser() }
|
|
Field("humidity") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.DehumidifierSize.Request.init))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum FilterPressureDrop: Equatable, Sendable, Hashable {
|
|
case index(mode: Routes.FilterPressureDrop.Mode? = nil)
|
|
case submit(Routes.FilterPressureDrop.Request)
|
|
|
|
public static let index = Self.index()
|
|
|
|
static let rootPath = "filter-pressure-drop"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
Query {
|
|
Optionally { Field("mode") { Routes.FilterPressureDrop.Mode.parser() } }
|
|
}
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
OneOf {
|
|
FormData {
|
|
Field("systemSize") { Double.parser() }
|
|
Field("climateZone") { ClimateZone.ZoneType.parser() }
|
|
Field("filterType") { Routes.FilterPressureDrop.FilterType.parser() }
|
|
Field("filterWidth") { Double.parser() }
|
|
Field("filterHeight") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.FilterPressureDrop.Request.Basic.init))
|
|
.map(.case(Routes.FilterPressureDrop.Request.basic))
|
|
|
|
FormData {
|
|
Field("filterWidth") { Double.parser() }
|
|
Field("filterHeight") { Double.parser() }
|
|
Field("filterDepth") { Double.parser() }
|
|
Field("ratedAirflow") { Double.parser() }
|
|
Field("ratedPressureDrop") { Double.parser() }
|
|
Field("designAirflow") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.FilterPressureDrop.Request.FanLaw.init))
|
|
.map(.case(Routes.FilterPressureDrop.Request.fanLaw))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum HeatingBalancePoint: Equatable, Sendable, Hashable {
|
|
case index(
|
|
mode: Routes.HeatingBalancePoint.Mode? = nil,
|
|
heatLossMode: Routes.HeatingBalancePoint.HeatLoss.Mode? = nil
|
|
)
|
|
case heatLossFields(mode: Routes.HeatingBalancePoint.HeatLoss.Mode)
|
|
case submit(Routes.HeatingBalancePoint.Request)
|
|
|
|
public static var index: Self { index() }
|
|
|
|
static let rootPath = "balance-point"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
Query {
|
|
Optionally { Field("mode") { Routes.HeatingBalancePoint.Mode.parser() } }
|
|
Optionally { Field("heatLossMode") { Routes.HeatingBalancePoint.HeatLoss.Mode.parser() } }
|
|
}
|
|
}
|
|
Route(.case(Self.heatLossFields)) {
|
|
Path { rootPath; "heat-loss" }
|
|
Method.get
|
|
Query {
|
|
Field("mode") { Routes.HeatingBalancePoint.HeatLoss.Mode.parser() }
|
|
}
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
OneOf {
|
|
// Economic balance point
|
|
FormData {
|
|
Field("fuelType") { Routes.HeatingBalancePoint.FuelType.parser() }
|
|
Field("fuelCostPerUnit") { Double.parser() }
|
|
Field("fuelAFUE") { Double.parser() }
|
|
Field("costPerKW") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.HeatingBalancePoint.Request.Economic.init))
|
|
.map(.case(Routes.HeatingBalancePoint.Request.economic))
|
|
|
|
// Thermal Balance Point
|
|
FormData {
|
|
Field("systemSize") { Double.parser() }
|
|
Optionally { Field("capacityAt47") { Double.parser() } }
|
|
Optionally { Field("capacityAt17") { Double.parser() } }
|
|
Optionally { Field("heatingDesignTemperature") { Double.parser() } }
|
|
OneOf {
|
|
Field("knownHeatLoss") { Double.parser() }
|
|
.map(.case(Routes.HeatingBalancePoint.HeatLoss.known))
|
|
Field("simplifiedHeatLoss") { Double.parser() }
|
|
.map(.case(Routes.HeatingBalancePoint.HeatLoss.estimated))
|
|
}
|
|
Optionally { Field("climateZone") { ClimateZone.parser() } }
|
|
}
|
|
.map(.memberwise(Routes.HeatingBalancePoint.Request.Thermal.init))
|
|
.map(.case(Routes.HeatingBalancePoint.Request.thermal))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum HVACSystemPerformance: Equatable, Sendable, Hashable {
|
|
case index
|
|
case submit(Routes.HVACSystemPerformance.Request)
|
|
|
|
static let rootPath = "hvac-system-performance"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
FormData {
|
|
Optionally { Field("altitude") { Double.parser() } }
|
|
Field("airflow") { Double.parser() }
|
|
Field("returnAirTemperature") { Double.parser() }
|
|
Field("returnAirHumidity") { Double.parser() }
|
|
Field("supplyAirTemperature") { Double.parser() }
|
|
Field("supplyAirHumidity") { Double.parser() }
|
|
Field("systemSize") { Double.parser() }
|
|
}
|
|
.map(.memberwise(Routes.HVACSystemPerformance.Request.init))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum MoldRisk: Equatable, Sendable, Hashable {
|
|
case index
|
|
case submit(Routes.MoldRisk.Request)
|
|
|
|
static let rootPath = "mold-risk"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
}
|
|
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
FormData {
|
|
Field("temperature") {
|
|
Double.parser()
|
|
}
|
|
Field("humidity") {
|
|
Double.parser()
|
|
}
|
|
}
|
|
.map(.memberwise(Routes.MoldRisk.Request.init))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum RoomPressure: Equatable, Sendable, Hashable {
|
|
case index(mode: Routes.RoomPressure.Mode? = nil)
|
|
case submit(Routes.RoomPressure.Request)
|
|
|
|
public static var index: Self { .index() }
|
|
|
|
static let rootPath = "room-pressure"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Path { rootPath }
|
|
Method.get
|
|
Query {
|
|
Optionally { Field("mode") { Routes.RoomPressure.Mode.parser() } }
|
|
}
|
|
}
|
|
Route(.case(Self.submit)) {
|
|
Path { rootPath }
|
|
Method.post
|
|
Body {
|
|
OneOf {
|
|
FormData {
|
|
Field("targetRoomPressure") { Double.parser() }
|
|
Field("doorWidth") { Double.parser() }
|
|
Field("doorHeight") { Double.parser() }
|
|
Field("doorUndercut") { Double.parser() }
|
|
Field("supplyAirflow") { Double.parser() }
|
|
Field("preferredGrilleHeight") {
|
|
Routes.RoomPressure.CommonReturnGrilleHeight.parser()
|
|
}
|
|
}
|
|
.map(.memberwise(Routes.RoomPressure.Request.KnownAirflow.init))
|
|
.map(.case(Routes.RoomPressure.Request.knownAirflow))
|
|
|
|
FormData {
|
|
Field("measuredRoomPressure") { Double.parser() }
|
|
Field("doorWidth") { Double.parser() }
|
|
Field("doorHeight") { Double.parser() }
|
|
Field("doorUndercut") { Double.parser() }
|
|
Field("preferredGrilleHeight") {
|
|
Routes.RoomPressure.CommonReturnGrilleHeight.parser()
|
|
}
|
|
}
|
|
.map(.memberwise(Routes.RoomPressure.Request.MeasuredPressure.init))
|
|
.map(.case(Routes.RoomPressure.Request.measuredPressure))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// swiftlint:enable type_body_length
|