|
|
|
@@ -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<String, String?> = try req.query.decode(Dictionary<String, String?>.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<String, String?> = try req.query.decode(Dictionary<String, String?>.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<String, String?> = try req.query.decode(Dictionary<String, String?>.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) |
|
|
|
|