228 lines
6.5 KiB
Swift
228 lines
6.5 KiB
Swift
import CasePaths
|
|
import Foundation
|
|
import PsychrometricClient
|
|
@preconcurrency import URLRouting
|
|
|
|
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.view)) {
|
|
View.router
|
|
}
|
|
}
|
|
}
|
|
|
|
public extension SiteRoute {
|
|
|
|
enum Api: Equatable, Sendable {
|
|
|
|
case calculateDehumidifierSize(DehumidifierSize.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.calculateDehumidifierSize)) {
|
|
Path { "api"; "v1"; "calculateDehumidifierSize" }
|
|
Method.post
|
|
Body(.json(DehumidifierSize.Request.self))
|
|
}
|
|
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 {
|
|
|
|
case index
|
|
case dehumidifierSize(DehumidifierSize)
|
|
case hvacSystemPerformance(HVACSystemPerformance)
|
|
case moldRisk(MoldRisk)
|
|
case roomPressure(RoomPressure)
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index)) {
|
|
Method.get
|
|
}
|
|
Route(.case(Self.dehumidifierSize)) {
|
|
DehumidifierSize.router
|
|
}
|
|
Route(.case(Self.hvacSystemPerformance)) {
|
|
HVACSystemPerformance.router
|
|
}
|
|
Route(.case(Self.moldRisk)) {
|
|
MoldRisk.router
|
|
}
|
|
Route(.case(Self.roomPressure)) {
|
|
RoomPressure.router
|
|
}
|
|
}
|
|
|
|
public enum DehumidifierSize: Equatable, Sendable {
|
|
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 HVACSystemPerformance: Equatable, Sendable {
|
|
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 {
|
|
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 {
|
|
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("form") { 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))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|