diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate index cd3e620..d08feaa 100644 Binary files a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index eef5c7d..922fb6f 100644 --- a/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -7,32 +7,48 @@ + + + + diff --git a/Sources/App/Controllers/FuelEntryV2Controller.swift b/Sources/App/Controllers/FuelEntryV2Controller.swift index d3f82a7..e343c56 100644 --- a/Sources/App/Controllers/FuelEntryV2Controller.swift +++ b/Sources/App/Controllers/FuelEntryV2Controller.swift @@ -275,6 +275,7 @@ struct FuelEntryV2Controller: RouteCollection { .field(\.$longitude) .field(\.$downloaded) .field(\.$loaddate) + .field(\.$tabletserial) .group(.and) { grp in grp.filter(\.$loaddate >= startdate) @@ -285,7 +286,7 @@ struct FuelEntryV2Controller: RouteCollection { .sort(\.$loaddate, .ascending) .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) .all().map{ - FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: emptyData, loaddate: $0.loaddate) + FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: emptyData, loaddate: $0.loaddate, tabletserial: $0.tabletserial ?? "") } let response = returnObj(data: query, meta: meta) return try await response.encodeResponse(for: req) @@ -365,6 +366,7 @@ struct FuelEntryV2Controller: RouteCollection { .field(\.$downloaded) .field(\.$loaddate) .field(\.$image) + .field(\.$tabletserial) .group(.and) { grp in if(enddate != nil) { grp.filter(\.$loaddate >= startdate) @@ -378,7 +380,7 @@ struct FuelEntryV2Controller: RouteCollection { .sort(\.$loaddate, .ascending) .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) .all().map{ - FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: $0.image, loaddate: $0.loaddate) + FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: $0.image, loaddate: $0.loaddate, tabletserial: $0.tabletserial ?? "") } let response = returnObj(data: query, meta: meta) return try await response.encodeResponse(for: req) @@ -434,6 +436,7 @@ struct FuelEntryV2Controller: RouteCollection { .field(\.$longitude) .field(\.$downloaded) .field(\.$loaddate) + .field(\.$tabletserial) .group(.and) { grp in grp.filter(\.$timestamp >= startdate ?? Calendar.current.startOfDay(for: Calendar.current.date(byAdding: .day, value: -2, to: Date())!)) @@ -444,7 +447,7 @@ struct FuelEntryV2Controller: RouteCollection { .sort(\.$loaddate, .ascending) .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) .all().map{ - FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: emptyData, loaddate: $0.loaddate) + FuelEntry.Output(id: $0.id, timestamp: $0.timestamp, ssid: $0.userID, latitude: $0.latitude, longitude: $0.longitude, product: $0.product, make: $0.make, model: $0.model, serialNumber: $0.serialNumber, tankID: $0.tankID, fuelAmount: $0.fuelAmount, fuelType: $0.fuelType, isOverride: $0.isOverride, image: emptyData, loaddate: $0.loaddate, tabletserial: $0.tabletserial ?? "") } let response = returnObj(data: query, meta: meta) return try await response.encodeResponse(for: req) diff --git a/Sources/App/Migrations/CreateFuelEntry.swift b/Sources/App/Migrations/CreateFuelEntry.swift index 591435d..7c178f5 100755 --- a/Sources/App/Migrations/CreateFuelEntry.swift +++ b/Sources/App/Migrations/CreateFuelEntry.swift @@ -112,3 +112,17 @@ struct AddLoadDateAndPullDate: AsyncMigration { } } +struct AddDeviceSerial: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("fuel_entries") + .field("tablet_serial", .string) + .update() + } + + func revert(on database: Database) async throws { + try await database.schema("fuel_entries") + .deleteField("tablet_serial") + .update() + } +} + diff --git a/Sources/App/Models/FuelEntry.swift b/Sources/App/Models/FuelEntry.swift index a3e5a93..cebca8b 100755 --- a/Sources/App/Models/FuelEntry.swift +++ b/Sources/App/Models/FuelEntry.swift @@ -69,6 +69,7 @@ final class FuelEntry: Model, Content { let isOverride: Bool let image: Data? let loaddate: Date? + let tabletserial: String? } struct wimage: Content{ @@ -158,6 +159,9 @@ final class FuelEntry: Model, Content { @Field(key: "downloaded") var downloaded: Bool? + @Field(key: "tablet_serial") + var tabletserial: String? + @Timestamp(key: "loadDate", on: .create) var loaddate: Date? @Timestamp(key: "pullDate", on: .none) var pulldate: Date? @@ -165,7 +169,7 @@ final class FuelEntry: Model, Content { init() {} - init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, image: Data?, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool, downloaded: Bool?) { //imageData: Data? + init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, image: Data?, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool, downloaded: Bool? = nil, tabletserial: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -182,9 +186,10 @@ final class FuelEntry: Model, Content { self.isOverride = isOverride self.downloaded = downloaded ?? nil self.image = image ?? nil + self.tabletserial = tabletserial ?? nil // self.imageData = imageData } - init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, image: Data?, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool) { //imageData: Data? + init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, image: Data?, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool, tabletserial: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -201,9 +206,10 @@ final class FuelEntry: Model, Content { self.isOverride = isOverride self.downloaded = downloaded ?? nil self.image = image ?? nil + self.tabletserial = tabletserial ?? nil // self.imageData = imageData } - init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool) { //imageData: Data? + init(id: UUID? = nil, timestamp: Date, userID: String, latitude: Double, longitude: Double, product: String, make: String, model: String, serialNumber: String, tankID: String, fuelAmount: Double, fuelType: String, isOverride: Bool, tabletserial: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -218,6 +224,7 @@ final class FuelEntry: Model, Content { self.fuelAmount = fuelAmount self.fuelType = fuelType self.isOverride = isOverride + self.tabletserial = tabletserial ?? nil // self.imageData = imageData } } diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 073a191..e88b168 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -1,5 +1,7 @@ import Fluent import FluentPostgresDriver +import NIOSSL + import Vapor // configures your application @@ -8,17 +10,32 @@ public func configure(_ app: Application) async throws { // uncomment to serve files from /Public folder // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) app.routes.defaultMaxBodySize = "128mb" -// let timeout = HTTPClient.Configuration.Timeout(connect: .seconds(300), read: .seconds(300)) -// app.http.client.configuration.timeout = timeout - app.databases.use(.postgres(hostname: "127.0.0.1", port: 5432, username: "mcarman", password: "@ng31F@rm0823262", database: "fueling"), as: .psql) -// app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init( -// hostname: Environment.get("DATABASE_HOST") ?? "localhost", -// port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? 5433, -// username: Environment.get("DATABASE_USERNAME") ?? "mcarman", -// password: Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262", -// database: Environment.get("DATABASE_NAME") ?? "fueling", -// tls: .disable) -// ), as: .psql) + let timeout = HTTPClient.Configuration.Timeout(connect: .seconds(300), read: .seconds(300)) + app.http.client.configuration.timeout = timeout + + let envHost = Environment.get("DATABASE_HOST") ?? "127.0.0.1" + var envPort: Int + switch app.environment { + case .development: + envPort = 5433 + default: + envPort = 5432 + } + let envUsername = Environment.get("DATABASE_USERNAME") ?? "mcarman" + let envPassword = Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262" + let envDB = Environment.get("DATABASE_NAME") ?? "fueling" + + app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init( + hostname: envHost, + port: envPort, + username: envUsername, + password: envPassword, + database: envDB) + ), as: .psql) + + +// app.databases.use(.postgres(hostname: "127.0.0.1", port: 5432, username: "mcarman", password: "@ng31F@rm0823262", database: "fueling"), as: .psql) + app.http.server.configuration.port = 3002 app.migrations.add(CreateFuelEntry()) app.migrations.add(AddLatitudeAndLongitudeAndRemoveGpsLocationAndImage()) @@ -32,6 +49,7 @@ public func configure(_ app: Application) async throws { app.migrations.add(UpdateUser2_AddTokenfield()) app.migrations.add(UpdateUser3_RemoveTokenfield()) app.migrations.add(AddLoadDateAndPullDate()) + app.migrations.add(AddDeviceSerial()) try await app.autoMigrate().get() // register routes