feat: Initial csv parsing for uploading rooms for a project. Need to style the upload form.
All checks were successful
CI / Linux Tests (push) Successful in 5m41s
All checks were successful
CI / Linux Tests (push) Successful in 5m41s
This commit is contained in:
@@ -96,8 +96,6 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
||||
extension Room {
|
||||
/// Represents the data required to create a new room for a project.
|
||||
public struct Create: Codable, Equatable, Sendable {
|
||||
/// The project this room is associated with.
|
||||
public let projectID: Project.ID
|
||||
/// A unique name for the room in the project.
|
||||
public let name: String
|
||||
/// The heating load required for the room (from Manual-J).
|
||||
@@ -114,14 +112,12 @@ extension Room {
|
||||
}
|
||||
|
||||
public init(
|
||||
projectID: Project.ID,
|
||||
name: String,
|
||||
heatingLoad: Double,
|
||||
coolingTotal: Double? = nil,
|
||||
coolingSensible: Double? = nil,
|
||||
registerCount: Int = 1
|
||||
) {
|
||||
self.projectID = projectID
|
||||
self.name = name
|
||||
self.heatingLoad = heatingLoad
|
||||
self.coolingTotal = coolingTotal
|
||||
@@ -130,6 +126,14 @@ extension Room {
|
||||
}
|
||||
}
|
||||
|
||||
public struct CSV: Equatable, Sendable {
|
||||
public let file: Data
|
||||
|
||||
public init(file: Data) {
|
||||
self.file = file
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a rectangular size calculation that is stored in the
|
||||
/// database for a given room.
|
||||
///
|
||||
|
||||
@@ -188,6 +188,7 @@ extension SiteRoute.View.ProjectRoute {
|
||||
}
|
||||
|
||||
public enum RoomRoute: Equatable, Sendable {
|
||||
case csv(Room.CSV)
|
||||
case delete(id: Room.ID)
|
||||
case index
|
||||
case submit(Room.Create)
|
||||
@@ -197,6 +198,23 @@ extension SiteRoute.View.ProjectRoute {
|
||||
static let rootPath = "rooms"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.csv)) {
|
||||
Path {
|
||||
rootPath
|
||||
"csv"
|
||||
}
|
||||
Headers {
|
||||
Field("Content-Type") { "multipart/form-data" }
|
||||
}
|
||||
Method.post
|
||||
Body().map(.memberwise(Room.CSV.init))
|
||||
// Body {
|
||||
// FormData {
|
||||
//
|
||||
// }
|
||||
// .map(.memberwise(Room.CSV.init))
|
||||
// }
|
||||
}
|
||||
Route(.case(Self.delete)) {
|
||||
Path {
|
||||
rootPath
|
||||
@@ -215,7 +233,7 @@ extension SiteRoute.View.ProjectRoute {
|
||||
Method.post
|
||||
Body {
|
||||
FormData {
|
||||
Field("projectID") { Project.ID.parser() }
|
||||
// Field("projectID") { Project.ID.parser() }
|
||||
Field("name", .string)
|
||||
Field("heatingLoad") { Double.parser() }
|
||||
Optionally {
|
||||
|
||||
Reference in New Issue
Block a user