25 lines
635 B
Swift
25 lines
635 B
Swift
import Models
|
|
import Validations
|
|
|
|
extension RequiredKW.Request {
|
|
func respond() async throws -> RequiredKW.Response {
|
|
try await validate()
|
|
let capacityAtDesign = self.capacityAtDesign ?? 0
|
|
let requiredKW = (Double(heatLoss) - Double(capacityAtDesign)) / 3413
|
|
return .init(requiredKW: requiredKW)
|
|
}
|
|
}
|
|
|
|
extension RequiredKW.Request: AsyncValidatable {
|
|
|
|
@inlinable
|
|
public var body: some AsyncValidation<Self> {
|
|
AsyncValidator.accumulating {
|
|
AsyncValidator.greaterThan(\.heatLoss, 0)
|
|
AsyncValidator.validate(\.capacityAtDesign) {
|
|
AsyncValidator.greaterThan(0).optional()
|
|
}
|
|
}
|
|
}
|
|
}
|