Bläddra i källkod

Added tabletserial to database and responses

v2_uploadImages
Mike Carman 1 år sedan
förälder
incheckning
87eac42ba9
6 ändrade filer med 85 tillägg och 27 borttagningar
  1. Binär
      .swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate
  2. +26
    -10
      .swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  3. +6
    -3
      Sources/App/Controllers/FuelEntryV2Controller.swift
  4. +14
    -0
      Sources/App/Migrations/CreateFuelEntry.swift
  5. +10
    -3
      Sources/App/Models/FuelEntry.swift
  6. +29
    -11
      Sources/App/configure.swift

Binär
.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate Visa fil


+ 26
- 10
.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist Visa fil

@@ -7,32 +7,48 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0D883F56-3D27-47AF-9A0F-FB7002B97483"
uuid = "1165C094-7F83-4580-9E1E-36ACC4A42F04"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/App/Controllers/FuelEntryV2Controller.swift"
filePath = "Sources/App/Models/FuelEntry.swift"
startingColumnNumber = "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">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "9FE35DE3-425A-4496-B588-D62D17C197D1"
uuid = "F812306B-8399-447C-84BE-4AC7A776D420"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/App/Controllers/FuelEntryV2Controller.swift"
filePath = "Sources/App/Models/FuelEntry.swift"
startingColumnNumber = "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">
</BreakpointContent>
</BreakpointProxy>


+ 6
- 3
Sources/App/Controllers/FuelEntryV2Controller.swift Visa fil

@@ -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)


+ 14
- 0
Sources/App/Migrations/CreateFuelEntry.swift Visa fil

@@ -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()
}
}


+ 10
- 3
Sources/App/Models/FuelEntry.swift Visa fil

@@ -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
}
}

+ 29
- 11
Sources/App/configure.swift Visa fil

@@ -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


Laddar…
Avbryt
Spara