| @@ -7,32 +7,48 @@ | |||||
| <BreakpointProxy | <BreakpointProxy | ||||
| BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | ||||
| <BreakpointContent | <BreakpointContent | ||||
| uuid = "0D883F56-3D27-47AF-9A0F-FB7002B97483" | |||||
| uuid = "1165C094-7F83-4580-9E1E-36ACC4A42F04" | |||||
| shouldBeEnabled = "Yes" | shouldBeEnabled = "Yes" | ||||
| ignoreCount = "0" | ignoreCount = "0" | ||||
| continueAfterRunningActions = "No" | continueAfterRunningActions = "No" | ||||
| filePath = "Sources/App/Controllers/FuelEntryV2Controller.swift" | |||||
| filePath = "Sources/App/Models/FuelEntry.swift" | |||||
| startingColumnNumber = "9223372036854775807" | startingColumnNumber = "9223372036854775807" | ||||
| endingColumnNumber = "9223372036854775807" | endingColumnNumber = "9223372036854775807" | ||||
| startingLineNumber = "645" | |||||
| endingLineNumber = "645" | |||||
| landmarkName = "create(req:)" | |||||
| startingLineNumber = "213" | |||||
| endingLineNumber = "213" | |||||
| landmarkName = "init(id:timestamp:userID:latitude:longitude:product:make:model:serialNumber:tankID:fuelAmount:fuelType:isOverride:tabletserial:)" | |||||
| landmarkType = "7"> | landmarkType = "7"> | ||||
| </BreakpointContent> | </BreakpointContent> | ||||
| </BreakpointProxy> | </BreakpointProxy> | ||||
| <BreakpointProxy | <BreakpointProxy | ||||
| BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | ||||
| <BreakpointContent | <BreakpointContent | ||||
| uuid = "9FE35DE3-425A-4496-B588-D62D17C197D1" | |||||
| uuid = "F812306B-8399-447C-84BE-4AC7A776D420" | |||||
| shouldBeEnabled = "Yes" | shouldBeEnabled = "Yes" | ||||
| ignoreCount = "0" | ignoreCount = "0" | ||||
| continueAfterRunningActions = "No" | continueAfterRunningActions = "No" | ||||
| filePath = "Sources/App/Controllers/FuelEntryV2Controller.swift" | |||||
| filePath = "Sources/App/Models/FuelEntry.swift" | |||||
| startingColumnNumber = "9223372036854775807" | startingColumnNumber = "9223372036854775807" | ||||
| endingColumnNumber = "9223372036854775807" | endingColumnNumber = "9223372036854775807" | ||||
| startingLineNumber = "646" | |||||
| endingLineNumber = "646" | |||||
| landmarkName = "create(req:)" | |||||
| startingLineNumber = "193" | |||||
| endingLineNumber = "193" | |||||
| landmarkName = "init(id:timestamp:userID:latitude:longitude:image:product:make:model:serialNumber:tankID:fuelAmount:fuelType:isOverride:tabletserial:)" | |||||
| landmarkType = "7"> | |||||
| </BreakpointContent> | |||||
| </BreakpointProxy> | |||||
| <BreakpointProxy | |||||
| BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | |||||
| <BreakpointContent | |||||
| uuid = "71BCB6D1-5BA1-44A4-B4BB-3CF6616E1B45" | |||||
| shouldBeEnabled = "Yes" | |||||
| ignoreCount = "0" | |||||
| continueAfterRunningActions = "No" | |||||
| filePath = "Sources/App/Models/FuelEntry.swift" | |||||
| startingColumnNumber = "9223372036854775807" | |||||
| endingColumnNumber = "9223372036854775807" | |||||
| startingLineNumber = "173" | |||||
| endingLineNumber = "173" | |||||
| landmarkName = "init(id:timestamp:userID:latitude:longitude:image:product:make:model:serialNumber:tankID:fuelAmount:fuelType:isOverride:downloaded:tabletserial:)" | |||||
| landmarkType = "7"> | landmarkType = "7"> | ||||
| </BreakpointContent> | </BreakpointContent> | ||||
| </BreakpointProxy> | </BreakpointProxy> | ||||
| @@ -275,6 +275,7 @@ struct FuelEntryV2Controller: RouteCollection { | |||||
| .field(\.$longitude) | .field(\.$longitude) | ||||
| .field(\.$downloaded) | .field(\.$downloaded) | ||||
| .field(\.$loaddate) | .field(\.$loaddate) | ||||
| .field(\.$tabletserial) | |||||
| .group(.and) { | .group(.and) { | ||||
| grp in | grp in | ||||
| grp.filter(\.$loaddate >= startdate) | grp.filter(\.$loaddate >= startdate) | ||||
| @@ -285,7 +286,7 @@ struct FuelEntryV2Controller: RouteCollection { | |||||
| .sort(\.$loaddate, .ascending) | .sort(\.$loaddate, .ascending) | ||||
| .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | ||||
| .all().map{ | .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) | let response = returnObj(data: query, meta: meta) | ||||
| return try await response.encodeResponse(for: req) | return try await response.encodeResponse(for: req) | ||||
| @@ -365,6 +366,7 @@ struct FuelEntryV2Controller: RouteCollection { | |||||
| .field(\.$downloaded) | .field(\.$downloaded) | ||||
| .field(\.$loaddate) | .field(\.$loaddate) | ||||
| .field(\.$image) | .field(\.$image) | ||||
| .field(\.$tabletserial) | |||||
| .group(.and) { | .group(.and) { | ||||
| grp in if(enddate != nil) { | grp in if(enddate != nil) { | ||||
| grp.filter(\.$loaddate >= startdate) | grp.filter(\.$loaddate >= startdate) | ||||
| @@ -378,7 +380,7 @@ struct FuelEntryV2Controller: RouteCollection { | |||||
| .sort(\.$loaddate, .ascending) | .sort(\.$loaddate, .ascending) | ||||
| .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | ||||
| .all().map{ | .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) | let response = returnObj(data: query, meta: meta) | ||||
| return try await response.encodeResponse(for: req) | return try await response.encodeResponse(for: req) | ||||
| @@ -434,6 +436,7 @@ struct FuelEntryV2Controller: RouteCollection { | |||||
| .field(\.$longitude) | .field(\.$longitude) | ||||
| .field(\.$downloaded) | .field(\.$downloaded) | ||||
| .field(\.$loaddate) | .field(\.$loaddate) | ||||
| .field(\.$tabletserial) | |||||
| .group(.and) { | .group(.and) { | ||||
| grp in | grp in | ||||
| grp.filter(\.$timestamp >= startdate ?? Calendar.current.startOfDay(for: Calendar.current.date(byAdding: .day, value: -2, to: Date())!)) | 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) | .sort(\.$loaddate, .ascending) | ||||
| .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | .range(lower: (paging["offset"] as! Int), upper: (paging["offset"] as! Int) + (paging["per"] as! Int)) | ||||
| .all().map{ | .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) | let response = returnObj(data: query, meta: meta) | ||||
| return try await response.encodeResponse(for: req) | return try await response.encodeResponse(for: req) | ||||
| @@ -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() | |||||
| } | |||||
| } | |||||
| @@ -69,6 +69,7 @@ final class FuelEntry: Model, Content { | |||||
| let isOverride: Bool | let isOverride: Bool | ||||
| let image: Data? | let image: Data? | ||||
| let loaddate: Date? | let loaddate: Date? | ||||
| let tabletserial: String? | |||||
| } | } | ||||
| struct wimage: Content{ | struct wimage: Content{ | ||||
| @@ -158,6 +159,9 @@ final class FuelEntry: Model, Content { | |||||
| @Field(key: "downloaded") | @Field(key: "downloaded") | ||||
| var downloaded: Bool? | var downloaded: Bool? | ||||
| @Field(key: "tablet_serial") | |||||
| var tabletserial: String? | |||||
| @Timestamp(key: "loadDate", on: .create) var loaddate: Date? | @Timestamp(key: "loadDate", on: .create) var loaddate: Date? | ||||
| @Timestamp(key: "pullDate", on: .none) var pulldate: Date? | @Timestamp(key: "pullDate", on: .none) var pulldate: Date? | ||||
| @@ -165,7 +169,7 @@ final class FuelEntry: Model, Content { | |||||
| init() {} | 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.id = id | ||||
| self.timestamp = timestamp | self.timestamp = timestamp | ||||
| self.userID = userID | self.userID = userID | ||||
| @@ -182,9 +186,10 @@ final class FuelEntry: Model, Content { | |||||
| self.isOverride = isOverride | self.isOverride = isOverride | ||||
| self.downloaded = downloaded ?? nil | self.downloaded = downloaded ?? nil | ||||
| self.image = image ?? nil | self.image = image ?? nil | ||||
| self.tabletserial = tabletserial ?? nil | |||||
| // self.imageData = imageData | // 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.id = id | ||||
| self.timestamp = timestamp | self.timestamp = timestamp | ||||
| self.userID = userID | self.userID = userID | ||||
| @@ -201,9 +206,10 @@ final class FuelEntry: Model, Content { | |||||
| self.isOverride = isOverride | self.isOverride = isOverride | ||||
| self.downloaded = downloaded ?? nil | self.downloaded = downloaded ?? nil | ||||
| self.image = image ?? nil | self.image = image ?? nil | ||||
| self.tabletserial = tabletserial ?? nil | |||||
| // self.imageData = imageData | // 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.id = id | ||||
| self.timestamp = timestamp | self.timestamp = timestamp | ||||
| self.userID = userID | self.userID = userID | ||||
| @@ -218,6 +224,7 @@ final class FuelEntry: Model, Content { | |||||
| self.fuelAmount = fuelAmount | self.fuelAmount = fuelAmount | ||||
| self.fuelType = fuelType | self.fuelType = fuelType | ||||
| self.isOverride = isOverride | self.isOverride = isOverride | ||||
| self.tabletserial = tabletserial ?? nil | |||||
| // self.imageData = imageData | // self.imageData = imageData | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,5 +1,7 @@ | |||||
| import Fluent | import Fluent | ||||
| import FluentPostgresDriver | import FluentPostgresDriver | ||||
| import NIOSSL | |||||
| import Vapor | import Vapor | ||||
| // configures your application | // configures your application | ||||
| @@ -8,17 +10,32 @@ public func configure(_ app: Application) async throws { | |||||
| // uncomment to serve files from /Public folder | // uncomment to serve files from /Public folder | ||||
| // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) | // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) | ||||
| app.routes.defaultMaxBodySize = "128mb" | 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.http.server.configuration.port = 3002 | ||||
| app.migrations.add(CreateFuelEntry()) | app.migrations.add(CreateFuelEntry()) | ||||
| app.migrations.add(AddLatitudeAndLongitudeAndRemoveGpsLocationAndImage()) | app.migrations.add(AddLatitudeAndLongitudeAndRemoveGpsLocationAndImage()) | ||||
| @@ -32,6 +49,7 @@ public func configure(_ app: Application) async throws { | |||||
| app.migrations.add(UpdateUser2_AddTokenfield()) | app.migrations.add(UpdateUser2_AddTokenfield()) | ||||
| app.migrations.add(UpdateUser3_RemoveTokenfield()) | app.migrations.add(UpdateUser3_RemoveTokenfield()) | ||||
| app.migrations.add(AddLoadDateAndPullDate()) | app.migrations.add(AddLoadDateAndPullDate()) | ||||
| app.migrations.add(AddDeviceSerial()) | |||||
| try await app.autoMigrate().get() | try await app.autoMigrate().get() | ||||
| // register routes | // register routes | ||||