// // cntrlCompartmentLocation.swift // // // Created by Michiel Carman on 4/1/24. // import Fluent import Vapor struct cntrlCompartmentLocation: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("compartmentlocations") rts.get(use: index) rts.get(":x", use: read) rts.post(use: create) rts.group(":x") { rt in rts.delete(use: delete) } ///Add custom routes here } func index(req: Request) async throws -> [mdlCompartmentLocation] { try await mdlCompartmentLocation.ObjQuery(req: req).all() } func read(req:Request) async throws -> mdlCompartmentLocation{ return try await mdlCompartmentLocation.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlCompartmentLocation { let obj = try req.content.decode(mdlCompartmentLocation.self) if(obj.id != nil){ obj._$idExists = true } try await obj.save(on: req.db) return obj } func update(req: Request) async throws -> mdlCompartmentLocation{ let obj = try req.content.decode(mdlCompartmentLocation.self) let dbobj = try await mdlCompartmentLocation.query(on: req.db).filter(\.$id == obj.id!).first()! dbobj.updatedate = Date() dbobj.updateuserid = -1 try await dbobj.update(on: req.db) return dbobj } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlCompartmentLocation.find(req.parameters.get("id"), on: req.db) else { throw Abort(.notFound) } try await obj.delete(on: req.db) return .noContent } }