diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..c2e5d02
Binary files /dev/null and b/.DS_Store differ
diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000..919434a
--- /dev/null
+++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/michielcarman.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/michielcarman.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..288c999
Binary files /dev/null and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/michielcarman.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/.swiftpm/xcode/xcuserdata/michielcarman.xcuserdatad/xcschemes/xcschememanagement.plist b/.swiftpm/xcode/xcuserdata/michielcarman.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..d7c4001
--- /dev/null
+++ b/.swiftpm/xcode/xcuserdata/michielcarman.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,14 @@
+
+
+
+
+ SchemeUserState
+
+ connexion_services.xcscheme_^#shared#^_
+
+ orderHint
+ 0
+
+
+
+
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..d0af8ad
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,65 @@
+# ================================
+# Build image
+# ================================
+FROM swift:5.4-focal as build
+
+# Install OS updates and, if needed, sqlite3
+RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
+ && apt-get -q update \
+ && apt-get -q dist-upgrade -y \
+ && rm -rf /var/lib/apt/lists/*
+
+# Set up a build area
+WORKDIR /build
+
+# First just resolve dependencies.
+# This creates a cached layer that can be reused
+# as long as your Package.swift/Package.resolved
+# files do not change.
+COPY ./Package.* ./
+RUN swift package resolve
+
+# Copy entire repo into container
+COPY . .
+
+# Build everything, with optimizations
+RUN swift build -c release
+
+# Switch to the staging area
+WORKDIR /staging
+
+# Copy main executable to staging area
+RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./
+
+# Copy any resouces from the public directory and views directory if the directories exist
+# Ensure that by default, neither the directory nor any of its contents are writable.
+RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
+RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
+
+# ================================
+# Run image
+# ================================
+FROM swift:5.4-focal-slim
+
+# Make sure all system packages are up to date.
+RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
+ apt-get -q update && apt-get -q dist-upgrade -y && rm -r /var/lib/apt/lists/*
+
+# Create a vapor user and group with /app as its home directory
+RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
+
+# Switch to the new home directory
+WORKDIR /app
+
+# Copy built executable and any staged resources from builder
+COPY --from=build --chown=vapor:vapor /staging /app
+
+# Ensure all further commands run as the vapor user
+USER vapor:vapor
+
+# Let Docker bind to port 8080
+EXPOSE 8080
+
+# Start the Vapor service when the image is run, default to listening on 8080 in production environment
+ENTRYPOINT ["./Run"]
+CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
diff --git a/Package.resolved b/Package.resolved
new file mode 100644
index 0000000..4212869
--- /dev/null
+++ b/Package.resolved
@@ -0,0 +1,205 @@
+{
+ "object": {
+ "pins": [
+ {
+ "package": "async-http-client",
+ "repositoryURL": "https://github.com/swift-server/async-http-client.git",
+ "state": {
+ "branch": null,
+ "revision": "1081b0b0541f535ca088acdb56f5ca5598bc6247",
+ "version": "1.6.3"
+ }
+ },
+ {
+ "package": "async-kit",
+ "repositoryURL": "https://github.com/vapor/async-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "f6f92e6d3704bd72ffb4d00e302c98476fe65854",
+ "version": "1.9.0"
+ }
+ },
+ {
+ "package": "console-kit",
+ "repositoryURL": "https://github.com/vapor/console-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "75ea3b627d88221440b878e5dfccc73fd06842ed",
+ "version": "4.2.7"
+ }
+ },
+ {
+ "package": "fluent",
+ "repositoryURL": "https://github.com/vapor/fluent.git",
+ "state": {
+ "branch": null,
+ "revision": "5810a409eb0271a576f68887fa6713dae3985056",
+ "version": "4.3.1"
+ }
+ },
+ {
+ "package": "fluent-kit",
+ "repositoryURL": "https://github.com/vapor/fluent-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "06a6939ff486cb6abae08b2e025b02291cff0da0",
+ "version": "1.15.3"
+ }
+ },
+ {
+ "package": "fluent-postgres-driver",
+ "repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git",
+ "state": {
+ "branch": null,
+ "revision": "0b7a43c78b7ae47eafad5736ab0fdc00aa31ca6f",
+ "version": "2.2.1"
+ }
+ },
+ {
+ "package": "multipart-kit",
+ "repositoryURL": "https://github.com/vapor/multipart-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "82f255699b1de9ba1f34dfc6b99e99aba5a1f8eb",
+ "version": "4.5.0"
+ }
+ },
+ {
+ "package": "postgres-kit",
+ "repositoryURL": "https://github.com/vapor/postgres-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "a050d338b41531bff65bccc87cf2a42871e87ff5",
+ "version": "2.3.3"
+ }
+ },
+ {
+ "package": "postgres-nio",
+ "repositoryURL": "https://github.com/vapor/postgres-nio.git",
+ "state": {
+ "branch": null,
+ "revision": "c5eda6cebfdb81959f96d4ad8fcb1e8fc4596a52",
+ "version": "1.6.3"
+ }
+ },
+ {
+ "package": "routing-kit",
+ "repositoryURL": "https://github.com/vapor/routing-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "a0801a36a6ad501d5ad6285cbcd4774de6b0a734",
+ "version": "4.3.0"
+ }
+ },
+ {
+ "package": "sql-kit",
+ "repositoryURL": "https://github.com/vapor/sql-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "8587674e7e2499fd2017840973f416182025b02d",
+ "version": "3.12.1"
+ }
+ },
+ {
+ "package": "swift-backtrace",
+ "repositoryURL": "https://github.com/swift-server/swift-backtrace.git",
+ "state": {
+ "branch": null,
+ "revision": "d3e04a9d4b3833363fb6192065b763310b156d54",
+ "version": "1.3.1"
+ }
+ },
+ {
+ "package": "swift-crypto",
+ "repositoryURL": "https://github.com/apple/swift-crypto.git",
+ "state": {
+ "branch": null,
+ "revision": "127d3745c37b5705e4bc8d16c7951c48dcc3332c",
+ "version": "2.0.0"
+ }
+ },
+ {
+ "package": "swift-log",
+ "repositoryURL": "https://github.com/apple/swift-log.git",
+ "state": {
+ "branch": null,
+ "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
+ "version": "1.4.2"
+ }
+ },
+ {
+ "package": "swift-metrics",
+ "repositoryURL": "https://github.com/apple/swift-metrics.git",
+ "state": {
+ "branch": null,
+ "revision": "3edd2f57afc4e68e23c3e4956bc8b65ca6b5b2ff",
+ "version": "2.2.0"
+ }
+ },
+ {
+ "package": "swift-nio",
+ "repositoryURL": "https://github.com/apple/swift-nio.git",
+ "state": {
+ "branch": null,
+ "revision": "6aa9347d9bc5bbfe6a84983aec955c17ffea96ef",
+ "version": "2.33.0"
+ }
+ },
+ {
+ "package": "swift-nio-extras",
+ "repositoryURL": "https://github.com/apple/swift-nio-extras.git",
+ "state": {
+ "branch": null,
+ "revision": "f73ca5ee9c6806800243f1ac415fcf82de9a4c91",
+ "version": "1.10.2"
+ }
+ },
+ {
+ "package": "swift-nio-http2",
+ "repositoryURL": "https://github.com/apple/swift-nio-http2.git",
+ "state": {
+ "branch": null,
+ "revision": "326f7f9a8c8c8402e3691adac04911cac9f9d87f",
+ "version": "1.18.4"
+ }
+ },
+ {
+ "package": "swift-nio-ssl",
+ "repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
+ "state": {
+ "branch": null,
+ "revision": "5e68c1ded15619bb281b273fa8c2d8fd7f7b2b7d",
+ "version": "2.16.1"
+ }
+ },
+ {
+ "package": "swift-nio-transport-services",
+ "repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
+ "state": {
+ "branch": null,
+ "revision": "e7f5278a26442dc46783ba7e063643d524e414a0",
+ "version": "1.11.3"
+ }
+ },
+ {
+ "package": "vapor",
+ "repositoryURL": "https://github.com/vapor/vapor.git",
+ "state": {
+ "branch": null,
+ "revision": "27119271502bf266be293be5325f0fb72435e8fd",
+ "version": "4.49.2"
+ }
+ },
+ {
+ "package": "websocket-kit",
+ "repositoryURL": "https://github.com/vapor/websocket-kit.git",
+ "state": {
+ "branch": null,
+ "revision": "b1c4df8f6c848c2e977726903bbe6578eed723ad",
+ "version": "2.2.0"
+ }
+ }
+ ]
+ },
+ "version": 1
+}
diff --git a/Package.swift b/Package.swift
new file mode 100644
index 0000000..89cdebe
--- /dev/null
+++ b/Package.swift
@@ -0,0 +1,36 @@
+// swift-tools-version:5.2
+import PackageDescription
+
+let package = Package(
+ name: "connexion_services",
+ platforms: [
+ .macOS(.v10_15)
+ ],
+ dependencies: [
+ // 💧 A server-side Swift web framework.
+ .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
+ .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),
+ .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),
+ ],
+ targets: [
+ .target(
+ name: "App",
+ dependencies: [
+ .product(name: "Fluent", package: "fluent"),
+ .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
+ .product(name: "Vapor", package: "vapor")
+ ],
+ swiftSettings: [
+ // Enable better optimizations when building in Release configuration. Despite the use of
+ // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
+ // builds. See for details.
+ .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
+ ]
+ ),
+ .target(name: "Run", dependencies: [.target(name: "App")]),
+ .testTarget(name: "AppTests", dependencies: [
+ .target(name: "App"),
+ .product(name: "XCTVapor", package: "vapor"),
+ ])
+ ]
+)
diff --git a/Resources/Views/index.leaf b/Resources/Views/index.leaf
new file mode 100644
index 0000000..10cb4f7
--- /dev/null
+++ b/Resources/Views/index.leaf
@@ -0,0 +1,12 @@
+
+
+
+
+
+ #(title)
+
+
+
+ #(title)
+
+
\ No newline at end of file
diff --git a/Sources/.DS_Store b/Sources/.DS_Store
new file mode 100644
index 0000000..886d6c6
Binary files /dev/null and b/Sources/.DS_Store differ
diff --git a/Sources/App/.DS_Store b/Sources/App/.DS_Store
new file mode 100644
index 0000000..e6d7849
Binary files /dev/null and b/Sources/App/.DS_Store differ
diff --git a/Sources/App/Controllers/.gitkeep b/Sources/App/Controllers/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/Sources/App/Controllers/c/CPCLTemplateCommandCtrl.swift b/Sources/App/Controllers/c/CPCLTemplateCommandCtrl.swift
new file mode 100644
index 0000000..d4d003a
--- /dev/null
+++ b/Sources/App/Controllers/c/CPCLTemplateCommandCtrl.swift
@@ -0,0 +1,155 @@
+//
+// CPCLTemplateCommandCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CPCLTemplateCommandCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCPCLTemplateCommand.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCPCLTemplateCommand.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCPCLTemplateCommand.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CPCLTemplateCommandCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCPCLTemplateCommand.query(on: req.db).with(\.$cpcltemplate)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCPCLTemplateCommand) -> mdlCPCLTemplateCommand.Output {
+ return mdlCPCLTemplateCommand.Output(
+ id: output.id!,
+ cmd: output.cmd,
+ sortorder: output.sortorder,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ cpcltemplate: output.$cpcltemplate.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCPCLTemplateCommand.Input){
+ output.cmd = input.cmd;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$cpcltemplate.id = input.cpcltemplate.id!
+ }
+
+ func createUnit(_ input: mdlCPCLTemplateCommand.Input) -> mdlCPCLTemplateCommand {
+ return mdlCPCLTemplateCommand(
+ id: input.id ?? nil
+ , cmd: input.cmd
+ , sortorder: input.sortorder
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , cpcltemplate: input.cpcltemplate
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCPCLTemplateCommand.Output(
+ id: output.id!
+ , cmd: output.cmd
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , cpcltemplate: output.cpcltemplate
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCPCLTemplateCommand, _ req: Request, _ input: mdlCPCLTemplateCommand.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCPCLTemplateCommand.Output(
+ id: output.id!
+ , cmd: output.cmd
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , cpcltemplate: input.cpcltemplate
+ )
+
+ }
+ }
+
+}
+extension CPCLTemplateCommandCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("cpclcommands")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CPCLTemplateCtrl.swift b/Sources/App/Controllers/c/CPCLTemplateCtrl.swift
new file mode 100644
index 0000000..1bb4343
--- /dev/null
+++ b/Sources/App/Controllers/c/CPCLTemplateCtrl.swift
@@ -0,0 +1,157 @@
+//
+// CPCLTemplateCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CPCLTemplateCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCPCLTemplate.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCPCLTemplate.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCPCLTemplate.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CPCLTemplateCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCPCLTemplate.query(on: req.db)
+ .with(\.$oilsamplelabel)
+ .with(\.$commands)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCPCLTemplate) -> mdlCPCLTemplate.Output {
+ return mdlCPCLTemplate.Output(
+ id: output.id!,
+ name: output.name,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ oilsamplelabel: output.$oilsamplelabel.value!,
+ commands: output.$commands.value
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCPCLTemplate.Input){
+ output.name = input.name;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$oilsamplelabel.id = input.oilsamplelabel.id!;
+ output.$commands.value = input.commands
+ }
+
+ func createUnit(_ input: mdlCPCLTemplate.Input) -> mdlCPCLTemplate {
+ return mdlCPCLTemplate(
+ id: input.id ?? nil
+ , name: input.name
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , oilsamplelabel: input.oilsamplelabel
+ , commands: input.commands
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCPCLTemplate.Output(
+ id: output.id!
+ , name: output.name
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , oilsamplelabel: output.oilsamplelabel
+ , commands: output.commands
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCPCLTemplate, _ req: Request, _ input: mdlCPCLTemplate.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCPCLTemplate.Output(
+ id: output.id!
+ , name: output.name
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , oilsamplelabel: input.oilsamplelabel
+ , commands: input.commands
+ )
+
+ }
+ }
+
+}
+extension CPCLTemplateCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("cpcltemplates")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CategoryCtrl.swift b/Sources/App/Controllers/c/CategoryCtrl.swift
new file mode 100644
index 0000000..fd7324b
--- /dev/null
+++ b/Sources/App/Controllers/c/CategoryCtrl.swift
@@ -0,0 +1,155 @@
+//
+// CategoryCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/9/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CategoryCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCategory.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCategory.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCategory.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CategoryCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCategory.query(on: req.db).with(\.$items)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCategory) -> mdlCategory.Output {
+ return mdlCategory.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ items: output.$items.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCategory.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$items.value = input.items
+ }
+
+ func createUnit(_ input: mdlCategory.Input) -> mdlCategory {
+ return mdlCategory(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , items: input.items
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCategory.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , items: output.items
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCategory, _ req: Request, _ input: mdlCategory.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCategory.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , items: input.items
+ )
+
+ }
+ }
+
+}
+extension CategoryCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("categories")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/ComparisonTypeCtrl.swift b/Sources/App/Controllers/c/ComparisonTypeCtrl.swift
new file mode 100644
index 0000000..f096359
--- /dev/null
+++ b/Sources/App/Controllers/c/ComparisonTypeCtrl.swift
@@ -0,0 +1,154 @@
+//
+// ComparisonTypeCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class ComparisonTypeCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlComparisonType.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlComparisonType.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlComparisonType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension ComparisonTypeCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlComparisonType.query(on: req.db).with(\.$specitems).with(\.$inspectioncategoryitemspecitems)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlComparisonType) -> mdlComparisonType.Output {
+ return mdlComparisonType.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ specitems: output.$specitems.value!,
+ inspectioncategoryitemspecitems: output.$inspectioncategoryitemspecitems.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlComparisonType.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$specitems.value = input.specitems;
+ output.$inspectioncategoryitemspecitems.value = input.inspectioncategoryitemspecitems
+ }
+
+ func createUnit(_ input: mdlComparisonType.Input) -> mdlComparisonType {
+ return mdlComparisonType(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , specitems: input.specitems
+ , inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlComparisonType.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , specitems: output.specitems
+ , inspectioncategoryitemspecitems: output.inspectioncategoryitemspecitems
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlComparisonType, _ req: Request, _ input: mdlComparisonType.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlComparisonType.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , specitems: input.specitems
+ , inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems
+ )
+ }
+ }
+
+}
+extension ComparisonTypeCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("comparisontypes")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CompartmentCtrl.swift b/Sources/App/Controllers/c/CompartmentCtrl.swift
new file mode 100644
index 0000000..ca31e27
--- /dev/null
+++ b/Sources/App/Controllers/c/CompartmentCtrl.swift
@@ -0,0 +1,160 @@
+//
+// CompartmentCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CompartmentCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartment.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartment.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCompartment.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CompartmentCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCompartment.query(on: req.db)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCompartment) -> mdlCompartment.Output {
+ return mdlCompartment.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ code: output.code,
+ sortorder: output.sortorder,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCompartment.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.code = input.code;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ }
+
+ func createUnit(_ input: mdlCompartment.Input) -> mdlCompartment {
+ return mdlCompartment(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , code: input.code
+ , sortorder: input.sortorder
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCompartment.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , code: output.code
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCompartment, _ req: Request, _ input: mdlCompartment.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCompartment.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , code: output.code
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+
+ }
+ }
+
+}
+extension CompartmentCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("compartments")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CompartmentGroupCtrl.swift b/Sources/App/Controllers/c/CompartmentGroupCtrl.swift
new file mode 100644
index 0000000..2b2865a
--- /dev/null
+++ b/Sources/App/Controllers/c/CompartmentGroupCtrl.swift
@@ -0,0 +1,155 @@
+//
+// CompartmentGroupCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CompartmentGroupCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartmentGroup.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartmentGroup.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCompartmentGroup.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CompartmentGroupCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCompartmentGroup.query(on: req.db)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCompartmentGroup) -> mdlCompartmentGroup.Output {
+ return mdlCompartmentGroup.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ sortorder: output.sortorder,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCompartmentGroup.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ }
+
+ func createUnit(_ input: mdlCompartmentGroup.Input) -> mdlCompartmentGroup {
+ return mdlCompartmentGroup(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , sortorder: input.sortorder
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCompartmentGroup.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCompartmentGroup, _ req: Request, _ input: mdlCompartmentGroup.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCompartmentGroup.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+
+ }
+ }
+
+}
+extension CompartmentGroupCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("compartmentgroups")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CompartmentLocationCtrl.swift b/Sources/App/Controllers/c/CompartmentLocationCtrl.swift
new file mode 100644
index 0000000..27b8417
--- /dev/null
+++ b/Sources/App/Controllers/c/CompartmentLocationCtrl.swift
@@ -0,0 +1,161 @@
+//
+// CompartmentLocationCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CompartmentLocationCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartmentLocation.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCompartmentLocation.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCompartmentLocation.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CompartmentLocationCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCompartmentLocation.query(on: req.db)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCompartmentLocation) -> mdlCompartmentLocation.Output {
+ return mdlCompartmentLocation.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ code: output.code,
+ sortorder: output.sortorder,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCompartmentLocation.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.code = input.code;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ }
+
+ func createUnit(_ input: mdlCompartmentLocation.Input) -> mdlCompartmentLocation {
+ return mdlCompartmentLocation(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , code: input.code
+
+ , sortorder: input.sortorder
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCompartmentLocation.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , code: output.code
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCompartmentLocation, _ req: Request, _ input: mdlCompartmentLocation.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCompartmentLocation.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , code: output.code
+ , sortorder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+
+ }
+ }
+
+}
+extension CompartmentLocationCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("compartmentlocations")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/ContactCtrl.swift b/Sources/App/Controllers/c/ContactCtrl.swift
new file mode 100644
index 0000000..aa6bcb5
--- /dev/null
+++ b/Sources/App/Controllers/c/ContactCtrl.swift
@@ -0,0 +1,170 @@
+//
+// ContractCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/5/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class ContactCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlContact.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlContact.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlContact.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension ContactCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlContact.query(on: req.db).with(\.$customer).with(\.$location).with(\.$contacttypes).with(\.$files)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlContact) -> mdlContact.Output {
+ return mdlContact.Output(
+ id: output.id!,
+ firstname: output.firstname,
+ lastname: output.lastname,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ customer: output.$customer.value!,
+ location: output.$location.value!,
+ contacttypes: output.$contacttypes.value!,
+ files: output.$files.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlContact.Input){
+ output.firstname = input.firstname;
+ output.lastname = input.lastname;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$customer.id = input.customer.id!;
+ output.$location.id = input.location.id!;
+ output.$contacttypes.value = input.contacttypes;
+ output.$files.value = input.files
+ }
+
+ func createUnit(_ input: mdlContact.Input) -> mdlContact {
+ return mdlContact(
+ id: input.id ?? nil
+ , firstname: input.firstname
+ , lastname: input.lastname
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , customer: input.customer
+ , location: input.location
+ , contacttypes: input.contacttypes
+ , files: input.files
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlContact.Output(
+ id: output.id!
+ , firstname: output.firstname
+ , lastname: output.lastname
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , customer: output.customer
+ , location: output.location
+ , contacttypes: output.contacttypes
+ , files: output.files
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlContact, _ req: Request, _ input: mdlContact.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlContact.Output(
+ id: output.id!
+ , firstname: output.firstname
+ , lastname: output.lastname
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , customer: input.customer
+ , location: input.location
+ , contacttypes: input.contacttypes
+ , files: input.files
+ )
+
+ }
+ }
+
+}
+extension ContactCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("contacts")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/ContactMethodCtrl.swift b/Sources/App/Controllers/c/ContactMethodCtrl.swift
new file mode 100644
index 0000000..7be246f
--- /dev/null
+++ b/Sources/App/Controllers/c/ContactMethodCtrl.swift
@@ -0,0 +1,174 @@
+//
+// ContactMethodCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/5/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class ContactMethodCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlContactMethod.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlContactMethod.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlContactMethod.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension ContactMethodCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlContactMethod.query(on: req.db).with(\.$contact)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlContactMethod) -> mdlContactMethod.Output {
+ return mdlContactMethod.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ line1: output.line1,
+ line2: output.line2,
+ line3: output.line3,
+ line4: output.line4,
+ primary: output.primary,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ contact: output.$contact.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlContactMethod.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.line1 = input.line1;
+ output.line2 = input.line2;
+ output.line3 = input.line3;
+ output.line4 = input.line4;
+ output.primary = input.primary;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$contact.id = input.contact.id!
+ }
+
+ func createUnit(_ input: mdlContactMethod.Input) -> mdlContactMethod {
+ return mdlContactMethod(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , line1: input.line1
+ , line2: input.line2
+ , line3: input.line3
+ , line4: input.line4
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , contact: input.contact
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlContactMethod.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , line1: output.line1
+ , line2: output.line2
+ , line3: output.line3
+ , line4: output.line4
+ , primary: output.primary
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , contact: output.contact
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlContactMethod, _ req: Request, _ input: mdlContactMethod.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlContactMethod.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , line1: output.line1
+ , line2: output.line2
+ , line3: output.line3
+ , line4: output.line4
+ , primary: output.primary
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , contact: input.contact
+ )
+
+ }
+ }
+
+}
+extension ContactMethodCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("contactmethods")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/c/CustomerCtrl.swift b/Sources/App/Controllers/c/CustomerCtrl.swift
new file mode 100644
index 0000000..cf9931e
--- /dev/null
+++ b/Sources/App/Controllers/c/CustomerCtrl.swift
@@ -0,0 +1,214 @@
+//
+// CustomerCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class CustomerCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCustomer.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlCustomer.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlCustomer.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension CustomerCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlCustomer.query(on: req.db)
+ .with(\.$contacts)
+ .with(\.$templates)
+ .with(\.$workorders)
+ .with(\.$machines)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlCustomer) -> mdlCustomer.Output {
+ return mdlCustomer.Output(
+ id: output.id!,
+ number: output.number,
+ name: output.name,
+ address: output.address,
+ address2: output.address2,
+ city: output.city,
+ state: output.state,
+ zip: output.zip,
+ phone1: output.phone1,
+ phone2: output.phone2,
+ fax: output.fax,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ contacts: output.contacts,
+ machines: output.machines,
+ templates: output.templates,
+ workorders: output.workorders
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlCustomer.Input){
+ output.number = input.number;
+ output.name = input.name;
+ output.address = input.address;
+ output.address2 = input.address2;
+ output.city = input.city;
+ output.state = input.state;
+ output.zip = input.zip;
+ output.phone1 = input.phone1;
+ output.phone2 = input.phone2;
+ output.fax = input.fax;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$contacts.value = input.contacts;
+ output.$machines.value = input.machines;
+ output.$templates.value = input.templates;
+ output.$workorders.value = input.workorders
+ }
+
+ func createUnit(_ input: mdlCustomer.Input) -> mdlCustomer {
+ return mdlCustomer(
+ id: input.id ?? nil
+ , number: input.number
+ , name: input.name
+ , address: input.address
+ , address2: input.address2
+ , city: input.city
+ , state: input.state
+ , zip: input.zip
+ , phone1: input.phone1
+ , phone2: input.phone2
+ , fax: input.fax
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , contacts: input.contacts
+ , machines: input.machines
+ , templates: input.templates
+ , workorders: input.workorders
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlCustomer.Output(
+ id: output.id!
+ , number: output.number
+ , name: output.name
+ , address: output.address
+ , address2: output.address2
+ , city: output.city
+ , state: output.state
+ , zip: output.zip
+ , phone1: output.phone1
+ , phone2: output.phone2
+ , fax: output.fax
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , contacts: output.contacts
+ , machines: output.machines
+ , templates: output.templates
+ , workorders: output.workorders
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlCustomer, _ req: Request, _ input: mdlCustomer.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlCustomer.Output(
+ id: output.id!
+ , number: output.number
+ , name: output.name
+ , address: output.address
+ , address2: output.address2
+ , city: output.city
+ , state: output.state
+ , zip: output.zip
+ , phone1: output.phone1
+ , phone2: output.phone2
+ , fax: output.fax
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , contacts: input.contacts
+ , machines: input.machines
+ , templates: input.templates
+ , workorders: input.workorders
+ )
+
+ }
+ }
+
+}
+extension CustomerCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("customers")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/d/DataTypeCtrl.swift b/Sources/App/Controllers/d/DataTypeCtrl.swift
new file mode 100644
index 0000000..c25f81c
--- /dev/null
+++ b/Sources/App/Controllers/d/DataTypeCtrl.swift
@@ -0,0 +1,130 @@
+//
+// DataTypeCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/2/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class DataTypeCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlDataType.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlDataType.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlDataType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+
+extension DataTypeCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlDataType.query(on: req.db).with(\.$units)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlDataType) -> mdlDataType.Output {
+ return mdlDataType.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , units: output.$units.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlDataType.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.$units.value = input.units
+ }
+
+ func createUnit(_ input: mdlDataType.Input) -> mdlDataType {
+ return mdlDataType(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , units: input.units
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlDataType.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , units: output.units
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlDataType, _ req: Request, _ input: mdlDataType.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlDataType.Output(
+ id: output.id!
+ , name: input.name
+ , description: input.description
+ , units: input.units
+ )
+ }
+ }
+
+ }
+ extension DataTypeCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("datatypes")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+ }
diff --git a/Sources/App/Controllers/d/DivisionCtrl.swift b/Sources/App/Controllers/d/DivisionCtrl.swift
new file mode 100644
index 0000000..a64fe13
--- /dev/null
+++ b/Sources/App/Controllers/d/DivisionCtrl.swift
@@ -0,0 +1,157 @@
+//
+// Division.swift
+//
+//
+// Created by Michiel Carman on 11/2/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class DivisionCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlDivision.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlDivision.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlDivision.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+
+extension DivisionCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlDivision.query(on: req.db).with(\.$users)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlDivision) -> mdlDivision.Output {
+ return mdlDivision.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ users: output.$users.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlDivision.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$users.value = input.users
+ }
+
+ func createUnit(_ input: mdlDivision.Input) -> mdlDivision {
+ return mdlDivision(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , users: input.users
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlDivision.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , users: output.users
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlDivision, _ req: Request, _ input: mdlDivision.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlDivision.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , users: output.users
+ )
+
+ }
+ }
+
+}
+ extension DivisionCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("divisions")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+ }
+
diff --git a/Sources/App/Controllers/f/FileCtrl.swift b/Sources/App/Controllers/f/FileCtrl.swift
new file mode 100644
index 0000000..1cc2f7a
--- /dev/null
+++ b/Sources/App/Controllers/f/FileCtrl.swift
@@ -0,0 +1,181 @@
+//
+// FileCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/12/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+import AppKit
+
+final class FileCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFile.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFile.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlFile.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension FileCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlFile.query(on: req.db)
+ .with(\.$workorder)
+ .with(\.$inspectioncategoryitem)
+ .with(\.$contact)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+
+ //create Output
+ func createRead(_ output: mdlFile) -> mdlFile.Output {
+ return mdlFile.Output(
+ id: output.id!
+ , name: output.name
+ , filepath: output.filepath
+ , filedata: String()
+
+ , filetype: output.filetype
+ , fileextension: output.fileextension
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , workorder: output.$workorder.value!
+ , inspectioncategoryitem: output.$inspectioncategoryitem.value!
+ , contact: output.$contact.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlFile.Input){
+ output.name = input.name;
+ output.filepath = input.filepath;
+ output.filetype = input.filetype;
+
+ output.fileextension = input.fileextension;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$workorder.id = input.workorder.id!;
+ output.$inspectioncategoryitem.id = input.inspectioncategoryitem.id!;
+ output.$contact.id = input.contact.id!;
+ }
+
+ func createUnit(_ input: mdlFile.Input) -> mdlFile {
+ return mdlFile(
+ id: input.id ?? nil
+ , name: input.name
+ , filepath: input.filepath
+ , filedata: input.filedata
+ , filetype: input.filetype
+ , fileextension: input.fileextension
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , workorder: input.workorder
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , contact: input.contact
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlFile.Output(
+ id: output.id!
+ , name: output.name
+ , filepath: output.filepath
+ , filedata: String()
+ , filetype: output.filetype
+ , fileextension: output.fileextension
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , workorder: output.workorder
+ , inspectioncategoryitem: output.inspectioncategoryitem
+ , contact: output.contact
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlFile, _ req: Request, _ input: mdlFile.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlFile.Output(
+ id: output.id!
+ , name: output.name
+ , filepath: output.filepath
+ , filedata: input.filedata
+ , filetype: output.filetype
+ , fileextension: output.fileextension
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , workorder: input.workorder
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , contact: input.contact
+ )
+
+ }
+ }
+
+}
+extension FileCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("files")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/f/FluidCtrl.swift b/Sources/App/Controllers/f/FluidCtrl.swift
new file mode 100644
index 0000000..1e14f76
--- /dev/null
+++ b/Sources/App/Controllers/f/FluidCtrl.swift
@@ -0,0 +1,160 @@
+//
+// FluidCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/9/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class FluidCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFluid.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFluid.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlFluid.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension FluidCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlFluid.query(on: req.db).with(\.$viscosities)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlFluid) -> mdlFluid.Output {
+ return mdlFluid.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ sortoder: output.sortorder,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ viscosities: output.$viscosities.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlFluid.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.sortorder = input.sortoder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$viscosities.value = input.viscosities
+ }
+
+ func createUnit(_ input: mdlFluid.Input) -> mdlFluid {
+ return mdlFluid(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , sortorder: input.sortoder
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , viscosities: input.viscosities
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlFluid.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortoder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , viscosities: output.viscosities
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlFluid, _ req: Request, _ input: mdlFluid.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlFluid.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortoder: output.sortorder
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , viscosities: input.viscosities
+ )
+
+ }
+ }
+
+}
+extension FluidCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("fluids")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/f/FuelLevelCtrl.swift b/Sources/App/Controllers/f/FuelLevelCtrl.swift
new file mode 100644
index 0000000..c3e41b7
--- /dev/null
+++ b/Sources/App/Controllers/f/FuelLevelCtrl.swift
@@ -0,0 +1,155 @@
+//
+// FuelLevelCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class FuelLevelCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFuelLevel.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlFuelLevel.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlFuelLevel.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension FuelLevelCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlFuelLevel.query(on: req.db)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlFuelLevel) -> mdlFuelLevel.Output {
+ return mdlFuelLevel.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ isactive: output.isactive,
+ sortorder: output.sortorder,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlFuelLevel.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ }
+
+ func createUnit(_ input: mdlFuelLevel.Input) -> mdlFuelLevel {
+ return mdlFuelLevel(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , isactive: input.isactive
+ , sortorder: input.sortorder
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlFuelLevel.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlFuelLevel, _ req: Request, _ input: mdlFuelLevel.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlFuelLevel.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ )
+
+ }
+ }
+
+}
+extension FuelLevelCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("fuellevels")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/g/GateCtrl.swift b/Sources/App/Controllers/g/GateCtrl.swift
new file mode 100644
index 0000000..2b031b0
--- /dev/null
+++ b/Sources/App/Controllers/g/GateCtrl.swift
@@ -0,0 +1,104 @@
+//
+// File.swift
+//
+//
+// Created by Michiel Carman on 11/2/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class GateCtrl{
+ //Create Division
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlGate.Input.self)
+ let output = buildObj(input)
+ return output.save(on: req.db).map{
+ self.buildObj(output)
+ }
+ }
+ //Update Division
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlGate.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).flatMap{output in self.buildObj(output, input)
+ return self.save(output, req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.buildObj($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.buildObj($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlGate.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+
+extension GateCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlGate.query(on: req.db).with(\.$location)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Input
+ func buildObj(_ input: mdlGate.Input) -> mdlGate {
+ return mdlGate(name: input.name, description: input.description, sortorder: input.sortorder, isactive: input.isactive, createuserid: input.createuserid, createdate: input.createdate, updateuserid: input.updateuserid, updatedate: input.updatedate, location: input.location)
+ }
+ //create Output
+ func buildObj(_ output: mdlGate) -> mdlGate.Output {
+ return mdlGate.Output(id: output.id!, name: output.name, description: output.description, sortorder: output.sortorder, isactive: output.isactive, createdate: output.createdate, createuserid: output.createuserid, updatedate: output.updatedate, updateuserid: output.updateuserid, location: output.location)
+ }
+
+ func buildObj(_ output: Optional.WrappedType, _ input: mdlGate.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.sortorder = input.sortorder;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.createuserid = input.createuserid;
+ output.updatedate = input.updatedate;
+ output.updateuserid = input.updateuserid;
+ output.location = input.location;
+ }
+
+ func save(_ output: mdlGate, _ req: Request) -> EventLoopFuture{
+ return output.save(on: req.db).map{self.buildObj(output)}
+ }
+
+}
+extension GateCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("gates")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/IncompleteReasonCtrl.swift b/Sources/App/Controllers/i/IncompleteReasonCtrl.swift
new file mode 100644
index 0000000..d40f627
--- /dev/null
+++ b/Sources/App/Controllers/i/IncompleteReasonCtrl.swift
@@ -0,0 +1,155 @@
+//
+// IncompleteReasonCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/5/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class IncompleteReasonCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlIncompleteReason.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlIncompleteReason.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlIncompleteReason.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension IncompleteReasonCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlIncompleteReason.query(on: req.db).with(\.$workorders)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlIncompleteReason) -> mdlIncompleteReason.Output {
+ return mdlIncompleteReason.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ workorders: output.$workorders.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlIncompleteReason.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$workorders.value = input.workorders
+ }
+
+ func createUnit(_ input: mdlIncompleteReason.Input) -> mdlIncompleteReason {
+ return mdlIncompleteReason(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , workorders: input.workorders
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlIncompleteReason.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , workorders: output.workorders
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlIncompleteReason, _ req: Request, _ input: mdlIncompleteReason.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlIncompleteReason.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , workorders: input.workorders
+ )
+
+ }
+ }
+
+}
+extension IncompleteReasonCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("incompletereaseons")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InputTypeCtrl.swift b/Sources/App/Controllers/i/InputTypeCtrl.swift
new file mode 100644
index 0000000..2c9d248
--- /dev/null
+++ b/Sources/App/Controllers/i/InputTypeCtrl.swift
@@ -0,0 +1,130 @@
+//
+// InputTypeCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/4/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InputTypeCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInputType.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInputType.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInputType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InputTypeCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInputType.query(on: req.db).with(\.$items).with(\.$inspectioncategoryitems)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInputType) -> mdlInputType.Output {
+ return mdlInputType.Output(
+ id: output.id!,
+ name: output.name,
+ items: output.$items.value!,
+ inspectioncategoryitems: output.$inspectioncategoryitems.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInputType.Input){
+ output.name = input.name;
+ output.$items.value = input.items!;
+ output.$inspectioncategoryitems.value = input.inspectioncategoryitems!
+ }
+
+ func createUnit(_ input: mdlInputType.Input) -> mdlInputType {
+ return mdlInputType(
+ id: input.id ?? nil
+ , name: input.name
+ , items: input.items
+ , inspectioncategoryitems: input.inspectioncategoryitems
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInputType.Output(
+ id: output.id!
+ , name: output.name
+ , items: output.items
+ , inspectioncategoryitems: output.inspectioncategoryitems
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInputType, _ req: Request, _ input: mdlInputType.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInputType.Output(
+ id: output.id!
+ , name: output.name
+ , items: input.items
+ , inspectioncategoryitems: input.inspectioncategoryitems
+ )
+
+ }
+ }
+
+}
+extension InputTypeCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inputtypes")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryCtrl.swift
new file mode 100644
index 0000000..70bab28
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryCtrl.swift
@@ -0,0 +1,170 @@
+//
+// InspectionCategoryCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/10/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategory.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategory.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategory.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategory.query(on: req.db).with(\.$inspection).with(\.$inspectioncategoryitems)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategory) -> mdlInspectionCategory.Output {
+ return mdlInspectionCategory.Output(
+ id: output.id!,
+ summary: output.summary,
+ sortorder: output.sortorder,
+ categoryname: output.categoryname,
+ categorydesription: output.categorydescription,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ inspection: output.$inspection.value!,
+ inspectioncategoryitems: output.$inspectioncategoryitems.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategory.Input){
+ output.summary = input.summary;
+ output.sortorder = input.sortorder;
+ output.categoryname = input.categoryname;
+ output.categorydescription = input.categorydesription;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$inspection.id = input.inspection.id!;
+ output.$inspectioncategoryitems.value = input.inspectioncategoryitems!
+ }
+
+ func createUnit(_ input: mdlInspectionCategory.Input) -> mdlInspectionCategory {
+ return mdlInspectionCategory(
+ id: input.id ?? nil
+ , summary: input.summary
+ , sortorder: input.sortorder
+ , categoryname: input.categoryname
+ , categorydescription: input.categorydesription
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , inspection: input.inspection
+ , inspectioncategoyitems: input.inspectioncategoryitems
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategory.Output(
+ id: output.id!
+ , summary: output.summary
+ , sortorder: output.sortorder
+ , categoryname: output.categoryname
+ , categorydesription: output.categorydescription
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspection: output.inspection
+ , inspectioncategoryitems: output.inspectioncategoryitems
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategory, _ req: Request, _ input: mdlInspectionCategory.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategory.Output(
+ id: output.id!
+ , summary: output.summary
+ , sortorder: output.sortorder
+ , categoryname: output.categoryname
+ , categorydesription: output.categorydescription
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspection: input.inspection
+ , inspectioncategoryitems: input.inspectioncategoryitems
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategories")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemCtrl.swift
new file mode 100644
index 0000000..c5e140c
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemCtrl.swift
@@ -0,0 +1,217 @@
+//
+// InspectionCategoryItemCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/10/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+import AppKit
+
+final class InspectionCategoryItemCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItem.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItem.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItem.query(on: req.db)
+ .with(\.$item)
+ .with(\.$inspectioncategory)
+ .with(\.$userdefinedcode)
+ .with(\.$inputtype)
+ .with(\.$currentitem)
+ .with(\.$parent)
+ .with(\.$inspectioncategoryitems)
+ .with(\.$inspectioncategoryitemresponsetypes)
+ .with(\.$inspectioncategoryitemspecs)
+ .with(\.$notes)
+ .with(\.$files)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItem) -> mdlInspectionCategoryItem.Output {
+ return mdlInspectionCategoryItem.Output(
+ id: output.id!,
+ name: output.name,
+ description: output.description,
+ sortorder: output.sortorder,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ item: output.$item.value!,
+ inspectioncategory: output.$inspectioncategory.value!,
+ userdefinedcode: output.$userdefinedcode.value!,
+ inputtype: output.$inputtype.value!,
+ currentitem: output.$currentitem.value!,
+ parent: output.$parent.value!,
+ inspectioncategoryitems: output.$inspectioncategoryitems.value!,
+ inspectioncategoryitemresponsetypes: output.$inspectioncategoryitemresponsetypes.value!,
+ inspectioncategoryitemspecs: output.$inspectioncategoryitemspecs.value!,
+ notes: output.$notes.value!,
+ files: output.$files.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItem.Input){
+ output.name = input.name;
+ output.description = input.description;
+ output.sortorder = input.sortorder;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$item.id = input.item.id!;
+ output.$inspectioncategory.id = input.inspectioncategory.id!;
+ output.$userdefinedcode.id = input.userdefinedcode.id!;
+ output.$inputtype.id = input.inputtype.id!;
+ output.$currentitem.id = input.currentitem.id!;
+ output.$parent.id = input.parent.id!;
+ output.$inspectioncategoryitems.value = input.inspectioncategoryitems;
+ output.$inspectioncategoryitemresponsetypes.value = input.inspectioncategoryitemresponsetypes;
+ output.$inspectioncategoryitemspecs.value = input.inspectioncategoryitemspecs;
+ output.$notes.value = input.notes;
+ output.$files.value = input.files;
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItem.Input) -> mdlInspectionCategoryItem {
+ return mdlInspectionCategoryItem(
+ id: input.id ?? nil
+ , name: input.name
+ , description: input.description
+ , sortorder: input.sortorder
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , item: input.item
+ , inspectioncategory: input.inspectioncategory
+ , userdefinedcode: input.userdefinedcode
+ , inputtype: input.inputtype
+ , currentitem: input.currentitem
+ , parent: input.parent
+ , inspectioncategoryitems: input.inspectioncategoryitems
+ , inspectioncategoryitemresponsetypes: input.inspectioncategoryitemresponsetypes
+ , inspectioncategoryitemspecs: input.inspectioncategoryitemspecs
+ , notes: input.notes
+ , files: input.files
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItem.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , item: output.item
+ , inspectioncategory: output.inspectioncategory
+ , userdefinedcode: output.userdefinedcode
+ , inputtype: output.inputtype
+ , currentitem: output.currentitem
+ , parent: output.parent
+ , inspectioncategoryitems: output.inspectioncategoryitems
+ , inspectioncategoryitemresponsetypes: output.inspectioncategoryitemresponsetypes
+ , inspectioncategoryitemspecs: output.inspectioncategoryitemspecs
+ , notes: output.notes
+ , files: output.files
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItem, _ req: Request, _ input: mdlInspectionCategoryItem.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItem.Output(
+ id: output.id!
+ , name: output.name
+ , description: output.description
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , item: input.item
+ , inspectioncategory: input.inspectioncategory
+ , userdefinedcode: input.userdefinedcode
+ , inputtype: input.inputtype
+ , currentitem: input.currentitem
+ , parent: input.parent
+ , inspectioncategoryitems: input.inspectioncategoryitems
+ , inspectioncategoryitemresponsetypes: input.inspectioncategoryitemresponsetypes
+ , inspectioncategoryitemspecs: input.inspectioncategoryitemspecs
+ , notes: input.notes
+ , files: input.files
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategoryitems")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemResponseTypeCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemResponseTypeCtrl.swift
new file mode 100644
index 0000000..0484e3f
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemResponseTypeCtrl.swift
@@ -0,0 +1,160 @@
+//
+// InspectionCategoryItemResponseTypeCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/10/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryItemResponseTypeCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemResponseType.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemResponseType.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItemResponseType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemResponseTypeCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItemResponseType.query(on: req.db).with(\.$inspectioncategoryitem).with(\.$responsetype)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItemResponseType) -> mdlInspectionCategoryItemResponseType.Output {
+ return mdlInspectionCategoryItemResponseType.Output(
+ id: output.id!,
+ name: output.name,
+ sortorder: output.sortorder,
+ isselected: output.isselected,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ inspectioncategoryitem: output.$inspectioncategoryitem.value!,
+ responsetype: output.$responsetype.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItemResponseType.Input){
+ output.name = input.name;
+ output.sortorder = input.sortorder;
+ output.isselected = input.isselected;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$inspectioncategoryitem.id = input.inspectioncategoryitem.id!;
+ output.$responsetype.id = input.responsetype.id!
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItemResponseType.Input) -> mdlInspectionCategoryItemResponseType {
+ return mdlInspectionCategoryItemResponseType(
+ id: input.id ?? nil
+ , name: input.name
+ , sortorder: input.sortorder
+ , isselected: input.isselected
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , responsetype: input.responsetype
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItemResponseType.Output(
+ id: output.id!
+ , name: output.name
+ , sortorder: output.sortorder
+ , isselected: output.isselected
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitem: output.inspectioncategoryitem
+ , responsetype: output.responsetype
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItemResponseType, _ req: Request, _ input: mdlInspectionCategoryItemResponseType.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItemResponseType.Output(
+ id: output.id!
+ , name: output.name
+ , sortorder: output.sortorder
+ , isselected: output.isselected
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , responsetype: input.responsetype
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemResponseTypeCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategoryitemresponsetypes")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemSpecCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemSpecCtrl.swift
new file mode 100644
index 0000000..c0294a6
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemSpecCtrl.swift
@@ -0,0 +1,163 @@
+//
+// InspectionCategoryItemSpecCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryItemSpecCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpec.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpec.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItemSpec.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemSpecCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItemSpec.query(on: req.db)
+ .with(\.$inspectioncategoryitem)
+ .with(\.$spec)
+ .with(\.$inspectioncategoryitemspecitems)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItemSpec) -> mdlInspectionCategoryItemSpec.Output {
+ return mdlInspectionCategoryItemSpec.Output(
+ id: output.id!,
+ name: output.name,
+ numberoftests: output.numberoftests,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ inspectioncategoryitem: output.$inspectioncategoryitem.value!,
+ spec: output.$spec.value!,
+ inspectioncategoryitemspecitems: output.$inspectioncategoryitemspecitems.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItemSpec.Input){
+ output.name = input.name;
+ output.numberoftests = input.numberoftests;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$inspectioncategoryitem.id = input.inspectioncategoryitem.id!;
+ output.$spec.id = input.spec.id!;
+ output.$inspectioncategoryitemspecitems.value = input.inspectioncategoryitemspecitems
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItemSpec.Input) -> mdlInspectionCategoryItemSpec {
+ return mdlInspectionCategoryItemSpec(
+ id: input.id ?? nil
+ , name: input.name
+ , numberoftests: input.numberoftests
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , spec: input.spec
+ , inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItemSpec.Output(
+ id: output.id!
+ , name: output.name
+ , numberoftests: output.numberoftests
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitem: output.inspectioncategoryitem
+ , spec: output.spec
+ , inspectioncategoryitemspecitems: output.inspectioncategoryitemspecitems
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItemSpec, _ req: Request, _ input: mdlInspectionCategoryItemSpec.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItemSpec.Output(
+ id: output.id!
+ , name: output.name
+ , numberoftests: output.numberoftests
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitem: input.inspectioncategoryitem
+ , spec: input.spec
+ , inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemSpecCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategoryitemspecs")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemSpecItemCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemCtrl.swift
new file mode 100644
index 0000000..29e2a24
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemCtrl.swift
@@ -0,0 +1,190 @@
+//
+// InspectionCategoryItemSpecItemCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryItemSpecItemCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItem.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItem.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItemSpecItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemSpecItemCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItemSpecItem.query(on: req.db)
+ .with(\.$inspectioncategoryitemspec)
+ .with(\.$comparisontype)
+ .with(\.$unit)
+ .with(\.$inspectioncategoryitemspecitemtests)
+ .with(\.$inspectioncategoryitemspecitemvalues)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItemSpecItem) -> mdlInspectionCategoryItemSpecItem.Output {
+ return mdlInspectionCategoryItemSpecItem.Output(
+ id: output.id!,
+ name: output.name,
+ average: output.average,
+ qualifier: output.qualifier,
+ result: output.result,
+ sortorder: output.sortorder,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ inspectioncategoryitemspec: output.$inspectioncategoryitemspec.value!,
+ comparisontype: output.$comparisontype.value!,
+ unit: output.$unit.value!,
+ inspectioncategoryitemspecitemtests: output.$inspectioncategoryitemspecitemtests.value!,
+ inspectioncategoryitemspecitemvalues: output.$inspectioncategoryitemspecitemvalues.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItemSpecItem.Input){
+ output.name = input.name;
+ output.average = input.average;
+ output.qualifier = input.qualifier;
+ output.result = input.result;
+ output.sortorder = input.sortorder;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$inspectioncategoryitemspec.id = input.inspectioncategoryitemspec.id!;
+ output.$comparisontype.id = input.comparisontype.id!;
+ output.$unit.id = input.unit.id!;
+ output.$inspectioncategoryitemspecitemtests.value = input.inspectioncategoryitemspecitemtests;
+ output.$inspectioncategoryitemspecitemvalues.value = input.inspectioncategoryitemspecitemvalues
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItemSpecItem.Input) -> mdlInspectionCategoryItemSpecItem {
+ return mdlInspectionCategoryItemSpecItem(
+ id: input.id ?? nil
+ , name: input.name
+ , average: input.average
+ , qualifier: input.qualifier
+ , result: input.result
+ , sortorder: input.sortorder
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , inspectioncategoryitemspec: input.inspectioncategoryitemspec
+ , comparisontype: input.comparisontype
+ , unit: input.unit
+ , inspectioncategoryitemspecitemtests: input.inspectioncategoryitemspecitemtests
+ , inspectioncategoryitemspecitemvalues: input.inspectioncategoryitemspecitemvalues
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItemSpecItem.Output(
+ id: output.id!
+ , name: output.name
+ , average: output.average
+ , qualifier: output.qualifier
+ , result: output.result
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitemspec: output.inspectioncategoryitemspec
+ , comparisontype: output.comparisontype
+ , unit: output.unit
+ , inspectioncategoryitemspecitemtests: output.inspectioncategoryitemspecitemtests
+ , inspectioncategoryitemspecitemvalues: output.inspectioncategoryitemspecitemvalues
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItemSpecItem, _ req: Request, _ input: mdlInspectionCategoryItemSpecItem.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItemSpecItem.Output(
+ id: output.id!
+ , name: output.name
+ , average: output.average
+ , qualifier: output.qualifier
+ , result: output.result
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitemspec: input.inspectioncategoryitemspec
+ , comparisontype: input.comparisontype
+ , unit: input.unit
+ , inspectioncategoryitemspecitemtests: input.inspectioncategoryitemspecitemtests
+ , inspectioncategoryitemspecitemvalues: input.inspectioncategoryitemspecitemvalues
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemSpecItemCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategoryitemspecitems")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemSpecItemTestCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemTestCtrl.swift
new file mode 100644
index 0000000..0fd01c1
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemTestCtrl.swift
@@ -0,0 +1,156 @@
+//
+// InspectionCategoryItemSpecItemTestCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryItemSpecItemTestCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItemTest.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItemTest.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItemSpecItemTest.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemSpecItemTestCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItemSpecItemTest.query(on: req.db)
+ .with(\.$inspectioncategoryitemspecitem)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItemSpecItemTest) -> mdlInspectionCategoryItemSpecItemTest.Output {
+ return mdlInspectionCategoryItemSpecItemTest.Output(
+ id: output.id!,
+ number: output.number,
+ value: output.value,
+ isactive: output.isactive,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ inspectioncategoryitemspecitem: output.$inspectioncategoryitemspecitem.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItemSpecItemTest.Input){
+ output.number = input.number;
+ output.value = input.value;
+ output.isactive = input.isactive;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$inspectioncategoryitemspecitem.id = input.inspectioncategoryitemspecitem.id!
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItemSpecItemTest.Input) -> mdlInspectionCategoryItemSpecItemTest {
+ return mdlInspectionCategoryItemSpecItemTest(
+ id: input.id ?? nil
+ , number: input.number
+ , value: input.value
+ , isactive: input.isactive
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , inspectioncategoryitemspecitem: input.inspectioncategoryitemspecitem
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItemSpecItemTest.Output(
+ id: output.id!
+ , number: output.number
+ , value: output.value
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitemspecitem: output.inspectioncategoryitemspecitem
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItemSpecItemTest, _ req: Request, _ input: mdlInspectionCategoryItemSpecItemTest.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItemSpecItemTest.Output(
+ id: output.id!
+ , number: output.number
+ , value: output.value
+ , isactive: output.isactive
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , inspectioncategoryitemspecitem: input.inspectioncategoryitemspecitem
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemSpecItemTestCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inspectioncategoryitemspecitemtests")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCategoryItemSpecItemValueCtrl.swift b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemValueCtrl.swift
new file mode 100644
index 0000000..372653e
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCategoryItemSpecItemValueCtrl.swift
@@ -0,0 +1,157 @@
+//
+// InspectionCategoryItemSpecItemValueCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/11/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCategoryItemSpecItemValueCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItemValue.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspectionCategoryItemSpecItemValue.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspectionCategoryItemSpecItemValue.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCategoryItemSpecItemValueCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder {
+ let query = mdlInspectionCategoryItemSpecItemValue.query(on: req.db)
+ .with(\.$valuetype)
+ .with(\.$inspectioncategoryitemspecitem)
+ if let id = req.parameters.get("id", as: Int.self){
+ return query.filter(\.$id == id)
+ } else{
+ return query
+ }
+ }
+ //create Output
+ func createRead(_ output: mdlInspectionCategoryItemSpecItemValue) -> mdlInspectionCategoryItemSpecItemValue.Output {
+ return mdlInspectionCategoryItemSpecItemValue.Output(
+ id: output.id!,
+ value: output.value,
+ sortorder: output.sortorder,
+ createdate: output.createdate,
+ createuserid: output.createuserid,
+ updatedate: output.updatedate,
+ updateuserid: output.updateuserid,
+ valuetype: output.$valuetype.value!,
+ inspectioncategoryitemspecitem: output.$inspectioncategoryitemspecitem.value!
+ )
+ }
+
+ func mapOutput(_ output: Optional.WrappedType, _ input: mdlInspectionCategoryItemSpecItemValue.Input){
+ output.value = input.value;
+ output.sortorder = input.sortorder;
+ output.createdate = input.createdate;
+ output.updatedate = input.updatedate;
+ output.createuserid = input.createuserid;
+ output.updateuserid = input.updateuserid;
+ output.$valuetype.id = input.valuetype.id!;
+ output.$inspectioncategoryitemspecitem.id = input.inspectioncategoryitemspecitem.id!
+ }
+
+ func createUnit(_ input: mdlInspectionCategoryItemSpecItemValue.Input) -> mdlInspectionCategoryItemSpecItemValue {
+ return mdlInspectionCategoryItemSpecItemValue(
+ id: input.id ?? nil
+ , value: input.value
+ , sortorder: input.sortorder
+ , createuserid: input.createuserid ?? -1
+ , createdate: input.createdate
+ , updateuserid: input.updateuserid ?? -1
+ , updatedate: input.updatedate
+ , valuetype: input.valuetype
+ , inspectioncategoryitemspecitem: input.inspectioncategoryitemspecitem
+ )
+ }
+
+ //update function
+ func save(_ output: Optional.WrappedType, req: Request) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{mdlInspectionCategoryItemSpecItemValue.Output(
+ id: output.id!
+ , value: output.value
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , valuetype: output.valuetype
+ , inspectioncategoryitemspecitem: output.inspectioncategoryitemspecitem
+ )
+ }
+ }
+ //create function
+ func save(_ output: mdlInspectionCategoryItemSpecItemValue, _ req: Request, _ input: mdlInspectionCategoryItemSpecItemValue.Input) -> EventLoopFuture {
+ return output
+ .save(on: req.db)
+ .map{
+ mdlInspectionCategoryItemSpecItemValue.Output(
+ id: output.id!
+ , value: output.value
+ , sortorder: output.sortorder
+ , createdate: output.createdate
+ , createuserid: output.createuserid
+ , updatedate: output.updatedate
+ , updateuserid: output.updateuserid
+ , valuetype: input.valuetype
+ , inspectioncategoryitemspecitem: input.inspectioncategoryitemspecitem
+ )
+
+ }
+ }
+
+}
+extension InspectionCategoryItemSpecItemValueCtrl: RouteCollection{
+ func boot(routes: RoutesBuilder) throws{
+ let apigroup = routes.grouped("inpsectioncategoryitemspecitemvalues")
+ apigroup.get("", use: readAll)
+ apigroup.get(":id", use: read)
+ apigroup.post("", use: create)
+ apigroup.post(":id", use: update)
+ apigroup.delete(":id", use: delete)
+
+
+ }
+}
diff --git a/Sources/App/Controllers/i/InspectionCtrl.swift b/Sources/App/Controllers/i/InspectionCtrl.swift
new file mode 100644
index 0000000..2041d32
--- /dev/null
+++ b/Sources/App/Controllers/i/InspectionCtrl.swift
@@ -0,0 +1,185 @@
+//
+// InspectionCtrl.swift
+//
+//
+// Created by Michiel Carman on 11/10/21.
+//
+
+import Foundation
+import Vapor
+import Fluent
+import FluentPostgresDriver
+
+final class InspectionCtrl{
+ //Create Unit
+ func create(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspection.Input.self)
+ let output = self.createUnit(input)
+ return self.save(output, req, input)
+
+ }
+
+ //Update Unit
+ func update(req: Request) throws -> EventLoopFuture{
+ let input = try req.content.decode(mdlInspection.Input.self)
+ return try qbase(req: req).first().unwrap(or: Abort(.notFound)).flatMap{output in self.mapOutput(output, input)
+ return self.save(output, req: req)
+ }
+ }
+
+ //Get all Divisions
+ func readAll(req: Request) throws -> EventLoopFuture>{
+ return try qbase(req: req)
+ .paginate(for: req)
+ .map{
+ page in page.map{
+ self.createRead($0)
+ }
+ }
+ }
+ //Get 1 Division
+ func read(req: Request) throws -> EventLoopFuture{
+
+ return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)}
+
+ }
+ //Delete 1 Division
+ func delete(req: Request) throws -> EventLoopFuture{
+
+ guard let id = req.parameters.get("id", as: Int.self) else{
+ throw Abort(.badRequest)
+ }
+ return mdlInspection.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok}
+ }
+
+}
+extension InspectionCtrl{
+ //Query Settings
+ func qbase(req: Request) throws -> QueryBuilder