|
|
|
@@ -1,5 +1,5 @@ |
|
|
|
// |
|
|
|
// Location.swift |
|
|
|
// cntrlFuel.swift |
|
|
|
// |
|
|
|
// |
|
|
|
// Created by Michiel Carman on 4/1/24. |
|
|
|
@@ -8,9 +8,9 @@ |
|
|
|
import Fluent |
|
|
|
import Vapor |
|
|
|
|
|
|
|
struct cntrlLocation: RouteCollection { |
|
|
|
struct cntrlFuel: RouteCollection { |
|
|
|
func boot(routes: RoutesBuilder) throws { |
|
|
|
let rts = routes.grouped("locations") |
|
|
|
let rts = routes.grouped("fuels") |
|
|
|
rts.get(use: index) |
|
|
|
rts.post(use: create) |
|
|
|
rts.put(use: update) |
|
|
|
@@ -19,18 +19,18 @@ struct cntrlLocation: RouteCollection { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func index(req: Request) async throws -> [mdlLocation] { |
|
|
|
try await mdlLocation.query(on: req.db).all() |
|
|
|
func index(req: Request) async throws -> [mdlFuel] { |
|
|
|
try await mdlFuel.query(on: req.db).all() |
|
|
|
} |
|
|
|
|
|
|
|
func create(req: Request) async throws -> mdlLocation { |
|
|
|
let obj = try req.content.decode(mdlLocation.self) |
|
|
|
func create(req: Request) async throws -> mdlFuel { |
|
|
|
let obj = try req.content.decode(mdlFuel.self) |
|
|
|
try await obj.save(on: req.db) |
|
|
|
return obj |
|
|
|
} |
|
|
|
func update(req: Request) async throws -> mdlLocation{ |
|
|
|
let obj = try req.content.decode(mdlLocation.self) |
|
|
|
let dbobj = try await mdlLocation.query(on: req.db).filter(\.$id == obj.id!).first()! |
|
|
|
func update(req: Request) async throws -> mdlFuel{ |
|
|
|
let obj = try req.content.decode(mdlFuel.self) |
|
|
|
let dbobj = try await mdlFuel.query(on: req.db).filter(\.$id == obj.id!).first()! |
|
|
|
|
|
|
|
dbobj.updatedate = Date() |
|
|
|
dbobj.updateuserid = -1 |
|
|
|
@@ -40,7 +40,7 @@ struct cntrlLocation: RouteCollection { |
|
|
|
} |
|
|
|
|
|
|
|
func delete(req: Request) async throws -> HTTPStatus { |
|
|
|
guard let obj = try await mdlLocation.find(req.parameters.get("id"), on: req.db) else { |
|
|
|
guard let obj = try await mdlFuel.find(req.parameters.get("id"), on: req.db) else { |
|
|
|
throw Abort(.notFound) |
|
|
|
} |
|
|
|
try await obj.delete(on: req.db) |