|
|
|
@@ -18,6 +18,7 @@ struct FuelEntryV2Controller: RouteCollection { |
|
|
|
tokenAuthGroup.get("test", use: filtered) |
|
|
|
// fuelEntries.get("with-images", use: getAllEntriesWithImages) |
|
|
|
tokenAuthGroup.post(use: create) |
|
|
|
tokenAuthGroup.put( use: softdelete) |
|
|
|
// fuelEntries.post("upload-image", use: uploadImage) |
|
|
|
tokenAuthGroup.group(":fuelEntryID") { fuelEntry in |
|
|
|
fuelEntry.delete(use: delete) |
|
|
|
@@ -34,6 +35,26 @@ struct FuelEntryV2Controller: RouteCollection { |
|
|
|
var pages: Int |
|
|
|
} |
|
|
|
|
|
|
|
struct dload: Content{ |
|
|
|
var id: UUID |
|
|
|
} |
|
|
|
|
|
|
|
@Sendable |
|
|
|
func softdelete(req: Request) async throws -> Response { |
|
|
|
let ids = try req.content.decode([dload].self) |
|
|
|
var msg: [String] = [] |
|
|
|
for id in ids { |
|
|
|
guard let fe = try await FuelEntry.find(id.id, on: req.db) else { |
|
|
|
msg.append("create error message for item") |
|
|
|
continue |
|
|
|
} |
|
|
|
fe.downloaded = true |
|
|
|
try await fe.save(on: req.db) |
|
|
|
} |
|
|
|
let response = Response(status: .ok, body: "good") |
|
|
|
return response |
|
|
|
} |
|
|
|
|
|
|
|
@Sendable |
|
|
|
func filtered(req: Request) async throws -> Response { |
|
|
|
|
|
|
|
@@ -75,6 +96,8 @@ struct FuelEntryV2Controller: RouteCollection { |
|
|
|
.field(\.$longitude) |
|
|
|
.field(\.$image) |
|
|
|
.field(\.$downloaded) |
|
|
|
//.filter(\.$image != nil) |
|
|
|
|
|
|
|
} else { |
|
|
|
query = query |
|
|
|
.field(\.$id) |
|
|
|
@@ -101,8 +124,9 @@ struct FuelEntryV2Controller: RouteCollection { |
|
|
|
.filter(\.$tankID == tank) |
|
|
|
} |
|
|
|
if(image){ |
|
|
|
//query = query.filter(\.$image) |
|
|
|
let wimage = try await query.paginate(for: req).map{ |
|
|
|
img in FuelEntry.wimage(id: img.id, timestamp: img.timestamp, userID: img.userID, latitude: img.latitude, longitutde: img.longitude, product: img.product, make: img.make, model: img.model, serialNumber: img.serialNumber, tankID: img.tankID, fuelAmount: img.fuelAmount, fuelType: img.fuelType, isOverride: img.isOverride, image: img.image!, downloaded: img.downloaded!) |
|
|
|
img in FuelEntry.wimage(id: img.id, timestamp: img.timestamp, userID: img.userID, latitude: img.latitude, longitutde: img.longitude, product: img.product, make: img.make, model: img.model, serialNumber: img.serialNumber, tankID: img.tankID, fuelAmount: img.fuelAmount, fuelType: img.fuelType, isOverride: img.isOverride, image: img.image == nil ? Data(): img.image, downloaded: img.downloaded!) |
|
|
|
} |
|
|
|
return try await wimage.encodeResponse(for: req) |
|
|
|
} else { |
|
|
|
@@ -216,3 +240,8 @@ struct PageRequest: Content { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|