diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate index 4934839..4f812c5 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 bcd2102..0bc865e 100644 --- a/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,8 +14,8 @@ filePath = "Sources/App/Models/FuelEntry.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "245" - endingLineNumber = "245" + startingLineNumber = "247" + endingLineNumber = "247" landmarkName = "init(id:timestamp:userID:latitude:longitude:product:make:model:serialNumber:tankID:fuelAmount:fuelType:isOverride:tabletserial:uniqueID:)" landmarkType = "7"> @@ -30,8 +30,8 @@ filePath = "Sources/App/Models/FuelEntry.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "224" - endingLineNumber = "224" + startingLineNumber = "225" + endingLineNumber = "225" landmarkName = "init(id:timestamp:userID:latitude:longitude:image:product:make:model:serialNumber:tankID:fuelAmount:fuelType:isOverride:tabletserial:uniqueID:)" landmarkType = "7"> @@ -174,8 +174,8 @@ filePath = "Sources/App/Models/FuelEntry.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "291" - endingLineNumber = "291" + startingLineNumber = "293" + endingLineNumber = "293" landmarkName = "init(from:)" landmarkType = "7"> @@ -222,8 +222,8 @@ filePath = "Sources/App/Models/FuelEntry.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "297" - endingLineNumber = "297" + startingLineNumber = "299" + endingLineNumber = "299" landmarkName = "init(from:)" landmarkType = "7"> @@ -260,5 +260,221 @@ landmarkType = "7"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/App/Controllers/V2.2/FuelEntryControllerV2_2.swift b/Sources/App/Controllers/V2.2/FuelEntryControllerV2_2.swift index 9c8569c..a06e81c 100644 --- a/Sources/App/Controllers/V2.2/FuelEntryControllerV2_2.swift +++ b/Sources/App/Controllers/V2.2/FuelEntryControllerV2_2.swift @@ -653,10 +653,13 @@ struct FuelEntryV2ControllerV2_2: RouteCollection { func create(req: Request) async throws -> Response { let fuelEntry = try req.content.decode([FuelEntry.V2_2_Input].self) + var results: [FuelEntry] = [] for entry in fuelEntry { + let uuid = entry.uniqueID + let input = FuelEntry.init(from: entry) - let exists = try await FuelEntry.query(on: req.db).filter(\.$uniqueID, .equal, input.uniqueID).first() + let exists = try await FuelEntry.query(on: req.db).filter(\.$uniqueID, .equal, uuid).first() if(exists == nil) { let data = entry.image ?? nil let length = data?.count @@ -683,7 +686,7 @@ struct FuelEntryV2ControllerV2_2: RouteCollection { // try await fuelEntry.create(on: req.db) let response = try await results.map{ - try FuelEntry.V2_1_Output.init(from: $0) + try FuelEntry.V2_2_Output.init(from: $0) }.encodeResponse(for: req) return response } diff --git a/Sources/App/DTO/V2.2/v2.2.swift b/Sources/App/DTO/V2.2/v2.2.swift index e86c155..a6ada1e 100644 --- a/Sources/App/DTO/V2.2/v2.2.swift +++ b/Sources/App/DTO/V2.2/v2.2.swift @@ -63,7 +63,7 @@ extension FuelEntry { if img { self.image = decoder.image } - self.uniqueID = decoder.uniqueID?.uuidString + self.uniqueID = decoder.uniqueID } } diff --git a/Sources/App/Migrations/CreateFuelEntry.swift b/Sources/App/Migrations/CreateFuelEntry.swift index 0c9181e..359e292 100755 --- a/Sources/App/Migrations/CreateFuelEntry.swift +++ b/Sources/App/Migrations/CreateFuelEntry.swift @@ -110,6 +110,20 @@ struct AddUniqueIDFiled: AsyncMigration { } } +struct ChangeUniqueIDFiled: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("fuel_entries") + .updateField("unique_id", .string) + .update() + } + + func revert(on database: Database) async throws { + try await database.schema("fuel_entries") + .updateField("unique_id", .uuid) + .update() + } +} + struct AddAppVersion: AsyncMigration { func prepare(on database: Database) async throws { try await database.schema("fuel_entries") diff --git a/Sources/App/Models/FuelEntry.swift b/Sources/App/Models/FuelEntry.swift index 7a031ae..3a1a724 100755 --- a/Sources/App/Models/FuelEntry.swift +++ b/Sources/App/Models/FuelEntry.swift @@ -170,13 +170,13 @@ final class FuelEntry: Model, Content { @Timestamp(key: "loadDate", on: .create) var loaddate: Date? @Timestamp(key: "pullDate", on: .none) var pulldate: Date? - @Field(key: "unique_id") var uniqueID: UUID? + @Field(key: "unique_id") var uniqueID: String? // var imageData: Data? 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? = nil, tabletserial: String? = nil, appversion: String? = nil, uniqueID: UUID? = nil) { //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, appversion: String? = nil, uniqueID: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -199,7 +199,7 @@ final class FuelEntry: Model, Content { // 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, downloaded: Bool? = nil, tabletserial: String? = nil, uniqueID: UUID? = nil) { //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, uniqueID: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -220,7 +220,8 @@ final class FuelEntry: Model, Content { self.uniqueID = uniqueID // 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, tabletserial: String? = nil, uniqueID: UUID? = nil) { //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, uniqueID: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -241,7 +242,8 @@ final class FuelEntry: Model, Content { self.uniqueID = uniqueID // 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, tabletserial: String? = nil, uniqueID: UUID? = nil) { //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, uniqueID: String? = nil) { //imageData: Data? self.id = id self.timestamp = timestamp self.userID = userID @@ -317,6 +319,6 @@ final class FuelEntry: Model, Content { self.image = decoder.image self.tabletserial = decoder.tabletSerial ?? "" self.downloaded = false - self.uniqueID = decoder.uniqueID == nil ? nil : UUID(uuidString: decoder.uniqueID!) + self.uniqueID = decoder.uniqueID } } diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index ce8affc..86daf94 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -53,6 +53,7 @@ public func configure(_ app: Application) async throws { app.migrations.add(AddDeviceSerial()) app.migrations.add(AddAppVersion()) app.migrations.add(AddUniqueIDFiled()) + app.migrations.add(ChangeUniqueIDFiled()) try await app.autoMigrate().get() // register routes diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index 7d42f12..5deaf74 100755 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -6,6 +6,8 @@ func routes(_ app: Application) throws { app.routes.defaultMaxBodySize = "64mb"; let V2_1 = app.grouped("api").grouped("v2.1") try V2_1.register(collection: FuelEntryV2ControllerV2_1()) + let v2_2 = app.grouped("api").grouped("v2.2") + try v2_2.register(collection: FuelEntryV2ControllerV2_2()) let v2 = app.grouped("api").grouped("v2") try v2.register(collection: FuelEntryV2Controller()) try v2.register(collection: UserController())