diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mcarman.xcuserdatad/UserInterfaceState.xcuserstate index b50e365..3f8b46d 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 a53316c..eef5c7d 100644 --- a/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/.swiftpm/xcode/xcuserdata/mcarman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -4,54 +4,6 @@ type = "1" version = "2.0"> - - - - - - - - - - - - @@ -78,8 +30,8 @@ filePath = "Sources/App/Controllers/FuelEntryV2Controller.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "617" - endingLineNumber = "617" + startingLineNumber = "646" + endingLineNumber = "646" landmarkName = "create(req:)" landmarkType = "7"> diff --git a/Sources/App/Controllers/FuelEntryV2Controller.swift b/Sources/App/Controllers/FuelEntryV2Controller.swift index dfda1d5..d3f82a7 100644 --- a/Sources/App/Controllers/FuelEntryV2Controller.swift +++ b/Sources/App/Controllers/FuelEntryV2Controller.swift @@ -211,17 +211,29 @@ struct FuelEntryV2Controller: RouteCollection { } fileprivate func getMaximError(_ req: Request, _ message: String) async throws -> returnObj { + let rt = req.route!.description.replacingOccurrences(of: "GET ", with: "").replacingOccurrences(of: "PUT ", with: "").replacingOccurrences(of: "POST ", with: "").replacingOccurrences(of: "DELETE ", with: "") + let method = req.method.rawValue + let baseurl = "https://fueling.prelub.com" let data : [FuelEntry.Output] = [] - let meta = Meta(page: 0, per: 0, total: 0, lastpage: true, error: true, message: message, queryparameters: try await getParams(req) ) + let meta = Meta(page: 0, per: 0, total: 0, lastpage: true, error: true, message: message, method: method, baseurl: baseurl, route: rt, querystring: "" ) return returnObj(data: data, meta: meta) } @Sendable func filterLoadDate(req: Request) async throws -> Response { + let rt = req.route!.description.replacingOccurrences(of: "GET ", with: "").replacingOccurrences(of: "PUT ", with: "").replacingOccurrences(of: "POST ", with: "").replacingOccurrences(of: "DELETE ", with: "") + let method = req.method.rawValue + let baseurl = "https://fueling.prelub.com" let qstring = req.query + let components: Dictionary = try req.query.decode(Dictionary.self) + var startdate : Date? + var qs: [String] = [] + for component in components { + qs.append( "\(component.key)=\(component.value ?? "nil")") + } if(try qstring.get(String?.self, at: "startdate") != nil) { startdate = try parseDate2(qstring.get(String?.self, at: "startdate") ?? "") if(startdate == nil) { @@ -241,9 +253,12 @@ struct FuelEntryV2Controller: RouteCollection { let emptyData: Data? = Data() let page = try qstring.get(Int?.self, at: "page") ?? 1 let per = try qstring.get(Int?.self, at: "per") ?? 10 + let qsStr = qs.joined(separator: "&") + let records = try await getCount(req, generateSQLNoImage(startdate ?? nil, enddate ?? nil) ) + let paging = try await getPaging(page, per, records) - let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", queryparameters: try await getParams(req) ) + let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", method: method, baseurl: baseurl, route: rt, querystring: "?\(qsStr)") let query = try await FuelEntry.query(on: req.db) .field(\.$id) .field(\.$timestamp) @@ -278,9 +293,16 @@ struct FuelEntryV2Controller: RouteCollection { @Sendable func filterImages(req: Request) async throws -> Response { - + let rt = req.route!.description.replacingOccurrences(of: "GET ", with: "").replacingOccurrences(of: "PUT ", with: "").replacingOccurrences(of: "POST ", with: "").replacingOccurrences(of: "DELETE ", with: "") + let method = req.method.rawValue + let baseurl = "https://fueling.prelub.com" let qstring = req.query + let components: Dictionary = try req.query.decode(Dictionary.self) var startdate : Date? + var qs: [String] = [] + for component in components { + qs.append( "\(component.key)=\(component.value ?? "nil")") + } if(try qstring.get(String?.self, at: "startdate") != nil) { startdate = try parseDate2(qstring.get(String?.self, at: "startdate") ?? "") if(startdate == nil) { @@ -322,10 +344,10 @@ struct FuelEntryV2Controller: RouteCollection { .all() .count } - + let qsStr = qs.joined(separator: "&") let paging = try await getPaging(page, per, records) - let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", queryparameters: try await getParams(req) ) + let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", method: method, baseurl: baseurl, route: rt, querystring: "?\(qsStr)") let query = try await FuelEntry.query(on: req.db) .field(\.$id) .field(\.$timestamp) @@ -364,9 +386,16 @@ struct FuelEntryV2Controller: RouteCollection { @Sendable func filterTimeStamp(req: Request) async throws -> Response { - + let rt = req.route!.description.replacingOccurrences(of: "GET ", with: "").replacingOccurrences(of: "PUT ", with: "").replacingOccurrences(of: "POST ", with: "").replacingOccurrences(of: "DELETE ", with: "") + let method = req.method.rawValue + let baseurl = "https://fueling.prelub.com" let qstring = req.query + let components: Dictionary = try req.query.decode(Dictionary.self) var startdate : Date? + var qs: [String] = [] + for component in components { + qs.append( "\(component.key)=\(component.value ?? "nil")") + } if(try qstring.get(String?.self, at: "startdate") != nil) { startdate = try parseDate2(qstring.get(String?.self, at: "startdate") ?? "") if(startdate == nil) { @@ -388,7 +417,7 @@ struct FuelEntryV2Controller: RouteCollection { let per = try qstring.get(Int?.self, at: "per") ?? 10 let records = try await getCount(req, generateSQLNoImage(startdate ?? nil, enddate ?? nil) ) let paging = try await getPaging(page, per, records) - let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", queryparameters: try await getParams(req) ) + let meta = Meta(page: page, per: per, total: records, lastpage: (paging["lastpage"] != nil) ? paging["lastpage"] as! Bool : false, error: false, message: "", method: method, baseurl: baseurl, route: rt, querystring: "?\(qs.joined(separator: "&"))") let query = try await FuelEntry.query(on: req.db) .field(\.$id) .field(\.$timestamp) diff --git a/Sources/App/Helpers/PageHelper.swift b/Sources/App/Helpers/PageHelper.swift index 9e3265c..2c18690 100644 --- a/Sources/App/Helpers/PageHelper.swift +++ b/Sources/App/Helpers/PageHelper.swift @@ -36,7 +36,10 @@ public struct Meta: Content{ let lastpage: Bool let error: Bool let message: String? - let queryparameters: [qparam] + let method: String? + let baseurl: String? + let route: String? + let querystring: String? } public struct qparam: Content{ diff --git a/Sources/App/Models/FuelEntry.swift b/Sources/App/Models/FuelEntry.swift index 375c5ee..a3e5a93 100755 --- a/Sources/App/Models/FuelEntry.swift +++ b/Sources/App/Models/FuelEntry.swift @@ -30,7 +30,7 @@ final class FuelEntry: Model, Content { let loaddate: Date? let pulldate: Date? func toFuelEntry() -> FuelEntry { - var entry = FuelEntry() + let entry = FuelEntry() entry.id = self.id entry.timestamp = self.timestamp entry.userID = self.userID @@ -90,7 +90,7 @@ final class FuelEntry: Model, Content { let loaddate: Date? let pulldate: Date? func toFuelEntry() -> FuelEntry { - var entry = FuelEntry() + let entry = FuelEntry() entry.id = self.id entry.timestamp = self.timestamp entry.userID = self.userID diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 073a191..ffaf095 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -10,7 +10,7 @@ public func configure(_ app: Application) async throws { 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(.postgres(hostname: "127.0.0.1", port: 5433, 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,