| @@ -0,0 +1,7 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <Workspace | |||
| version = "1.0"> | |||
| <FileRef | |||
| location = "self:"> | |||
| </FileRef> | |||
| </Workspace> | |||
| @@ -0,0 +1,14 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |||
| <plist version="1.0"> | |||
| <dict> | |||
| <key>SchemeUserState</key> | |||
| <dict> | |||
| <key>connexion_services.xcscheme_^#shared#^_</key> | |||
| <dict> | |||
| <key>orderHint</key> | |||
| <integer>0</integer> | |||
| </dict> | |||
| </dict> | |||
| </dict> | |||
| </plist> | |||
| @@ -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"] | |||
| @@ -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 | |||
| } | |||
| @@ -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 <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> 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"), | |||
| ]) | |||
| ] | |||
| ) | |||
| @@ -0,0 +1,12 @@ | |||
| <!doctype html> | |||
| <html lang="en"> | |||
| <head> | |||
| <meta charset="utf-8"> | |||
| <title>#(title)</title> | |||
| </head> | |||
| <body> | |||
| <h1>#(title)</h1> | |||
| </body> | |||
| </html> | |||
| @@ -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<mdlCPCLTemplateCommand.Output>{ | |||
| 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<mdlCPCLTemplateCommand.Output>{ | |||
| 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<Page<mdlCPCLTemplateCommand.Output>>{ | |||
| 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<mdlCPCLTemplateCommand.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCPCLTemplateCommand> { | |||
| 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<mdlCPCLTemplateCommand>.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<mdlCPCLTemplateCommand>.WrappedType, req: Request) -> EventLoopFuture<mdlCPCLTemplateCommand.Output> { | |||
| 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<mdlCPCLTemplateCommand.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCPCLTemplate.Output>{ | |||
| 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<mdlCPCLTemplate.Output>{ | |||
| 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<Page<mdlCPCLTemplate.Output>>{ | |||
| 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<mdlCPCLTemplate.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCPCLTemplate> { | |||
| 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<mdlCPCLTemplate>.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<mdlCPCLTemplate>.WrappedType, req: Request) -> EventLoopFuture<mdlCPCLTemplate.Output> { | |||
| 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<mdlCPCLTemplate.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCategory.Output>{ | |||
| 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<mdlCategory.Output>{ | |||
| 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<Page<mdlCategory.Output>>{ | |||
| 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<mdlCategory.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCategory> { | |||
| 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<mdlCategory>.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<mdlCategory>.WrappedType, req: Request) -> EventLoopFuture<mdlCategory.Output> { | |||
| 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<mdlCategory.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlComparisonType.Output>{ | |||
| 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<mdlComparisonType.Output>{ | |||
| 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<Page<mdlComparisonType.Output>>{ | |||
| 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<mdlComparisonType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlComparisonType> { | |||
| 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<mdlComparisonType>.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<mdlComparisonType>.WrappedType, req: Request) -> EventLoopFuture<mdlComparisonType.Output> { | |||
| 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<mdlComparisonType.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCompartment.Output>{ | |||
| 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<mdlCompartment.Output>{ | |||
| 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<Page<mdlCompartment.Output>>{ | |||
| 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<mdlCompartment.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCompartment> { | |||
| 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<mdlCompartment>.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<mdlCompartment>.WrappedType, req: Request) -> EventLoopFuture<mdlCompartment.Output> { | |||
| 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<mdlCompartment.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCompartmentGroup.Output>{ | |||
| 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<mdlCompartmentGroup.Output>{ | |||
| 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<Page<mdlCompartmentGroup.Output>>{ | |||
| 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<mdlCompartmentGroup.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCompartmentGroup> { | |||
| 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<mdlCompartmentGroup>.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<mdlCompartmentGroup>.WrappedType, req: Request) -> EventLoopFuture<mdlCompartmentGroup.Output> { | |||
| 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<mdlCompartmentGroup.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCompartmentLocation.Output>{ | |||
| 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<mdlCompartmentLocation.Output>{ | |||
| 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<Page<mdlCompartmentLocation.Output>>{ | |||
| 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<mdlCompartmentLocation.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCompartmentLocation> { | |||
| 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<mdlCompartmentLocation>.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<mdlCompartmentLocation>.WrappedType, req: Request) -> EventLoopFuture<mdlCompartmentLocation.Output> { | |||
| 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<mdlCompartmentLocation.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlContact.Output>{ | |||
| 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<mdlContact.Output>{ | |||
| 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<Page<mdlContact.Output>>{ | |||
| 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<mdlContact.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlContact> { | |||
| 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<mdlContact>.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<mdlContact>.WrappedType, req: Request) -> EventLoopFuture<mdlContact.Output> { | |||
| 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<mdlContact.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlContactMethod.Output>{ | |||
| 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<mdlContactMethod.Output>{ | |||
| 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<Page<mdlContactMethod.Output>>{ | |||
| 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<mdlContactMethod.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlContactMethod> { | |||
| 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<mdlContactMethod>.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<mdlContactMethod>.WrappedType, req: Request) -> EventLoopFuture<mdlContactMethod.Output> { | |||
| 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<mdlContactMethod.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlCustomer.Output>{ | |||
| 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<mdlCustomer.Output>{ | |||
| 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<Page<mdlCustomer.Output>>{ | |||
| 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<mdlCustomer.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlCustomer> { | |||
| 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<mdlCustomer>.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<mdlCustomer>.WrappedType, req: Request) -> EventLoopFuture<mdlCustomer.Output> { | |||
| 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<mdlCustomer.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlDataType.Output>{ | |||
| 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<mdlDataType.Output>{ | |||
| 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<Page<mdlDataType.Output>>{ | |||
| 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<mdlDataType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlDataType> { | |||
| 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<mdlDataType>.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<mdlDataType>.WrappedType, req: Request) -> EventLoopFuture<mdlDataType.Output> { | |||
| 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<mdlDataType.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlDivision.Output>{ | |||
| 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<mdlDivision.Output>{ | |||
| 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<Page<mdlDivision.Output>>{ | |||
| 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<mdlDivision.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlDivision> { | |||
| 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<mdlDivision>.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<mdlDivision>.WrappedType, req: Request) -> EventLoopFuture<mdlDivision.Output> { | |||
| 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<mdlDivision.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlFile.Output>{ | |||
| 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<mdlFile.Output>{ | |||
| 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<Page<mdlFile.Output>>{ | |||
| 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<mdlFile.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlFile> { | |||
| 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<mdlFile>.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<mdlFile>.WrappedType, req: Request) -> EventLoopFuture<mdlFile.Output> { | |||
| 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<mdlFile.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlFluid.Output>{ | |||
| 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<mdlFluid.Output>{ | |||
| 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<Page<mdlFluid.Output>>{ | |||
| 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<mdlFluid.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlFluid> { | |||
| 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<mdlFluid>.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<mdlFluid>.WrappedType, req: Request) -> EventLoopFuture<mdlFluid.Output> { | |||
| 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<mdlFluid.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlFuelLevel.Output>{ | |||
| 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<mdlFuelLevel.Output>{ | |||
| 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<Page<mdlFuelLevel.Output>>{ | |||
| 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<mdlFuelLevel.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlFuelLevel> { | |||
| 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<mdlFuelLevel>.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<mdlFuelLevel>.WrappedType, req: Request) -> EventLoopFuture<mdlFuelLevel.Output> { | |||
| 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<mdlFuelLevel.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlGate.Output>{ | |||
| 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<mdlGate.Output>{ | |||
| 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<Page<mdlGate.Output>>{ | |||
| 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<mdlGate.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.buildObj($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlGate> { | |||
| 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<mdlGate>.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<mdlGate.Output>{ | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlIncompleteReason.Output>{ | |||
| 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<mdlIncompleteReason.Output>{ | |||
| 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<Page<mdlIncompleteReason.Output>>{ | |||
| 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<mdlIncompleteReason.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlIncompleteReason> { | |||
| 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<mdlIncompleteReason>.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<mdlIncompleteReason>.WrappedType, req: Request) -> EventLoopFuture<mdlIncompleteReason.Output> { | |||
| 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<mdlIncompleteReason.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInputType.Output>{ | |||
| 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<mdlInputType.Output>{ | |||
| 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<Page<mdlInputType.Output>>{ | |||
| 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<mdlInputType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInputType> { | |||
| 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<mdlInputType>.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<mdlInputType>.WrappedType, req: Request) -> EventLoopFuture<mdlInputType.Output> { | |||
| 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<mdlInputType.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategory.Output>{ | |||
| 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<mdlInspectionCategory.Output>{ | |||
| 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<Page<mdlInspectionCategory.Output>>{ | |||
| 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<mdlInspectionCategory.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategory> { | |||
| 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<mdlInspectionCategory>.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<mdlInspectionCategory>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategory.Output> { | |||
| 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<mdlInspectionCategory.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItem.Output>{ | |||
| 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<mdlInspectionCategoryItem.Output>{ | |||
| 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<Page<mdlInspectionCategoryItem.Output>>{ | |||
| 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<mdlInspectionCategoryItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItem> { | |||
| 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<mdlInspectionCategoryItem>.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<mdlInspectionCategoryItem>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItem.Output> { | |||
| 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<mdlInspectionCategoryItem.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItemResponseType.Output>{ | |||
| 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<mdlInspectionCategoryItemResponseType.Output>{ | |||
| 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<Page<mdlInspectionCategoryItemResponseType.Output>>{ | |||
| 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<mdlInspectionCategoryItemResponseType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItemResponseType> { | |||
| 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<mdlInspectionCategoryItemResponseType>.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<mdlInspectionCategoryItemResponseType>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItemResponseType.Output> { | |||
| 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<mdlInspectionCategoryItemResponseType.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItemSpec.Output>{ | |||
| 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<mdlInspectionCategoryItemSpec.Output>{ | |||
| 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<Page<mdlInspectionCategoryItemSpec.Output>>{ | |||
| 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<mdlInspectionCategoryItemSpec.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItemSpec> { | |||
| 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<mdlInspectionCategoryItemSpec>.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<mdlInspectionCategoryItemSpec>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItemSpec.Output> { | |||
| 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<mdlInspectionCategoryItemSpec.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItemSpecItem.Output>{ | |||
| 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<mdlInspectionCategoryItemSpecItem.Output>{ | |||
| 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<Page<mdlInspectionCategoryItemSpecItem.Output>>{ | |||
| 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<mdlInspectionCategoryItemSpecItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItemSpecItem> { | |||
| 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<mdlInspectionCategoryItemSpecItem>.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<mdlInspectionCategoryItemSpecItem>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItemSpecItem.Output> { | |||
| 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<mdlInspectionCategoryItemSpecItem.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItemSpecItemTest.Output>{ | |||
| 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<mdlInspectionCategoryItemSpecItemTest.Output>{ | |||
| 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<Page<mdlInspectionCategoryItemSpecItemTest.Output>>{ | |||
| 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<mdlInspectionCategoryItemSpecItemTest.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItemSpecItemTest> { | |||
| 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<mdlInspectionCategoryItemSpecItemTest>.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<mdlInspectionCategoryItemSpecItemTest>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItemSpecItemTest.Output> { | |||
| 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<mdlInspectionCategoryItemSpecItemTest.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspectionCategoryItemSpecItemValue.Output>{ | |||
| 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<mdlInspectionCategoryItemSpecItemValue.Output>{ | |||
| 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<Page<mdlInspectionCategoryItemSpecItemValue.Output>>{ | |||
| 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<mdlInspectionCategoryItemSpecItemValue.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspectionCategoryItemSpecItemValue> { | |||
| 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<mdlInspectionCategoryItemSpecItemValue>.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<mdlInspectionCategoryItemSpecItemValue>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionCategoryItemSpecItemValue.Output> { | |||
| 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<mdlInspectionCategoryItemSpecItemValue.Output> { | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<mdlInspection.Output>{ | |||
| 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<mdlInspection.Output>{ | |||
| 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<Page<mdlInspection.Output>>{ | |||
| 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<mdlInspection.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| 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<mdlInspection> { | |||
| let query = mdlInspection.query(on: req.db) | |||
| .with(\.$workorder) | |||
| .with(\.$inspectiontype) | |||
| .with(\.$inspectionlevel) | |||
| .with(\.$technicians) | |||
| .with(\.$inspectioncategories) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlInspection) -> mdlInspection.Output { | |||
| return mdlInspection.Output( | |||
| id: output.id!, | |||
| interval: output.interval, | |||
| segment: output.segment, | |||
| startdate: output.startdate, | |||
| enddate: output.enddate, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| workorder: output.$workorder.value!, | |||
| inspectiontype: output.$inspectiontype.value!, | |||
| inspectionlevel: output.$inspectionlevel.value!, | |||
| technicians: output.$technicians.value!, | |||
| inspectioncategories: output.$inspectioncategories.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlInspection>.WrappedType, _ input: mdlInspection.Input){ | |||
| output.interval = input.interval; | |||
| output.segment = input.segment; | |||
| output.startdate = input.startdate; | |||
| output.enddate = input.enddate; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.workorder = input.workorder; | |||
| output.inspectiontype = input.inspectiontype; | |||
| output.inspectionlevel = input.inspectionlevel; | |||
| output.technicians = input.technicians!; | |||
| output.inspectioncategories = input.inspectioncategories! | |||
| } | |||
| func createUnit(_ input: mdlInspection.Input) -> mdlInspection { | |||
| return mdlInspection( | |||
| id: input.id ?? nil | |||
| , interval: input.interval | |||
| , segment: input.segment | |||
| , startdate: input.startdate | |||
| , enddate: input.enddate | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorder: input.workorder | |||
| , inspectiontye: input.inspectiontype | |||
| , inspectionlevel: input.inspectionlevel | |||
| , technicians: input.technicians! | |||
| , inspectioncategoryies: input.inspectioncategories! | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlInspection>.WrappedType, req: Request) -> EventLoopFuture<mdlInspection.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlInspection.Output( | |||
| id: output.id! | |||
| , interval: output.interval | |||
| , segment: output.segment | |||
| , startdate: output.startdate | |||
| , enddate: output.enddate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.workorder | |||
| , inspectiontype: output.inspectiontype | |||
| , inspectionlevel: output.inspectionlevel | |||
| , technicians: output.technicians | |||
| , inspectioncategories: output.inspectioncategories | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlInspection, _ req: Request, _ input: mdlInspection.Input) -> EventLoopFuture<mdlInspection.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlInspection.Output( | |||
| id: output.id! | |||
| , interval: output.interval | |||
| , segment: output.segment | |||
| , startdate: output.startdate | |||
| , enddate: output.enddate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: input.workorder | |||
| , inspectiontype: input.inspectiontype | |||
| , inspectionlevel: input.inspectionlevel | |||
| , technicians: input.technicians | |||
| , inspectioncategories: input.inspectioncategories | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension InspectionCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("inspections") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,168 @@ | |||
| // | |||
| // InspectionLevelCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class InspectionLevelCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlInspectionLevel.Output>{ | |||
| let input = try req.content.decode(mdlInspectionLevel.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlInspectionLevel.Output>{ | |||
| let input = try req.content.decode(mdlInspectionLevel.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<Page<mdlInspectionLevel.Output>>{ | |||
| 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<mdlInspectionLevel.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlInspectionLevel.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension InspectionLevelCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlInspectionLevel> { | |||
| let query = mdlInspectionLevel.query(on: req.db) | |||
| .with(\.$inspectiontype) | |||
| .with(\.$templates) | |||
| .with(\.$inspections) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlInspectionLevel) -> mdlInspectionLevel.Output { | |||
| return mdlInspectionLevel.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, | |||
| inspectiontype: output.$inspectiontype.value!, | |||
| templates: output.$templates.value!, | |||
| inspections: output.$inspections.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlInspectionLevel>.WrappedType, _ input: mdlInspectionLevel.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.$inspectiontype.id = input.inspectiontype.id!; | |||
| output.$templates.value = input.templates; | |||
| output.$inspections.value = input.inspections | |||
| } | |||
| func createUnit(_ input: mdlInspectionLevel.Input) -> mdlInspectionLevel { | |||
| return mdlInspectionLevel( | |||
| 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 | |||
| , inspectiontype: input.inspectiontype | |||
| , templates: input.templates | |||
| , inspections: input.inspections | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlInspectionLevel>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionLevel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlInspectionLevel.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 | |||
| , inspectiontype: output.inspectiontype | |||
| , templates: output.templates | |||
| , inspections: output.inspections | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlInspectionLevel, _ req: Request, _ input: mdlInspectionLevel.Input) -> EventLoopFuture<mdlInspectionLevel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlInspectionLevel.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 | |||
| , inspectiontype: input.inspectiontype | |||
| , templates: input.templates | |||
| , inspections: input.inspections | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension InspectionLevelCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("inspectionlevels") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| // | |||
| // InspectionTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class InspectionTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlInspectionType.Output>{ | |||
| let input = try req.content.decode(mdlInspectionType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlInspectionType.Output>{ | |||
| let input = try req.content.decode(mdlInspectionType.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<Page<mdlInspectionType.Output>>{ | |||
| 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<mdlInspectionType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlInspectionType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension InspectionTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlInspectionType> { | |||
| let query = mdlInspectionType.query(on: req.db).with(\.$templates).with(\.$inspections) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlInspectionType) -> mdlInspectionType.Output { | |||
| return mdlInspectionType.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, | |||
| templates: output.$templates.value!, | |||
| inspections: output.$inspections.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlInspectionType>.WrappedType, _ input: mdlInspectionType.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.$templates.value = input.templates; | |||
| output.$inspections.value = input.inspections | |||
| } | |||
| func createUnit(_ input: mdlInspectionType.Input) -> mdlInspectionType { | |||
| return mdlInspectionType( | |||
| 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 | |||
| , templates: input.templates | |||
| , inspections: input.inspections | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlInspectionType>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlInspectionType.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 | |||
| , templates: output.templates | |||
| , inspections: output.inspections | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlInspectionType, _ req: Request, _ input: mdlInspectionType.Input) -> EventLoopFuture<mdlInspectionType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlInspectionType.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 | |||
| , templates: output.templates | |||
| , inspections: output.inspections | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension InspectionTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("inspectiontypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // | |||
| // InspectionUserCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/12/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class InspectionUserCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlInspectionUser.Output>{ | |||
| let input = try req.content.decode(mdlInspectionUser.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlInspectionUser.Output>{ | |||
| let input = try req.content.decode(mdlInspectionUser.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<Page<mdlInspectionUser.Output>>{ | |||
| 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<mdlInspectionUser.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlInspectionUser.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension InspectionUserCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlInspectionUser> { | |||
| let query = mdlInspectionUser.query(on: req.db).with(\.$user).with(\.$inspection) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlInspectionUser) -> mdlInspectionUser.Output { | |||
| return mdlInspectionUser.Output( | |||
| id: output.id!, | |||
| user: output.$user.value!, | |||
| inspection: output.$inspection.value!, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlInspectionUser>.WrappedType, _ input: mdlInspectionUser.Input){ | |||
| output.$user.id = input.user.id!; | |||
| output.$inspection.id = input.inspection.id!; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid | |||
| } | |||
| func createUnit(_ input: mdlInspectionUser.Input) -> mdlInspectionUser { | |||
| return mdlInspectionUser( | |||
| id: input.id ?? nil | |||
| , user: input.user | |||
| , inspection: input.inspection | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlInspectionUser>.WrappedType, req: Request) -> EventLoopFuture<mdlInspectionUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlInspectionUser.Output( | |||
| id: output.id! | |||
| , user: output.user | |||
| , inspection: output.inspection | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlInspectionUser, _ req: Request, _ input: mdlInspectionUser.Input) -> EventLoopFuture<mdlInspectionUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlInspectionUser.Output( | |||
| id: output.id! | |||
| , user: input.user | |||
| , inspection: input.inspection | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension InspectionUserCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("inspectionusers") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,189 @@ | |||
| // | |||
| // ItemCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ItemCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlItem.Output>{ | |||
| let input = try req.content.decode(mdlItem.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlItem.Output>{ | |||
| let input = try req.content.decode(mdlItem.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<Page<mdlItem.Output>>{ | |||
| 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<mdlItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ItemCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlItem> { | |||
| let query = mdlItem.query(on: req.db) | |||
| .with(\.$category) | |||
| .with(\.$code) | |||
| .with(\.$inputtype) | |||
| .with(\.$specs) | |||
| .with(\.$responsetypes) | |||
| .with(\.$templatecategoryitems) | |||
| .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: mdlItem) -> mdlItem.Output { | |||
| return mdlItem.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, | |||
| category: output.$category.value!, | |||
| code: output.$code.value!, | |||
| inputtype: output.$inputtype.value!, | |||
| responsetypes: output.$responsetypes.value! | |||
| , specs: output.$specs.value!, | |||
| templatecategoryitems: output.$templatecategoryitems.value!, | |||
| inspectioncategoryitems: output.$inspectioncategoryitems.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlItem>.WrappedType, _ input: mdlItem.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.$category.id = input.category.id!; | |||
| output.$code.id = input.code.id!; | |||
| output.$inputtype.id = input.inputtype.id!; | |||
| output.$specs.value = input.specs; | |||
| output.$templatecategoryitems.value = input.templatecategoryitems; | |||
| output.$inspectioncategoryitems.value = input.inspectioncategoryitems; | |||
| output.$responsetypes.value = input.responsetypes; | |||
| } | |||
| func createUnit(_ input: mdlItem.Input) -> mdlItem { | |||
| return mdlItem( | |||
| 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 | |||
| , responsetypes: input.responsetypes | |||
| , specs: input.specs | |||
| , templatecategoryitems: input.templatecategoryitems | |||
| , inspectioncategoryitems: input.inspectioncategoryitems | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlItem>.WrappedType, req: Request) -> EventLoopFuture<mdlItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlItem.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 | |||
| , category: output.category | |||
| , code: output.code | |||
| , inputtype: output.inputtype | |||
| , responsetypes: output.responsetypes | |||
| , specs: output.specs | |||
| , templatecategoryitems: output.templatecategoryitems | |||
| , inspectioncategoryitems: output.inspectioncategoryitems | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlItem, _ req: Request, _ input: mdlItem.Input) -> EventLoopFuture<mdlItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlItem.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 | |||
| , category: input.category | |||
| , code: input.code | |||
| , inputtype: input.inputtype | |||
| , responsetypes: input.responsetypes | |||
| , specs: input.specs | |||
| , templatecategoryitems: input.templatecategoryitems | |||
| , inspectioncategoryitems: input.inspectioncategoryitems | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ItemCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("items") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // JobSiteCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class JobSiteCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlJobSite.Output>{ | |||
| let input = try req.content.decode(mdlJobSite.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlJobSite.Output>{ | |||
| let input = try req.content.decode(mdlJobSite.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<Page<mdlJobSite.Output>>{ | |||
| 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<mdlJobSite.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlJobSite.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension JobSiteCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlJobSite> { | |||
| let query = mdlJobSite.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: mdlJobSite) -> mdlJobSite.Output { | |||
| return mdlJobSite.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<mdlJobSite>.WrappedType, _ input: mdlJobSite.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: mdlJobSite.Input) -> mdlJobSite { | |||
| return mdlJobSite( | |||
| 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<mdlJobSite>.WrappedType, req: Request) -> EventLoopFuture<mdlJobSite.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlJobSite.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: mdlJobSite, _ req: Request, _ input: mdlJobSite.Input) -> EventLoopFuture<mdlJobSite.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlJobSite.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 JobSiteCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("jobsites") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,179 @@ | |||
| // | |||
| // LabSettingCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/2/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class LabSettingCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlLabSetting.Output>{ | |||
| let input = try req.content.decode(mdlLabSetting.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlLabSetting.Output>{ | |||
| let input = try req.content.decode(mdlLabSetting.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<Page<mdlLabSetting.Output>>{ | |||
| 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<mdlLabSetting.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlLabSetting.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension LabSettingCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlLabSetting> { | |||
| let query = mdlLabSetting.query(on: req.db).with(\.$oilsamplelabels).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: mdlLabSetting) -> mdlLabSetting.Output { | |||
| return mdlLabSetting.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| description: output.description, | |||
| barcodedelimiter: output.barcodedelimiter, | |||
| barcodeactive: output.barcodeactive, | |||
| textactive: output.textactive, | |||
| logoactive: output.logoactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| oilsamplelabels: output.$oilsamplelabels.value!, | |||
| users: output.$users.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlLabSetting>.WrappedType, _ input: mdlLabSetting.Input){ | |||
| output.name = input.name; | |||
| output.description = input.description; | |||
| output.barcodedelimiter = input.barcodedelimiter; | |||
| output.barcodeactive = input.barcodeactive; | |||
| output.textactive = input.textactive; | |||
| output.logoactive = input.logoactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$oilsamplelabels.value = input.oilsamplelabels | |||
| } | |||
| func createUnit(_ input: mdlLabSetting.Input) -> mdlLabSetting { | |||
| return mdlLabSetting( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , description: input.description | |||
| , barcodedelimiter: input.barcodedelimiter | |||
| , barcodeactive: input.barcodeactive | |||
| , textactive: input.textactive | |||
| , logoactive: input.logoactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , oilsamplelabels: input.oilsamplelabels | |||
| , users: input.users | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlLabSetting>.WrappedType, req: Request) -> EventLoopFuture<mdlLabSetting.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlLabSetting.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , barcodedelimiter: output.barcodedelimiter | |||
| , barcodeactive: output.barcodeactive | |||
| , textactive: output.textactive | |||
| , logoactive: output.logoactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , oilsamplelabels: output.oilsamplelabels | |||
| , users: output.users | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlLabSetting, _ req: Request, _ input: mdlLabSetting.Input) -> EventLoopFuture<mdlLabSetting.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlLabSetting.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , barcodedelimiter: output.barcodedelimiter | |||
| , barcodeactive: output.barcodeactive | |||
| , textactive: output.textactive | |||
| , logoactive: output.logoactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , oilsamplelabels: output.oilsamplelabels | |||
| , users: output.users | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension LabSettingCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("labsettings") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // LebelCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class LevelCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlLevel.Output>{ | |||
| let input = try req.content.decode(mdlLevel.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlLevel.Output>{ | |||
| let input = try req.content.decode(mdlLevel.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<Page<mdlLevel.Output>>{ | |||
| 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<mdlLevel.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlLevel.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension LevelCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlLevel> { | |||
| let query = mdlLevel.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: mdlLevel) -> mdlLevel.Output { | |||
| return mdlLevel.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<mdlLevel>.WrappedType, _ input: mdlLevel.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: mdlLevel.Input) -> mdlLevel { | |||
| return mdlLevel( | |||
| 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<mdlLevel>.WrappedType, req: Request) -> EventLoopFuture<mdlLevel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlLevel.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: mdlLevel, _ req: Request, _ input: mdlLevel.Input) -> EventLoopFuture<mdlLevel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlLevel.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 LevelCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("levels") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // LicenseCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class LicenseCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlLicense.Output>{ | |||
| let input = try req.content.decode(mdlLicense.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlLicense.Output>{ | |||
| let input = try req.content.decode(mdlLicense.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<Page<mdlLicense.Output>>{ | |||
| 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<mdlLicense.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlLicense.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension LicenseCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlLicense> { | |||
| let query = mdlLicense.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: mdlLicense) -> mdlLicense.Output { | |||
| return mdlLicense.Output( | |||
| id: output.id!, | |||
| value: output.value, | |||
| sortorder: output.sortorder, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlLicense>.WrappedType, _ input: mdlLicense.Input){ | |||
| output.value = input.value; | |||
| 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: mdlLicense.Input) -> mdlLicense { | |||
| return mdlLicense( | |||
| id: input.id ?? nil | |||
| , value: input.value | |||
| , 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<mdlLicense>.WrappedType, req: Request) -> EventLoopFuture<mdlLicense.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlLicense.Output( | |||
| id: output.id! | |||
| , value: output.value | |||
| , sortorder: output.sortorder | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlLicense, _ req: Request, _ input: mdlLicense.Input) -> EventLoopFuture<mdlLicense.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlLicense.Output( | |||
| id: output.id! | |||
| , value: output.value | |||
| , sortorder: output.sortorder | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension LicenseCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("licenses") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,209 @@ | |||
| // | |||
| // Location.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/3/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class LocationCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlLocation.Output>{ | |||
| let input = try req.content.decode(mdlLocation.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlLocation.Output>{ | |||
| let input = try req.content.decode(mdlLocation.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<Page<mdlLocation.Output>>{ | |||
| 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<mdlLocation.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlLocation.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension LocationCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlLocation> { | |||
| let query = mdlLocation.query(on: req.db) | |||
| .with(\.$unit) | |||
| .with(\.$labsetting) | |||
| .with(\.$user) | |||
| .with(\.$contacts) | |||
| .with(\.$gates) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlLocation) -> mdlLocation.Output { | |||
| return mdlLocation.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| address: output.address, | |||
| address2: output.address2, | |||
| city: output.city, | |||
| state: output.state, | |||
| zip: output.zip, | |||
| dealercode: output.dealercode, | |||
| logofile: output.logofile, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| unit: output.$unit.value!, | |||
| labsetting: output.$labsetting.value!, | |||
| user: output.$user.value!, | |||
| contacts: output.$contacts.value!, | |||
| gates: output.$gates.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlLocation>.WrappedType, _ input: mdlLocation.Input){ | |||
| 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.dealercode = input.dealercode; | |||
| output.logofile = input.logofile; | |||
| output.isactive = input.isactive | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$unit.id = input.unit.id!; | |||
| output.$labsetting.id = input.id!; | |||
| output.$user.value = input.user; | |||
| output.$contacts.value = input.contacts | |||
| output.$gates.value = input.gates | |||
| } | |||
| func createUnit(_ input: mdlLocation.Input) -> mdlLocation { | |||
| return mdlLocation( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , address: input.address | |||
| , address2: input.address2 | |||
| , city: input.city | |||
| , state: input.state | |||
| , zip: input.zip | |||
| , dealercode: input.dealercode | |||
| , logofile: input.logofile | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , unit: input.unit | |||
| , labsetting: input.labsetting | |||
| , user: input.user | |||
| , contacts: input.contacts | |||
| , gates: input.gates | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlLocation>.WrappedType, req: Request) -> EventLoopFuture<mdlLocation.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlLocation.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , address: output.address | |||
| , address2: output.address2 | |||
| , city: output.city | |||
| , state: output.state | |||
| , zip: output.zip | |||
| , dealercode: output.dealercode | |||
| , logofile: output.logofile | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , unit: output.unit | |||
| , labsetting: output.labsetting | |||
| , user: output.user | |||
| , contacts: output.contacts | |||
| , gates: output.gates | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlLocation, _ req: Request, _ input: mdlLocation.Input) -> EventLoopFuture<mdlLocation.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlLocation.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , address: output.address | |||
| , address2: output.address2 | |||
| , city: output.city | |||
| , state: output.state | |||
| , zip: output.zip | |||
| , dealercode: output.dealercode | |||
| , logofile: output.logofile | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , unit: output.unit | |||
| , labsetting: input.labsetting | |||
| , user: input.user | |||
| , contacts: input.contacts | |||
| , gates: input.gates | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension LocationCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("locations") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,234 @@ | |||
| // | |||
| // MachineCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class MachineCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlMachine.Output>{ | |||
| let input = try req.content.decode(mdlMachine.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlMachine.Output>{ | |||
| let input = try req.content.decode(mdlMachine.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<Page<mdlMachine.Output>>{ | |||
| 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<mdlMachine.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlMachine.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension MachineCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlMachine> { | |||
| let query = mdlMachine.query(on: req.db) | |||
| .with(\.$machinetype) | |||
| .with(\.$parent) | |||
| .with(\.$model) | |||
| .with(\.$machinenumbers) | |||
| .with(\.$machinemeters) | |||
| .with(\.$customers) | |||
| .with(\.$children) | |||
| .with(\.$templates) | |||
| .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: mdlMachine) -> mdlMachine.Output { | |||
| return mdlMachine.Output( | |||
| id: output.id!, | |||
| manufactureryear: output.manufactureryear, | |||
| description: output.description, | |||
| currentlocation: output.currentlocation, | |||
| lastservicedate: output.lastservicedate, | |||
| isactive: output.isactive, | |||
| voltage: output.voltage, | |||
| kw: output.kw, | |||
| phase: output.phase, | |||
| inservicedate: output.inservicedate, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| machinetype: output.$machinetype.value!, | |||
| parent: output.$parent.value!, | |||
| model: output.$model.value!, | |||
| machinenumbers: output.$machinenumbers.value!, | |||
| machinemeters: output.$machinemeters.value!, | |||
| customers: output.$customers.value!, | |||
| children: output.$children.value!, | |||
| templates: output.$templates.value!, | |||
| workorders: output.$workorders.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlMachine>.WrappedType, _ input: mdlMachine.Input){ | |||
| output.manufactureryear = input.manufactureryear; | |||
| output.description = input.description; | |||
| output.currentlocation = input.currentlocation; | |||
| output.lastservicedate = input.lastservicedate; | |||
| output.isactive = input.isactive; | |||
| output.voltage = input.voltage; | |||
| output.kw = input.kw; | |||
| output.phase = input.phase; | |||
| output.inservicedate = input.inservicedate; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$machinetype.id = input.machinetype.id!; | |||
| output.$parent.id = input.parent.id!; | |||
| output.$model.id = input.model.id!; | |||
| output.$machinenumbers.value = input.machinenumbers; | |||
| output.$machinemeters.value = input.machinemeters; | |||
| output.$customers.value = input.customers; | |||
| output.$children.value = input.children; | |||
| output.$templates.value = input.templates; | |||
| output.$workorders.value = input.workorders | |||
| } | |||
| func createUnit(_ input: mdlMachine.Input) -> mdlMachine { | |||
| return mdlMachine( | |||
| id: input.id ?? nil | |||
| , manufactureryear: input.manufactureryear | |||
| , description: input.description | |||
| , currentlocation: input.currentlocation | |||
| , lastservicedate: input.lastservicedate | |||
| , isactive: input.isactive | |||
| , voltage: input.voltage | |||
| , kw: input.kw | |||
| , phase: input.phase | |||
| , inservicedate: input.inservicedate | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , machinetype: input.machinetype | |||
| , parent: input.parent | |||
| , model: input.model | |||
| , machinenumbers: input.machinenumbers | |||
| , machinemeters: input.machinemeters | |||
| , customers: input.customers | |||
| , children: input.children | |||
| , templates: input.templates | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlMachine>.WrappedType, req: Request) -> EventLoopFuture<mdlMachine.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlMachine.Output( | |||
| id: output.id! | |||
| , manufactureryear: output.manufactureryear | |||
| , description: output.description | |||
| , currentlocation: output.currentlocation | |||
| , lastservicedate: output.lastservicedate | |||
| , isactive: output.isactive | |||
| , voltage: output.voltage | |||
| , kw: output.kw | |||
| , phase: output.phase | |||
| , inservicedate: output.inservicedate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machinetype: output.machinetype | |||
| , parent: output.parent | |||
| , model: output.model | |||
| , machinenumbers: output.machinenumbers | |||
| , machinemeters: output.machinemeters | |||
| , customers: output.customers | |||
| , children: output.children | |||
| , templates: output.templates | |||
| , workorders: output.workorders | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlMachine, _ req: Request, _ input: mdlMachine.Input) -> EventLoopFuture<mdlMachine.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlMachine.Output( | |||
| id: output.id! | |||
| , manufactureryear: output.manufactureryear | |||
| , description: output.description | |||
| , currentlocation: output.currentlocation | |||
| , lastservicedate: output.lastservicedate | |||
| , isactive: output.isactive | |||
| , voltage: output.voltage | |||
| , kw: output.kw | |||
| , phase: output.phase | |||
| , inservicedate: output.inservicedate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machinetype: input.machinetype | |||
| , parent: input.parent | |||
| , model: input.model | |||
| , machinenumbers: input.machinenumbers | |||
| , machinemeters: input.machinemeters | |||
| , customers: input.customers | |||
| , children: input.children | |||
| , templates: input.templates | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension MachineCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("machines") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // MachineMeterCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class MachineMeterCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlMachineMeter.Output>{ | |||
| let input = try req.content.decode(mdlMachineMeter.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlMachineMeter.Output>{ | |||
| let input = try req.content.decode(mdlMachineMeter.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<Page<mdlMachineMeter.Output>>{ | |||
| 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<mdlMachineMeter.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlMachineMeter.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension MachineMeterCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlMachineMeter> { | |||
| let query = mdlMachineMeter.query(on: req.db).with(\.$machine) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlMachineMeter) -> mdlMachineMeter.Output { | |||
| return mdlMachineMeter.Output( | |||
| id: output.id!, | |||
| label: output.label, | |||
| value: output.value, | |||
| imgfile: output.imgfile, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| machine: output.$machine.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlMachineMeter>.WrappedType, _ input: mdlMachineMeter.Input){ | |||
| output.label = input.label; | |||
| output.value = input.value; | |||
| output.imgfile = input.imgfile; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$machine.id = input.machine.id! | |||
| } | |||
| func createUnit(_ input: mdlMachineMeter.Input) -> mdlMachineMeter { | |||
| return mdlMachineMeter( | |||
| id: input.id ?? nil | |||
| , label: input.label | |||
| , value: input.value | |||
| , imgfile: input.imgfile | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , machine: input.machine | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlMachineMeter>.WrappedType, req: Request) -> EventLoopFuture<mdlMachineMeter.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlMachineMeter.Output( | |||
| id: output.id! | |||
| , label: output.label | |||
| , value: output.value | |||
| , imgfile: output.imgfile | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machine: output.machine | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlMachineMeter, _ req: Request, _ input: mdlMachineMeter.Input) -> EventLoopFuture<mdlMachineMeter.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlMachineMeter.Output( | |||
| id: output.id! | |||
| , label: output.label | |||
| , value: output.value | |||
| , imgfile: output.imgfile | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machine: input.machine | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension MachineMeterCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("machinemeters") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,153 @@ | |||
| // | |||
| // MachineNumberCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class MachineNumberCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlMachineNumber.Output>{ | |||
| let input = try req.content.decode(mdlMachineNumber.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlMachineNumber.Output>{ | |||
| let input = try req.content.decode(mdlMachineNumber.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<Page<mdlMachineNumber.Output>>{ | |||
| 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<mdlMachineNumber.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlMachineNumber.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension MachineNumberCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlMachineNumber> { | |||
| let query = mdlMachineNumber.query(on: req.db).with(\.$machine) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlMachineNumber) -> mdlMachineNumber.Output { | |||
| return mdlMachineNumber.Output( | |||
| id: output.id!, | |||
| label: output.label, | |||
| value: output.value, | |||
| imgfile: output.imgfile, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| machine: output.$machine.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlMachineNumber>.WrappedType, _ input: mdlMachineNumber.Input){ | |||
| output.label = input.label; | |||
| output.value = input.value; | |||
| output.imgfile = input.imgfile; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$machine.id = input.machine.id! | |||
| } | |||
| func createUnit(_ input: mdlMachineNumber.Input) -> mdlMachineNumber { | |||
| return mdlMachineNumber( | |||
| id: input.id ?? nil | |||
| , label: input.label | |||
| , value: input.value | |||
| , imgfile: input.imgfile | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , machine: input.machine | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlMachineNumber>.WrappedType, req: Request) -> EventLoopFuture<mdlMachineNumber.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlMachineNumber.Output( | |||
| id: output.id! | |||
| , label: output.label | |||
| , value: output.value | |||
| , imgfile: output.imgfile | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machine: output.machine | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlMachineNumber, _ req: Request, _ input: mdlMachineNumber.Input) -> EventLoopFuture<mdlMachineNumber.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlMachineNumber.Output( | |||
| id: output.id! | |||
| , label: output.label | |||
| , value: output.value | |||
| , imgfile: output.imgfile | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machine: input.machine | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension MachineNumberCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("machinenumbers") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // MachineTypeCtrl.swift.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class MachineTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlMachineType.Output>{ | |||
| let input = try req.content.decode(mdlMachineType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlMachineType.Output>{ | |||
| let input = try req.content.decode(mdlMachineType.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<Page<mdlMachineType.Output>>{ | |||
| 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<mdlMachineType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlMachineType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension MachineTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlMachineType> { | |||
| let query = mdlMachineType.query(on: req.db).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: mdlMachineType) -> mdlMachineType.Output { | |||
| return mdlMachineType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| description: output.description, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| machines: output.$machines.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlMachineType>.WrappedType, _ input: mdlMachineType.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.$machines.value = input.machines | |||
| } | |||
| func createUnit(_ input: mdlMachineType.Input) -> mdlMachineType { | |||
| return mdlMachineType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , description: input.description | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , machines: input.machines! | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlMachineType>.WrappedType, req: Request) -> EventLoopFuture<mdlMachineType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlMachineType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machines: output.machines | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlMachineType, _ req: Request, _ input: mdlMachineType.Input) -> EventLoopFuture<mdlMachineType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlMachineType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , machines: input.machines | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension MachineTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("machinetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,161 @@ | |||
| // | |||
| // MakeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class MakeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlMake.Output>{ | |||
| let input = try req.content.decode(mdlMake.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlMake.Output>{ | |||
| let input = try req.content.decode(mdlMake.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<Page<mdlMake.Output>>{ | |||
| 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<mdlMake.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlMake.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension MakeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlMake> { | |||
| let query = mdlMake.query(on: req.db).with(\.$models).with(\.$templates) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlMake) -> mdlMake.Output { | |||
| return mdlMake.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, | |||
| models: output.$models.value!, | |||
| templates: output.$templates.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlMake>.WrappedType, _ input: mdlMake.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.$models.value = input.models; | |||
| output.$templates.value = input.templates | |||
| } | |||
| func createUnit(_ input: mdlMake.Input) -> mdlMake { | |||
| return mdlMake( | |||
| 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 | |||
| , models: input.models | |||
| , templates: input.templates | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlMake>.WrappedType, req: Request) -> EventLoopFuture<mdlMake.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlMake.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 | |||
| , models: output.models | |||
| , templates: output.templates | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlMake, _ req: Request, _ input: mdlMake.Input) -> EventLoopFuture<mdlMake.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlMake.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 | |||
| , models: input.models | |||
| , templates: input.templates | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension MakeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("makes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,191 @@ | |||
| // | |||
| // ModelCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| import AppKit | |||
| final class ModelCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlModel.Output>{ | |||
| let input = try req.content.decode(mdlModel.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlModel.Output>{ | |||
| let input = try req.content.decode(mdlModel.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<Page<mdlModel.Output>>{ | |||
| 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<mdlModel.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlModel.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ModelCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlModel> { | |||
| let query = mdlModel.query(on: req.db) | |||
| .with(\.$make) | |||
| .with(\.$product) | |||
| .with(\.$templates) | |||
| .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: mdlModel) -> mdlModel.Output { | |||
| return mdlModel.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, | |||
| make: output.$make.value!, | |||
| product: output.$product.value!, | |||
| templates: output.$templates.value!, | |||
| machines: output.$machines.value! | |||
| ) | |||
| } | |||
| func makemake(_ output: Optional<mdlMake>.Wrapped,_ input: mdlMake.Input) { | |||
| output.id = input.id!; | |||
| output.name = input.name; | |||
| output.description = input.description; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.createuserid = input.createuserid; | |||
| output.updatedate = input.updatedate; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$templates.value = input.templates; | |||
| output.$models.value = input.models; | |||
| } | |||
| func makeproduct(input: mdlModel.Input) -> mdlProduct{ | |||
| return mdlProduct(id: input.product.id!, code: input.product.code, description: input.product.description, isactive: input.product.isactive, createuserid: input.product.createuserid, createdate: input.product.createdate, updateuserid: input.product.updateuserid, updatedate: input.product.updatedate, models: input.product.models, templates: input.product.templates) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlModel>.WrappedType, _ input: mdlModel.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.$make.id = input.make.id!; | |||
| output.$product.id = input.product.id!; | |||
| output.$templates.value = input.templates; | |||
| output.$machines.value = input.machines | |||
| } | |||
| func createUnit(_ input: mdlModel.Input) -> mdlModel { | |||
| return mdlModel( | |||
| 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 | |||
| , make: input.make | |||
| , product: input.product | |||
| , templates: input.templates | |||
| , machines: input.machines | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlModel>.WrappedType, req: Request) -> EventLoopFuture<mdlModel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlModel.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 | |||
| , make: output.make | |||
| , product: output.product | |||
| , templates: output.templates | |||
| , machines: output.machines | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlModel, _ req: Request, _ input: mdlModel.Input) -> EventLoopFuture<mdlModel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlModel.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 | |||
| , make: input.make | |||
| , product: input.product | |||
| , templates: input.templates | |||
| , machines: input.machines | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ModelCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("models") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| // | |||
| // ModuleCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ModuleCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlModule.Output>{ | |||
| let input = try req.content.decode(mdlModule.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlModule.Output>{ | |||
| let input = try req.content.decode(mdlModule.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<Page<mdlModule.Output>>{ | |||
| 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<mdlModule.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlModule.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ModuleCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlModule> { | |||
| let query = mdlModule.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: mdlModule) -> mdlModule.Output { | |||
| return mdlModule.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, | |||
| users: output.$users.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlModule>.WrappedType, _ input: mdlModule.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; | |||
| output.$users.value = input.users | |||
| } | |||
| func createUnit(_ input: mdlModule.Input) -> mdlModule { | |||
| return mdlModule( | |||
| 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 | |||
| , users: input.users | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlModule>.WrappedType, req: Request) -> EventLoopFuture<mdlModule.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlModule.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 | |||
| , users: output.users | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlModule, _ req: Request, _ input: mdlModule.Input) -> EventLoopFuture<mdlModule.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlModule.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 | |||
| , users: input.users | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ModuleCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("modules") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,156 @@ | |||
| // | |||
| // NoteCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/12/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class NoteCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlNote.Output>{ | |||
| let input = try req.content.decode(mdlNote.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlNote.Output>{ | |||
| let input = try req.content.decode(mdlNote.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<Page<mdlNote.Output>>{ | |||
| 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<mdlNote.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlNote.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension NoteCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlNote> { | |||
| let query = mdlNote.query(on: req.db).with(\.$notetype).with(\.$workorder).with(\.$inspectioncategoryitem) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlNote) -> mdlNote.Output { | |||
| return mdlNote.Output( | |||
| id: output.id! | |||
| , text: output.text | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.$workorder.value! | |||
| , inspectioncategoryitem: output.$inspectioncategoryitem.value! | |||
| , notetype: output.$notetype.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlNote>.WrappedType, _ input: mdlNote.Input){ | |||
| output.text = input.text; | |||
| output.$workorder.id = input.workorder.id!; | |||
| output.$inspectioncategoryitem.id = input.inspectioncategoryitem.id!; | |||
| output.$notetype.id = input.notetype.id!; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid | |||
| } | |||
| func createUnit(_ input: mdlNote.Input) -> mdlNote { | |||
| return mdlNote( | |||
| id: input.id ?? nil | |||
| , text: input.text | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorder: input.workorder | |||
| , inspectioncategoryitem: input.inspectioncategoryitem | |||
| , notetype: input.notetype | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlNote>.WrappedType, req: Request) -> EventLoopFuture<mdlNote.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlNote.Output( | |||
| id: output.id! | |||
| , text: output.text | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.workorder | |||
| , inspectioncategoryitem: output.inspectioncategoryitem | |||
| , notetype: output.notetype | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlNote, _ req: Request, _ input: mdlNote.Input) -> EventLoopFuture<mdlNote.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlNote.Output( | |||
| id: output.id! | |||
| , text: output.text | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: input.workorder | |||
| , inspectioncategoryitem: input.inspectioncategoryitem | |||
| , notetype: input.notetype | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension NoteCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("notes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // | |||
| // NoteTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class NoteTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlNoteType.Output>{ | |||
| let input = try req.content.decode(mdlNoteType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlNoteType.Output>{ | |||
| let input = try req.content.decode(mdlNoteType.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<Page<mdlNoteType.Output>>{ | |||
| 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<mdlNoteType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlNoteType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension NoteTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlNoteType> { | |||
| let query = mdlNoteType.query(on: req.db).with(\.$notes) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlNoteType) -> mdlNoteType.Output { | |||
| return mdlNoteType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| notes: output.$notes.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlNoteType>.WrappedType, _ input: mdlNoteType.Input){ | |||
| output.name = input.name | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$notes.value = input.notes | |||
| } | |||
| func createUnit(_ input: mdlNoteType.Input) -> mdlNoteType { | |||
| return mdlNoteType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , notes: input.notes | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlNoteType>.WrappedType, req: Request) -> EventLoopFuture<mdlNoteType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlNoteType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , notes: output.notes | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlNoteType, _ req: Request, _ input: mdlNoteType.Input) -> EventLoopFuture<mdlNoteType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlNoteType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , notes: input.notes | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension NoteTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("notetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // OilSampleCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/11/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class OilSampleCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlOilSample.Output>{ | |||
| let input = try req.content.decode(mdlOilSample.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlOilSample.Output>{ | |||
| let input = try req.content.decode(mdlOilSample.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<Page<mdlOilSample.Output>>{ | |||
| 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<mdlOilSample.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlOilSample.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension OilSampleCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlOilSample> { | |||
| let query = mdlOilSample.query(on: req.db).with(\.$workorder).with(\.$oilsampleitems) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlOilSample) -> mdlOilSample.Output { | |||
| return mdlOilSample.Output( | |||
| id: output.id!, | |||
| segment: output.segment, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| workorder: output.$workorder.value!, | |||
| oilsampleitems: output.$oilsampleitems.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlOilSample>.WrappedType, _ input: mdlOilSample.Input){ | |||
| output.segment = input.segment; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$workorder.id = input.workorder.id!; | |||
| output.$oilsampleitems.value = input.oilsampleitems! | |||
| } | |||
| func createUnit(_ input: mdlOilSample.Input) -> mdlOilSample { | |||
| return mdlOilSample( | |||
| id: input.id ?? nil | |||
| , segment: input.segment | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorder: input.workorder | |||
| , oilsampleitems: input.oilsampleitems | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlOilSample>.WrappedType, req: Request) -> EventLoopFuture<mdlOilSample.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlOilSample.Output( | |||
| id: output.id! | |||
| , segment: output.segment | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.workorder | |||
| , oilsampleitems: output.oilsampleitems | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlOilSample, _ req: Request, _ input: mdlOilSample.Input) -> EventLoopFuture<mdlOilSample.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlOilSample.Output( | |||
| id: output.id! | |||
| , segment: output.segment | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: input.workorder | |||
| , oilsampleitems: input.oilsampleitems | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension OilSampleCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("oilsamples") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,238 @@ | |||
| // | |||
| // OilSampleItem.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/11/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class OilSampleItemCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlOilSampleItem.Output>{ | |||
| let input = try req.content.decode(mdlOilSampleItem.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlOilSampleItem.Output>{ | |||
| let input = try req.content.decode(mdlOilSampleItem.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<Page<mdlOilSampleItem.Output>>{ | |||
| 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<mdlOilSampleItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlOilSampleItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension OilSampleItemCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlOilSampleItem> { | |||
| let query = mdlOilSampleItem.query(on: req.db).with(\.$oilsample) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| /* | |||
| let id: Int? | |||
| let compartmentname: String | |||
| let compartmentcode: String | |||
| let compartmentlocationname1: String | |||
| let compartmentlocationcode1: String | |||
| let compartmentlocationname2: String | |||
| let compartmentlocationcode2: String | |||
| let hoursonoil: Decimal? | |||
| let oiladded: Decimal? | |||
| let jobsitename: String | |||
| let fluidname: String | |||
| let viscosityname: String | |||
| let oilchanged: Bool? | |||
| let filterchanged: Bool? | |||
| let levelname: String | |||
| let comment: String | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let oilsample: mdlOilSample | |||
| */ | |||
| //create Output | |||
| func createRead(_ output: mdlOilSampleItem) -> mdlOilSampleItem.Output { | |||
| return mdlOilSampleItem.Output( | |||
| id: output.id!, | |||
| compartmentname: output.compartmentname, | |||
| compartmentcode: output.compartmentcode, | |||
| compartmentlocationname1: output.compartmentlocationname1, | |||
| compartmentlocationcode1: output.compartmentlocationcode1, | |||
| compartmentlocationname2: output.compartmentlocationname2, | |||
| compartmentlocationcode2: output.compartmentlocationcode2, | |||
| hoursonoil: output.hoursonoil, | |||
| oiladded: output.oiladded, | |||
| jobsitename: output.jobsitename, | |||
| fluidname: output.fluidname, | |||
| viscosityname: output.viscosityname, | |||
| oilchanged: output.oilchanged, | |||
| filterchanged: output.filterchanged, | |||
| levelname: output.levelname, | |||
| comment: output.comment, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| oilsample: output.$oilsample.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlOilSampleItem>.WrappedType, _ input: mdlOilSampleItem.Input){ | |||
| output.compartmentname = input.compartmentname; | |||
| output.compartmentcode = input.compartmentcode; | |||
| output.compartmentlocationname1 = input.compartmentlocationname1; | |||
| output.compartmentlocationcode1 = input.compartmentlocationcode1; | |||
| output.compartmentlocationname2 = input.compartmentlocationname2; | |||
| output.compartmentlocationcode2 = input.compartmentlocationcode2; | |||
| output.hoursonoil = input.hoursonoil; | |||
| output.oiladded = input.oiladded; | |||
| output.jobsitename = input.jobsitename; | |||
| output.fluidname = input.fluidname; | |||
| output.viscosityname = input.viscosityname; | |||
| output.oilchanged = input.oilchanged; | |||
| output.filterchanged = input.filterchanged; | |||
| output.levelname = input.levelname; | |||
| output.comment = input.comment; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$oilsample.id = input.oilsample.id! | |||
| } | |||
| func createUnit(_ input: mdlOilSampleItem.Input) -> mdlOilSampleItem { | |||
| return mdlOilSampleItem( | |||
| id: input.id ?? nil | |||
| , compartmentname: input.compartmentname | |||
| , compartmentcode: input.compartmentcode | |||
| , compartmentlocationname1: input.compartmentlocationname1 | |||
| , compartmentlocationcode1: input.compartmentlocationcode1 | |||
| , compartmentlocationname2: input.compartmentlocationname2 | |||
| , compartmentlocationcode2: input.compartmentlocationcode2 | |||
| , hoursonoil: input.hoursonoil | |||
| , oiladded: input.oiladded | |||
| , jobsitename: input.jobsitename | |||
| , fluidname: input.fluidname | |||
| , viscosityname: input.viscosityname | |||
| , oilchanged: input.oilchanged | |||
| , filterchanged: input.filterchanged | |||
| , levelname: input.levelname | |||
| , comment: input.comment | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , oilsample: input.oilsample | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlOilSampleItem>.WrappedType, req: Request) -> EventLoopFuture<mdlOilSampleItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlOilSampleItem.Output( | |||
| id: output.id! | |||
| , compartmentname: output.compartmentname | |||
| , compartmentcode: output.compartmentcode | |||
| , compartmentlocationname1: output.compartmentlocationname1 | |||
| , compartmentlocationcode1: output.compartmentlocationcode1 | |||
| , compartmentlocationname2: output.compartmentlocationname2 | |||
| , compartmentlocationcode2: output.compartmentlocationcode2 | |||
| , hoursonoil: output.hoursonoil | |||
| , oiladded: output.oiladded | |||
| , jobsitename: output.jobsitename | |||
| , fluidname: output.fluidname | |||
| , viscosityname: output.viscosityname | |||
| , oilchanged: output.oilchanged | |||
| , filterchanged: output.filterchanged | |||
| , levelname: output.levelname | |||
| , comment: output.comment | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , oilsample: output.oilsample | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlOilSampleItem, _ req: Request, _ input: mdlOilSampleItem.Input) -> EventLoopFuture<mdlOilSampleItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlOilSampleItem.Output( | |||
| id: output.id! | |||
| , compartmentname: output.compartmentname | |||
| , compartmentcode: output.compartmentcode | |||
| , compartmentlocationname1: output.compartmentlocationname1 | |||
| , compartmentlocationcode1: output.compartmentlocationcode1 | |||
| , compartmentlocationname2: output.compartmentlocationname2 | |||
| , compartmentlocationcode2: output.compartmentlocationcode2 | |||
| , hoursonoil: output.hoursonoil | |||
| , oiladded: output.oiladded | |||
| , jobsitename: output.jobsitename | |||
| , fluidname: output.fluidname | |||
| , viscosityname: output.viscosityname | |||
| , oilchanged: output.oilchanged | |||
| , filterchanged: output.filterchanged | |||
| , levelname: output.levelname | |||
| , comment: output.comment | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , oilsample: input.oilsample | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension OilSampleItemCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("oilsampleitems") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,190 @@ | |||
| // | |||
| // OilSampleLabelCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/11/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class OilSampleLabelCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlOilSampleLabel.Output>{ | |||
| let input = try req.content.decode(mdlOilSampleLabel.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlOilSampleLabel.Output>{ | |||
| let input = try req.content.decode(mdlOilSampleLabel.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<Page<mdlOilSampleLabel.Output>>{ | |||
| 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<mdlOilSampleLabel.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlOilSampleLabel.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension OilSampleLabelCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlOilSampleLabel> { | |||
| let query = mdlOilSampleLabel.query(on: req.db).with(\.$labsetting) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| /* | |||
| ,name: String | |||
| ,description: String | |||
| ,size: String | |||
| ,offset: String | |||
| ,hrez: String | |||
| ,vrez: String | |||
| ,height: String | |||
| ,quantity: Int | |||
| */ | |||
| //create Output | |||
| func createRead(_ output: mdlOilSampleLabel) -> mdlOilSampleLabel.Output { | |||
| return mdlOilSampleLabel.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| description: output.description, | |||
| size: output.size, | |||
| offset: output.offset, | |||
| hrez: output.hrez, | |||
| vrez: output.vrez, | |||
| height: output.height, | |||
| quantity: output.quantity, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| labsetting: output.$labsetting.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlOilSampleLabel>.WrappedType, _ input: mdlOilSampleLabel.Input){ | |||
| output.name = input.name; | |||
| output.description = input.description; | |||
| output.size = input.size; | |||
| output.offset = input.offset; | |||
| output.hrez = input.hrez; | |||
| output.vrez = input.vrez; | |||
| output.height = input.height; | |||
| output.quantity = input.quantity; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$labsetting.id = input.labsetting.id! | |||
| } | |||
| func createUnit(_ input: mdlOilSampleLabel.Input) -> mdlOilSampleLabel { | |||
| return mdlOilSampleLabel( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , description: input.description | |||
| , size: input.size | |||
| , offset: input.offset | |||
| , hrez: input.hrez | |||
| , vrez: input.vrez | |||
| , height: input.height | |||
| , quantity: input.quantity | |||
| , createdate: input.createdate | |||
| , createuserid: input.createuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , labsetting: input.labsetting | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlOilSampleLabel>.WrappedType, req: Request) -> EventLoopFuture<mdlOilSampleLabel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlOilSampleLabel.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , size: output.size | |||
| , offset: output.offset | |||
| , hrez: output.hrez | |||
| , vrez: output.vrez | |||
| , height: output.height | |||
| , quantity: output.quantity | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , labsetting: output.labsetting | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlOilSampleLabel, _ req: Request, _ input: mdlOilSampleLabel.Input) -> EventLoopFuture<mdlOilSampleLabel.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlOilSampleLabel.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , size: output.size | |||
| , offset: output.offset | |||
| , hrez: output.hrez | |||
| , vrez: output.vrez | |||
| , height: output.height | |||
| , quantity: output.quantity | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , labsetting: input.labsetting | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension OilSampleLabelCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("oilsamplelabels") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // Part.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class PartCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlPart.Output>{ | |||
| let input = try req.content.decode(mdlPart.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlPart.Output>{ | |||
| let input = try req.content.decode(mdlPart.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<Page<mdlPart.Output>>{ | |||
| 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<mdlPart.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlPart.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension PartCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlPart> { | |||
| let query = mdlPart.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: mdlPart) -> mdlPart.Output { | |||
| return mdlPart.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| number: output.number, | |||
| description: output.description, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlPart>.WrappedType, _ input: mdlPart.Input){ | |||
| output.name = input.name; | |||
| output.number = input.number; | |||
| output.description = input.description; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlPart.Input) -> mdlPart { | |||
| return mdlPart( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , number: input.number | |||
| , description: input.description | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlPart>.WrappedType, req: Request) -> EventLoopFuture<mdlPart.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlPart.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , number: output.number | |||
| , description: output.description | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlPart, _ req: Request, _ input: mdlPart.Input) -> EventLoopFuture<mdlPart.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlPart.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , number: output.number | |||
| , description: output.description | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension PartCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("parts") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // | |||
| // PriorityCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class PriorityCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlPriority.Output>{ | |||
| let input = try req.content.decode(mdlPriority.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlPriority.Output>{ | |||
| let input = try req.content.decode(mdlPriority.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<Page<mdlPriority.Output>>{ | |||
| 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<mdlPriority.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlPriority.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension PriorityCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlPriority> { | |||
| let query = mdlPriority.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: mdlPriority) -> mdlPriority.Output { | |||
| return mdlPriority.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| workorders: output.$workorders.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlPriority>.WrappedType, _ input: mdlPriority.Input){ | |||
| output.name = input.name; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$workorders.value = input.workorders | |||
| } | |||
| func createUnit(_ input: mdlPriority.Input) -> mdlPriority { | |||
| return mdlPriority( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlPriority>.WrappedType, req: Request) -> EventLoopFuture<mdlPriority.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlPriority.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorders: output.workorders | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlPriority, _ req: Request, _ input: mdlPriority.Input) -> EventLoopFuture<mdlPriority.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlPriority.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension PriorityCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("priorities") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| // | |||
| // ProductCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ProductCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlProduct.Output>{ | |||
| let input = try req.content.decode(mdlProduct.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlProduct.Output>{ | |||
| let input = try req.content.decode(mdlProduct.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<Page<mdlProduct.Output>>{ | |||
| 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<mdlProduct.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlProduct.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ProductCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlProduct> { | |||
| let query = mdlProduct.query(on: req.db).with(\.$models).with(\.$templates) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlProduct) -> mdlProduct.Output { | |||
| return mdlProduct.Output( | |||
| id: output.id!, | |||
| code: output.code, | |||
| description: output.description, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| models: output.$models.value!, | |||
| templates: output.$templates.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlProduct>.WrappedType, _ input: mdlProduct.Input){ | |||
| output.code = input.code; | |||
| 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.$models.value = input.models; | |||
| output.$templates.value = input.templates; | |||
| } | |||
| func createUnit(_ input: mdlProduct.Input) -> mdlProduct { | |||
| return mdlProduct( | |||
| id: input.id ?? nil | |||
| , code: input.code | |||
| , description: input.description | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , models: input.models | |||
| , templates: input.templates | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlProduct>.WrappedType, req: Request) -> EventLoopFuture<mdlProduct.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlProduct.Output( | |||
| id: output.id! | |||
| , code: output.code | |||
| , description: output.description | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , models: output.models | |||
| , templates: output.templates | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlProduct, _ req: Request, _ input: mdlProduct.Input) -> EventLoopFuture<mdlProduct.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlProduct.Output( | |||
| id: output.id! | |||
| , code: output.code | |||
| , description: output.description | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , models: input.models | |||
| , templates: input.templates | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ProductCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("products") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // ReasonCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ReasonCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlReason.Output>{ | |||
| let input = try req.content.decode(mdlReason.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlReason.Output>{ | |||
| let input = try req.content.decode(mdlReason.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<Page<mdlReason.Output>>{ | |||
| 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<mdlReason.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlReason.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ReasonCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlReason> { | |||
| let query = mdlReason.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: mdlReason) -> mdlReason.Output { | |||
| return mdlReason.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<mdlReason>.WrappedType, _ input: mdlReason.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: mdlReason.Input) -> mdlReason { | |||
| return mdlReason( | |||
| 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<mdlReason>.WrappedType, req: Request) -> EventLoopFuture<mdlReason.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlReason.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: mdlReason, _ req: Request, _ input: mdlReason.Input) -> EventLoopFuture<mdlReason.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlReason.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 ReasonCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("reasons") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // RepairTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class RepairTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlRepairType.Output>{ | |||
| let input = try req.content.decode(mdlRepairType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlRepairType.Output>{ | |||
| let input = try req.content.decode(mdlRepairType.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<Page<mdlRepairType.Output>>{ | |||
| 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<mdlRepairType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlRepairType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension RepairTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlRepairType> { | |||
| let query = mdlRepairType.query(on: req.db).with(\.$responsetypes) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlRepairType) -> mdlRepairType.Output { | |||
| return mdlRepairType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| color: output.color, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| responsetypes: output.$responsetypes.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlRepairType>.WrappedType, _ input: mdlRepairType.Input){ | |||
| output.name = input.name; | |||
| output.color = input.color; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$responsetypes.value = input.responsetypes! | |||
| } | |||
| func createUnit(_ input: mdlRepairType.Input) -> mdlRepairType { | |||
| return mdlRepairType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , color: input.color | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , responsetypes: input.responsetypes! | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlRepairType>.WrappedType, req: Request) -> EventLoopFuture<mdlRepairType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlRepairType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , color: output.color | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , responsetypes: output.responsetypes | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlRepairType, _ req: Request, _ input: mdlRepairType.Input) -> EventLoopFuture<mdlRepairType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlRepairType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , color: output.color | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , responsetypes: input.responsetypes | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension RepairTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("repairtypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,169 @@ | |||
| // | |||
| // ResponseTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ResponseTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlResponseType.Output>{ | |||
| let input = try req.content.decode(mdlResponseType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlResponseType.Output>{ | |||
| let input = try req.content.decode(mdlResponseType.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<Page<mdlResponseType.Output>>{ | |||
| 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<mdlResponseType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlResponseType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ResponseTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlResponseType> { | |||
| let query = mdlResponseType.query(on: req.db) | |||
| .with(\.$repairtype) | |||
| .with(\.$inspectioncategoryitemresopnsetypes) | |||
| .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: mdlResponseType) -> mdlResponseType.Output { | |||
| return mdlResponseType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| color: output.color, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| repairtype: output.$repairtype.value!, | |||
| items: output.$items.value!, | |||
| inspectioncategoryitemresopnsetypes: output.$inspectioncategoryitemresopnsetypes.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlResponseType>.WrappedType, _ input: mdlResponseType.Input){ | |||
| output.name = input.name; | |||
| output.color = input.color; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$repairtype.id = input.repairtype.id!; | |||
| output.$inspectioncategoryitemresopnsetypes.value = input.inspectioncategoryitemresopnsetypes; | |||
| output.$items.value = input.items | |||
| } | |||
| func createUnit(_ input: mdlResponseType.Input) -> mdlResponseType { | |||
| return mdlResponseType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , color: input.color | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , repairtype: input.repairtype | |||
| , items: input.items | |||
| , inspectioncategoryitemresopnsetypes: input.inspectioncategoryitemresopnsetypes | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlResponseType>.WrappedType, req: Request) -> EventLoopFuture<mdlResponseType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlResponseType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , color: output.color | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , repairtype: output.repairtype | |||
| , items: output.items | |||
| , inspectioncategoryitemresopnsetypes: output.inspectioncategoryitemresopnsetypes | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlResponseType, _ req: Request, _ input: mdlResponseType.Input) -> EventLoopFuture<mdlResponseType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlResponseType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , color: output.color | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , repairtype: input.repairtype | |||
| , items: input.items | |||
| , inspectioncategoryitemresopnsetypes: input.inspectioncategoryitemresopnsetypes | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ResponseTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("responsetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,135 @@ | |||
| // | |||
| // RoleCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/4/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class RoleCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlRole.Output>{ | |||
| let input = try req.content.decode(mdlRole.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlRole.Output>{ | |||
| let input = try req.content.decode(mdlRole.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<Page<mdlRole.Output>>{ | |||
| 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<mdlRole.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlRole.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension RoleCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlRole> { | |||
| let query = mdlRole.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: mdlRole) -> mdlRole.Output { | |||
| return mdlRole.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| description: output.description, | |||
| //createdate: output.createdate, | |||
| //createuserid: output.createuserid, | |||
| //updatedate: output.updatedate, | |||
| //updateuserid: output.updateuserid, | |||
| users: output.$users.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlRole>.WrappedType, _ input: mdlRole.Input){ | |||
| output.name = input.name; | |||
| output.description = input.description; | |||
| output.$users.value = input.users | |||
| } | |||
| func createUnit(_ input: mdlRole.Input) -> mdlRole { | |||
| return mdlRole( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , description: input.name | |||
| , users: input.users | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlRole>.WrappedType, req: Request) -> EventLoopFuture<mdlRole.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlRole.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , users: output.users | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlRole, _ req: Request, _ input: mdlRole.Input) -> EventLoopFuture<mdlRole.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlRole.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , users: input.users | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension RoleCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("roles") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // SignatureCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/12/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class SignatureCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlSignature.Output>{ | |||
| let input = try req.content.decode(mdlSignature.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlSignature.Output>{ | |||
| let input = try req.content.decode(mdlSignature.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<Page<mdlSignature.Output>>{ | |||
| 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<mdlSignature.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlSignature.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension SignatureCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlSignature> { | |||
| let query = mdlSignature.query(on: req.db).with(\.$signaturetype).with(\.$workorder) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlSignature) -> mdlSignature.Output { | |||
| return mdlSignature.Output( | |||
| id: output.id! | |||
| , path: output.path | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.$workorder.value! | |||
| , signaturetype: output.$signaturetype.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlSignature>.WrappedType, _ input: mdlSignature.Input){ | |||
| output.path = input.path; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$workorder.id = input.workorder.id!; | |||
| output.$signaturetype.id = input.signaturetype.id! | |||
| } | |||
| func createUnit(_ input: mdlSignature.Input) -> mdlSignature { | |||
| return mdlSignature( | |||
| id: input.id ?? nil | |||
| , path: input.path | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorder: input.workorder | |||
| , signaturetype: input.signaturetype | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlSignature>.WrappedType, req: Request) -> EventLoopFuture<mdlSignature.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlSignature.Output( | |||
| id: output.id! | |||
| , path: output.path | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: output.workorder | |||
| , signaturetype: output.signaturetype | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlSignature, _ req: Request, _ input: mdlSignature.Input) -> EventLoopFuture<mdlSignature.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlSignature.Output( | |||
| id: output.id! | |||
| , path: output.path | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorder: input.workorder | |||
| , signaturetype: input.signaturetype | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension SignatureCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("signatures") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // | |||
| // SignatureTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class SignatureTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlSignatureType.Output>{ | |||
| let input = try req.content.decode(mdlSignatureType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlSignatureType.Output>{ | |||
| let input = try req.content.decode(mdlSignatureType.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<Page<mdlSignatureType.Output>>{ | |||
| 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<mdlSignatureType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlSignatureType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension SignatureTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlSignatureType> { | |||
| let query = mdlSignatureType.query(on: req.db).with(\.$signatures) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlSignatureType) -> mdlSignatureType.Output { | |||
| return mdlSignatureType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| signatures: output.$signatures.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlSignatureType>.WrappedType, _ input: mdlSignatureType.Input){ | |||
| output.name = input.name; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$signatures.value = input.signatures | |||
| } | |||
| func createUnit(_ input: mdlSignatureType.Input) -> mdlSignatureType { | |||
| return mdlSignatureType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , signatures: input.signatures | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlSignatureType>.WrappedType, req: Request) -> EventLoopFuture<mdlSignatureType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlSignatureType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , signatures: output.signatures | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlSignatureType, _ req: Request, _ input: mdlSignatureType.Input) -> EventLoopFuture<mdlSignatureType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlSignatureType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , signatures: input.signatures | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension SignatureTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("signaturetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,168 @@ | |||
| // | |||
| // SpecCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class SpecCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlSpec.Output>{ | |||
| let input = try req.content.decode(mdlSpec.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlSpec.Output>{ | |||
| let input = try req.content.decode(mdlSpec.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<Page<mdlSpec.Output>>{ | |||
| 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<mdlSpec.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlSpec.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension SpecCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlSpec> { | |||
| let query = mdlSpec.query(on: req.db) | |||
| .with(\.$item) | |||
| .with(\.$specitems) | |||
| .with(\.$templatecategoryitemspecs) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlSpec) -> mdlSpec.Output { | |||
| return mdlSpec.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| numberoftests: output.numberoftests, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| item: output.$item.value!, | |||
| specitems: output.$specitems.value!, | |||
| templatecategoryitemspecs: output.$templatecategoryitemspecs.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlSpec>.WrappedType, _ input: mdlSpec.Input){ | |||
| output.name = input.name; | |||
| output.numberoftests = input.numberoftests; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$item.id = input.item.id!; | |||
| output.$specitems.value = input.specitems!; | |||
| output.$templatecategoryitemspecs.value = input.templatecategoryitemspecs!; | |||
| } | |||
| func createUnit(_ input: mdlSpec.Input) -> mdlSpec { | |||
| return mdlSpec( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , numberoftests: input.numberoftests | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , item: input.item | |||
| , specitems: input.specitems | |||
| , templatecategoryitemspecs: input.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlSpec>.WrappedType, req: Request) -> EventLoopFuture<mdlSpec.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlSpec.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , numberoftests: output.numberoftests | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , item: output.item | |||
| , specitems: output.specitems | |||
| , templatecategoryitemspecs: output.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlSpec, _ req: Request, _ input: mdlSpec.Input) -> EventLoopFuture<mdlSpec.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlSpec.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , numberoftests: output.numberoftests | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , item: input.item | |||
| , specitems: input.specitems | |||
| , templatecategoryitemspecs: input.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension SpecCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("specs") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,174 @@ | |||
| // | |||
| // SpecItemCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class SpecItemCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlSpecItem.Output>{ | |||
| let input = try req.content.decode(mdlSpecItem.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlSpecItem.Output>{ | |||
| let input = try req.content.decode(mdlSpecItem.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<Page<mdlSpecItem.Output>>{ | |||
| 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<mdlSpecItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlSpecItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension SpecItemCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlSpecItem> { | |||
| let query = mdlSpecItem.query(on: req.db) | |||
| .with(\.$spec) | |||
| .with(\.$comparisontype) | |||
| .with(\.$unit) | |||
| //.with(\.$specitemvalues) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlSpecItem) -> mdlSpecItem.Output { | |||
| return mdlSpecItem.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| qualifier: output.qualifier, | |||
| sortorder: output.sortorder, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| spec: output.$spec.value!, | |||
| comparisontype: output.$comparisontype.value!, | |||
| unit: output.$unit.value! | |||
| , specitemvalues: output.specitemvalues | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlSpecItem>.WrappedType, _ input: mdlSpecItem.Input){ | |||
| output.name = input.name; | |||
| output.qualifier = input.qualifier; | |||
| output.sortorder = input.sortorder; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$spec.id = input.spec.id!; | |||
| output.$comparisontype.id = input.comparisontype.id!; | |||
| output.$unit.id = input.unit.id!; | |||
| output.$specitemvalues.value = input.specitemvalues | |||
| } | |||
| func createUnit(_ input: mdlSpecItem.Input) -> mdlSpecItem { | |||
| return mdlSpecItem( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , qualifier: input.qualifier | |||
| , sortorder: input.sortorder | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , spec: input.spec | |||
| , comparisontype: input.comparisontype | |||
| , unit: input.unit | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlSpecItem>.WrappedType, req: Request) -> EventLoopFuture<mdlSpecItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlSpecItem.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , qualifier: output.qualifier | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , spec: output.spec | |||
| , comparisontype: output.comparisontype | |||
| , unit: output.unit | |||
| , specitemvalues: output.specitemvalues | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlSpecItem, _ req: Request, _ input: mdlSpecItem.Input) -> EventLoopFuture<mdlSpecItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlSpecItem.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , qualifier: output.qualifier | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , spec: output.spec | |||
| , comparisontype: input.comparisontype | |||
| , unit: input.unit | |||
| , specitemvalues: input.specitemvalues | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension SpecItemCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("specitems") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // SpecItemValueCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class SpecItemValueCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlSpecItemValue.Output>{ | |||
| let input = try req.content.decode(mdlSpecItemValue.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlSpecItemValue.Output>{ | |||
| let input = try req.content.decode(mdlSpecItemValue.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<Page<mdlSpecItemValue.Output>>{ | |||
| 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<mdlSpecItemValue.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlSpecItemValue.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension SpecItemValueCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlSpecItemValue> { | |||
| let query = mdlSpecItemValue.query(on: req.db).with(\.$specitem).with(\.$valuetype) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlSpecItemValue) -> mdlSpecItemValue.Output { | |||
| return mdlSpecItemValue.Output( | |||
| id: output.id!, | |||
| value: output.value, | |||
| sortorder: output.sortorder, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| specitem: output.$specitem.value!, | |||
| valuetype: output.$valuetype.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlSpecItemValue>.WrappedType, _ input: mdlSpecItemValue.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.$specitem.id = input.specitem.id!; | |||
| output.$valuetype.id = input.valuetype.id! | |||
| } | |||
| func createUnit(_ input: mdlSpecItemValue.Input) -> mdlSpecItemValue { | |||
| return mdlSpecItemValue( | |||
| id: input.id ?? nil | |||
| , value: input.value | |||
| , sortorder: input.sortorder | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , specitem: input.specitem | |||
| , valuetype: input.valuetype | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlSpecItemValue>.WrappedType, req: Request) -> EventLoopFuture<mdlSpecItemValue.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlSpecItemValue.Output( | |||
| id: output.id! | |||
| , value: output.value | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , specitem: output.specitem | |||
| , valuetype: output.valuetype | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlSpecItemValue, _ req: Request, _ input: mdlSpecItemValue.Input) -> EventLoopFuture<mdlSpecItemValue.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlSpecItemValue.Output( | |||
| id: output.id! | |||
| , value: output.value | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , specitem: input.specitem | |||
| , valuetype: input.valuetype | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension SpecItemValueCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("specitemvalues") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // Status Controller | |||
| // StatusCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class StatusCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlStatus.Output>{ | |||
| let input = try req.content.decode(mdlStatus.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlStatus.Output>{ | |||
| let input = try req.content.decode(mdlStatus.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<Page<mdlStatus.Output>>{ | |||
| 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<mdlStatus.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlStatus.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension StatusCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlStatus> { | |||
| let query = mdlStatus.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: mdlStatus) -> mdlStatus.Output { | |||
| return mdlStatus.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| workorders: output.$workorders.value | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlStatus>.WrappedType, _ input: mdlStatus.Input){ | |||
| output.name = input.name; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$workorders.value = input.workorders | |||
| } | |||
| func createUnit(_ input: mdlStatus.Input) -> mdlStatus { | |||
| return mdlStatus( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlStatus>.WrappedType, req: Request) -> EventLoopFuture<mdlStatus.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlStatus.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorders: output.workorders | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlStatus, _ req: Request, _ input: mdlStatus.Input) -> EventLoopFuture<mdlStatus.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlStatus.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , workorders: input.workorders | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension StatusCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("statuses") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,158 @@ | |||
| // | |||
| // TemplateCategoryCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class TemplateCategoryCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlTemplateCategory.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategory.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlTemplateCategory.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategory.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<Page<mdlTemplateCategory.Output>>{ | |||
| 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<mdlTemplateCategory.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlTemplateCategory.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension TemplateCategoryCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlTemplateCategory> { | |||
| let query = mdlTemplateCategory.query(on: req.db) | |||
| .with(\.$template) | |||
| .with(\.$category) | |||
| .with(\.$templatecategoryitems) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlTemplateCategory) -> mdlTemplateCategory.Output { | |||
| return mdlTemplateCategory.Output( | |||
| id: output.id!, | |||
| template: output.$template.value!, | |||
| category: output.$category.value!, | |||
| sortorder: output.sortorder, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| templatecategoryitems: output.$templatecategoryitems.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlTemplateCategory>.WrappedType, _ input: mdlTemplateCategory.Input){ | |||
| output.$template.id = input.template.id!; | |||
| output.$category.id = input.category.id!; | |||
| output.sortorder = input.sortorder; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$templatecategoryitems.value = input.templatecategoryitems! | |||
| } | |||
| func createUnit(_ input: mdlTemplateCategory.Input) -> mdlTemplateCategory { | |||
| return mdlTemplateCategory( | |||
| id: input.id ?? nil | |||
| , template: input.template | |||
| , category: input.category | |||
| , sortorder: input.sortorder | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , templatecategoryitems: input.templatecategoryitems | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlTemplateCategory>.WrappedType, req: Request) -> EventLoopFuture<mdlTemplateCategory.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlTemplateCategory.Output( | |||
| id: output.id! | |||
| , template: output.template | |||
| , category: output.category | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , templatecategoryitems: output.templatecategoryitems | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlTemplateCategory, _ req: Request, _ input: mdlTemplateCategory.Input) -> EventLoopFuture<mdlTemplateCategory.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlTemplateCategory.Output( | |||
| id: output.id! | |||
| , template: input.template | |||
| , category: input.category | |||
| , sortorder: input.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , templatecategoryitems: input.templatecategoryitems | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension TemplateCategoryCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("templatecategories") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,158 @@ | |||
| // | |||
| // TemplateCategoryItemCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class TemplateCategoryItemCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlTemplateCategoryItem.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategoryItem.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlTemplateCategoryItem.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategoryItem.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<Page<mdlTemplateCategoryItem.Output>>{ | |||
| 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<mdlTemplateCategoryItem.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlTemplateCategoryItem.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension TemplateCategoryItemCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlTemplateCategoryItem> { | |||
| let query = mdlTemplateCategoryItem.query(on: req.db) | |||
| .with(\.$templatecategory) | |||
| .with(\.$item) | |||
| .with(\.$templatecategoryitemspecs) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlTemplateCategoryItem) -> mdlTemplateCategoryItem.Output { | |||
| return mdlTemplateCategoryItem.Output( | |||
| id: output.id!, | |||
| templatecategory: output.$templatecategory.value!, | |||
| item: output.$item.value!, | |||
| sortorder: output.sortorder, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| templatecategoryitemspecs: output.$templatecategoryitemspecs.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlTemplateCategoryItem>.WrappedType, _ input: mdlTemplateCategoryItem.Input){ | |||
| output.$templatecategory.id = input.templatecategory.id!; | |||
| output.$item.id = input.item.id!; | |||
| output.sortorder = input.sortorder; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$templatecategoryitemspecs.value = input.templatecategoryitemspecs | |||
| } | |||
| func createUnit(_ input: mdlTemplateCategoryItem.Input) -> mdlTemplateCategoryItem { | |||
| return mdlTemplateCategoryItem( | |||
| id: input.id ?? nil | |||
| , templatecategory: input.templatecategory | |||
| , item: input.item | |||
| , sortorder: input.sortorder | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , templatecategoryitemspecs: input.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlTemplateCategoryItem>.WrappedType, req: Request) -> EventLoopFuture<mdlTemplateCategoryItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlTemplateCategoryItem.Output( | |||
| id: output.id! | |||
| , templatecategory: output.templatecategory | |||
| , item: output.item | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , templatecategoryitemspecs: output.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlTemplateCategoryItem, _ req: Request, _ input: mdlTemplateCategoryItem.Input) -> EventLoopFuture<mdlTemplateCategoryItem.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlTemplateCategoryItem.Output( | |||
| id: output.id! | |||
| , templatecategory: input.templatecategory | |||
| , item: input.item | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , templatecategoryitemspecs: input.templatecategoryitemspecs | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension TemplateCategoryItemCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("templatecategoryitems") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // TemplateCategoryItemSpec.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class TemplateCategoryItemSpecCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlTemplateCategoryItemSpec.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategoryItemSpec.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlTemplateCategoryItemSpec.Output>{ | |||
| let input = try req.content.decode(mdlTemplateCategoryItemSpec.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<Page<mdlTemplateCategoryItemSpec.Output>>{ | |||
| 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<mdlTemplateCategoryItemSpec.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlTemplateCategoryItemSpec.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension TemplateCategoryItemSpecCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlTemplateCategoryItemSpec> { | |||
| let query = mdlTemplateCategoryItemSpec.query(on: req.db).with(\.$templatecategoryitem).with(\.$spec) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlTemplateCategoryItemSpec) -> mdlTemplateCategoryItemSpec.Output { | |||
| return mdlTemplateCategoryItemSpec.Output( | |||
| id: output.id!, | |||
| templatecategoryitem: output.$templatecategoryitem.value!, | |||
| spec: output.$spec.value!, | |||
| sortorder: output.sortorder, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlTemplateCategoryItemSpec>.WrappedType, _ input: mdlTemplateCategoryItemSpec.Input){ | |||
| output.$templatecategoryitem.id = input.templatecategoryitem.id!; | |||
| output.$spec.id = input.spec.id!; | |||
| output.sortorder = input.sortorder; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlTemplateCategoryItemSpec.Input) -> mdlTemplateCategoryItemSpec { | |||
| return mdlTemplateCategoryItemSpec( | |||
| id: input.id ?? nil | |||
| , templatecategoryitem: input.templatecategoryitem | |||
| , spec: input.spec | |||
| , sortorder: input.sortorder | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlTemplateCategoryItemSpec>.WrappedType, req: Request) -> EventLoopFuture<mdlTemplateCategoryItemSpec.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlTemplateCategoryItemSpec.Output( | |||
| id: output.id! | |||
| , templatecategoryitem: output.templatecategoryitem | |||
| , spec: output.spec | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlTemplateCategoryItemSpec, _ req: Request, _ input: mdlTemplateCategoryItemSpec.Input) -> EventLoopFuture<mdlTemplateCategoryItemSpec.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlTemplateCategoryItemSpec.Output( | |||
| id: output.id! | |||
| , templatecategoryitem: input.templatecategoryitem | |||
| , spec: input.spec | |||
| , sortorder: output.sortorder | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension TemplateCategoryItemSpecCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("templatecategoryitemspecs") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,198 @@ | |||
| // | |||
| // TemplateCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class TemplateCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlTemplate.Output>{ | |||
| let input = try req.content.decode(mdlTemplate.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlTemplate.Output>{ | |||
| let input = try req.content.decode(mdlTemplate.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<Page<mdlTemplate.Output>>{ | |||
| 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<mdlTemplate.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlTemplate.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension TemplateCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlTemplate> { | |||
| let query = mdlTemplate.query(on: req.db) | |||
| .with(\.$inspectiontype) | |||
| .with(\.$inspectionlevel) | |||
| .with(\.$customer) | |||
| .with(\.$product) | |||
| .with(\.$make) | |||
| .with(\.$model) | |||
| .with(\.$machine) | |||
| .with(\.$categories) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlTemplate) -> mdlTemplate.Output { | |||
| return mdlTemplate.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, | |||
| inspectiontype: output.$inspectiontype.value!, | |||
| inspectionlevel: output.$inspectionlevel.value!, | |||
| customer: output.$customer.value!, | |||
| product: output.$product.value!, | |||
| make: output.$make.value!, | |||
| model: output.$model.value!, | |||
| machine: output.$machine.value!, | |||
| categories: output.$categories.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlTemplate>.WrappedType, _ input: mdlTemplate.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.$inspectiontype.id = input.inspectiontype.id!; | |||
| output.$inspectionlevel.id = input.inspectionlevel.id!; | |||
| output.$customer.id = input.customer.id!; | |||
| output.$product.id = input.product.id!; | |||
| output.$make.id = input.make.id!; | |||
| output.$model.id = input.model.id!; | |||
| output.$machine.id = input.machine.id!; | |||
| output.$categories.value = input.categories! | |||
| } | |||
| func createUnit(_ input: mdlTemplate.Input) -> mdlTemplate { | |||
| return mdlTemplate( | |||
| 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 | |||
| , inspectiontype: input.inspectiontype | |||
| , inspectionlevel: input.inspectionlevel | |||
| , customer: input.customer | |||
| , product: input.product | |||
| , make: input.make | |||
| , model: input.model | |||
| , machine: input.machine | |||
| , categories: input.categories | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlTemplate>.WrappedType, req: Request) -> EventLoopFuture<mdlTemplate.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlTemplate.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 | |||
| , inspectiontype: output.inspectiontype | |||
| , inspectionlevel: output.inspectionlevel | |||
| , customer: output.customer | |||
| , product: output.product | |||
| , make: output.make | |||
| , model: output.model | |||
| , machine: output.machine | |||
| , categories: output.categories | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlTemplate, _ req: Request, _ input: mdlTemplate.Input) -> EventLoopFuture<mdlTemplate.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlTemplate.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 | |||
| , inspectiontype: input.inspectiontype | |||
| , inspectionlevel: input.inspectionlevel | |||
| , customer: input.customer | |||
| , product: input.product | |||
| , make: input.make | |||
| , model: input.model | |||
| , machine: input.machine | |||
| , categories: input.categories | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension TemplateCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("templates") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,120 @@ | |||
| // | |||
| // UnitCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/2/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class UnitCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlUnit.Output>{ | |||
| let input = try req.content.decode(mdlUnit.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlUnit.Output>{ | |||
| let input = try req.content.decode(mdlUnit.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<Page<mdlUnit.Output>>{ | |||
| 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<mdlUnit.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlUnit.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension UnitCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlUnit> { | |||
| let query = mdlUnit.query(on: req.db).with(\.$datatype).with(\.$locations).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: mdlUnit) -> mdlUnit.Output { | |||
| return mdlUnit.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, | |||
| datatype: output.$datatype.value!, | |||
| locations: output.$locations.value!, | |||
| inspectioncategoryitemspecitems: output.$inspectioncategoryitemspecitems.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlUnit>.WrappedType, _ input: mdlUnit.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.$datatype.id = input.datatype.id! | |||
| } | |||
| func createUnit(_ input: mdlUnit.Input) -> mdlUnit { | |||
| return mdlUnit(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, datatype: input.datatype, locations: input.locations, inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlUnit>.WrappedType, req: Request) -> EventLoopFuture<mdlUnit.Output> { | |||
| return output.save(on: req.db).map{mdlUnit.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, datatype: output.datatype, locations: output.locations, inspectioncategoryitemspecitems: output.inspectioncategoryitemspecitems)} | |||
| } | |||
| //create function | |||
| func save(_ output: mdlUnit, _ req: Request, _ input: mdlUnit.Input) -> EventLoopFuture<mdlUnit.Output> { | |||
| return output.save(on: req.db).map{mdlUnit.Output(id: output.id!, name: input.name, description: input.description, isactive: input.isactive, createdate: input.createdate, createuserid: input.createuserid, updatedate: input.updatedate, updateuserid: input.updateuserid, datatype: input.datatype, locations: input.locations, inspectioncategoryitemspecitems: input.inspectioncategoryitemspecitems)} | |||
| } | |||
| } | |||
| extension UnitCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("units") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,206 @@ | |||
| // | |||
| // UserCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/2/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class UserCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlUser.Output>{ | |||
| let input = try req.content.decode(mdlUser.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlUser.Output>{ | |||
| let input = try req.content.decode(mdlUser.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<Page<mdlUser.Output>>{ | |||
| 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<mdlUser.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlUser.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension UserCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlUser> { | |||
| let query = mdlUser.query(on: req.db) | |||
| .with(\.$division) | |||
| .with(\.$inspections) | |||
| .with(\.$roles) | |||
| .with(\.$modules) | |||
| .with(\.$workorders) | |||
| .with(\.$labsettings) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlUser) -> mdlUser.Output { | |||
| return mdlUser.Output( | |||
| id: output.id!, | |||
| number: output.number, | |||
| firstname: output.firstname, | |||
| lastname: output.lastname, | |||
| username: output.username, | |||
| password: output.password, | |||
| activationcode: output.activationcode, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| division: output.$division.value!, | |||
| inspections: output.$inspections.value!, | |||
| roles: output.$roles.value!, | |||
| modules: output.$modules.value!, | |||
| workorderusers: output.$workorders.value!, | |||
| labsettings: output.$labsettings.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlUser>.WrappedType, _ input: mdlUser.Input){ | |||
| output.number = input.number; | |||
| output.firstname = input.firstname; | |||
| output.lastname = input.lastname; | |||
| output.username = input.username; | |||
| output.password = input.password; | |||
| output.activationcode = input.activationcode; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$division.id = input.division.id!; | |||
| output.$inspections.value = input.inspections; | |||
| output.$roles.value = input.roles; | |||
| output.$modules.value = input.modules; | |||
| output.$workorders.value = input.workorderusers; | |||
| output.$labsettings.value = input.labsettings | |||
| } | |||
| func createUnit(_ input: mdlUser.Input) -> mdlUser { | |||
| return mdlUser( | |||
| id: input.id ?? nil | |||
| , number: input.number | |||
| , firstname: input.firstname | |||
| , lastname: input.lastname | |||
| , username: input.username | |||
| , password: input.password | |||
| , activationcode: input.activationcode | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , division: input.division | |||
| , roles: input.roles | |||
| , modules: input.modules | |||
| , workorderusers: input.workorderusers | |||
| , inspections: input.inspections | |||
| , labsettings: input.labsettings | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlUser>.WrappedType, req: Request) -> EventLoopFuture<mdlUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlUser.Output( | |||
| id: output.id! | |||
| , number: output.number | |||
| , firstname: output.firstname | |||
| , lastname: output.lastname | |||
| , username: output.username | |||
| , password: output.password | |||
| , activationcode: output.activationcode | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , division: output.division | |||
| , inspections: output.inspections | |||
| , roles: output.roles | |||
| , modules: output.modules | |||
| , workorderusers: output.workorders | |||
| , labsettings: output.labsettings | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlUser, _ req: Request, _ input: mdlUser.Input) -> EventLoopFuture<mdlUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlUser.Output( | |||
| id: output.id! | |||
| , number: output.number | |||
| , firstname: output.firstname | |||
| , lastname: output.lastname | |||
| , username: output.username | |||
| , password: output.password | |||
| , activationcode: output.activationcode | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , division: input.division | |||
| , inspections: input.inspections | |||
| , roles: input.roles | |||
| , modules: input.modules | |||
| , workorderusers: input.workorderusers | |||
| , labsettings: input.labsettings | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension UserCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("users") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,161 @@ | |||
| // | |||
| // UserDefinedCodeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| import Network | |||
| final class UserDefinedCodeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlUserDefinedCode.Output>{ | |||
| let input = try req.content.decode(mdlUserDefinedCode.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlUserDefinedCode.Output>{ | |||
| let input = try req.content.decode(mdlUserDefinedCode.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<Page<mdlUserDefinedCode.Output>>{ | |||
| 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<mdlUserDefinedCode.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlUserDefinedCode.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension UserDefinedCodeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlUserDefinedCode> { | |||
| let query = mdlUserDefinedCode.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: mdlUserDefinedCode) -> mdlUserDefinedCode.Output { | |||
| return mdlUserDefinedCode.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!, | |||
| inspectioncategoryitems: output.$inspectioncategoryitems.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlUserDefinedCode>.WrappedType, _ input: mdlUserDefinedCode.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; | |||
| output.$inspectioncategoryitems.value = input.inspectioncategoryitems | |||
| } | |||
| func createUnit(_ input: mdlUserDefinedCode.Input) -> mdlUserDefinedCode { | |||
| return mdlUserDefinedCode( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , desription: input.description | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , items: input.items | |||
| , inspectioncategoryitems: input.inspectioncategoryitems | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlUserDefinedCode>.WrappedType, req: Request) -> EventLoopFuture<mdlUserDefinedCode.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlUserDefinedCode.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 | |||
| , inspectioncategoryitems: output.inspectioncategoryitems | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlUserDefinedCode, _ req: Request, _ input: mdlUserDefinedCode.Input) -> EventLoopFuture<mdlUserDefinedCode.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlUserDefinedCode.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 | |||
| , inspectioncategoryitems: input.inspectioncategoryitems | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension UserDefinedCodeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("userdefinedcodes.svc") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,154 @@ | |||
| // | |||
| // ValueTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ValueTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlValueType.Output>{ | |||
| let input = try req.content.decode(mdlValueType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlValueType.Output>{ | |||
| let input = try req.content.decode(mdlValueType.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<Page<mdlValueType.Output>>{ | |||
| 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<mdlValueType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlValueType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ValueTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlValueType> { | |||
| let query = mdlValueType.query(on: req.db).with(\.$specitemvalues).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: mdlValueType) -> mdlValueType.Output { | |||
| return mdlValueType.Output( | |||
| id: output.id!, | |||
| name: output.name, | |||
| description: output.description, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| specitemvalues: output.$specitemvalues.value!, | |||
| inspectioncategoryitemspecitemvalues: output.$inspectioncategoryitemspecitemvalues.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlValueType>.WrappedType, _ input: mdlValueType.Input){ | |||
| output.name = input.name; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$specitemvalues.value = input.specitemvalues; | |||
| output.$inspectioncategoryitemspecitemvalues.value = input.inspectioncategoryitemspecitemvalues | |||
| } | |||
| func createUnit(_ input: mdlValueType.Input) -> mdlValueType { | |||
| return mdlValueType( | |||
| id: input.id ?? nil | |||
| , name: input.name | |||
| , description: input.description | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , specitemvalues: input.specitemvalues | |||
| , inspectioncategoryitemspecitemvalues: input.inspectioncategoryitemspecitemvalues | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlValueType>.WrappedType, req: Request) -> EventLoopFuture<mdlValueType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlValueType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , specitemvalues: output.specitemvalues | |||
| , inspectioncategoryitemspecitemvalues: output.inspectioncategoryitemspecitemvalues | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlValueType, _ req: Request, _ input: mdlValueType.Input) -> EventLoopFuture<mdlValueType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlValueType.Output( | |||
| id: output.id! | |||
| , name: output.name | |||
| , description: output.description | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , specitemvalues: output.specitemvalues | |||
| , inspectioncategoryitemspecitemvalues: output.inspectioncategoryitemspecitemvalues | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ValueTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("valuetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| // | |||
| // ViscosityCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class ViscosityCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlViscosity.Output>{ | |||
| let input = try req.content.decode(mdlViscosity.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlViscosity.Output>{ | |||
| let input = try req.content.decode(mdlViscosity.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<Page<mdlViscosity.Output>>{ | |||
| 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<mdlViscosity.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlViscosity.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension ViscosityCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlViscosity> { | |||
| let query = mdlViscosity.query(on: req.db).with(\.$fluids) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlViscosity) -> mdlViscosity.Output { | |||
| return mdlViscosity.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, | |||
| fluids: output.$fluids.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlViscosity>.WrappedType, _ input: mdlViscosity.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; | |||
| output.$fluids.value = input.fluids | |||
| } | |||
| func createUnit(_ input: mdlViscosity.Input) -> mdlViscosity { | |||
| return mdlViscosity( | |||
| 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 | |||
| , fluids: input.fluids | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlViscosity>.WrappedType, req: Request) -> EventLoopFuture<mdlViscosity.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlViscosity.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 | |||
| , fluids: output.fluids | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlViscosity, _ req: Request, _ input: mdlViscosity.Input) -> EventLoopFuture<mdlViscosity.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlViscosity.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 | |||
| , fluids: input.fluids | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension ViscosityCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("viscosities") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,266 @@ | |||
| // | |||
| // WorkOrderCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class WorkOrderCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlWorkOrder.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrder.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlWorkOrder.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrder.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<Page<mdlWorkOrder.Output>>{ | |||
| 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<mdlWorkOrder.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlWorkOrder.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension WorkOrderCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlWorkOrder> { | |||
| let query = mdlWorkOrder.query(on: req.db) | |||
| .with(\.$customer) | |||
| .with(\.$machine) | |||
| .with(\.$priority) | |||
| .with(\.$reason) | |||
| .with(\.$incompletereason) | |||
| .with(\.$workorderstatuses) | |||
| .with(\.$userss) | |||
| .with(\.$inspections) | |||
| .with(\.$consumptions) | |||
| .with(\.$notes) | |||
| .with(\.$files) | |||
| .with(\.$signatures) | |||
| .with(\.$parts) | |||
| .with(\.$statuses) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let number: String | |||
| let specialinstruction: String | |||
| let scheduledstartdate: Date | |||
| let scheduledenddate: Date | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let customer: mdlCustomer | |||
| let machine: mdlMachine | |||
| let priority: mdlPriority | |||
| let reason: mdlReason | |||
| let incompletereason: mdlIncompleteReason | |||
| let workorderstatus: [mdlWorkOrder]? | |||
| let users: [mdlWorkOrderUser]? | |||
| let inspections: [mdlInspection]? | |||
| let consumptions: [mdlConsumption]? | |||
| let notes: [mdlNote]? | |||
| let files: [mdlFile]? | |||
| let signatures: [mdlSignature]? | |||
| let parts: [mdlWorkOrderPart]? | |||
| let statuses: [mdlStatus]? | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlWorkOrder) -> mdlWorkOrder.Output { | |||
| return mdlWorkOrder.Output( | |||
| id: output.id! | |||
| , number: output.number | |||
| , specialinstruction: output.specialinstruction | |||
| , scheduledstartdate: output.scheduledstartdate | |||
| , scheduledenddate: output.scheduledenddate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , customer: output.$customer.value! | |||
| , machine: output.$machine.value! | |||
| , priority: output.$priority.value! | |||
| , reason: output.$reason.value! | |||
| , incompletereason: output.$incompletereason.value! | |||
| , workorderstatuses: output.$workorderstatuses.value! | |||
| , users: output.$userss.value! | |||
| , inspections: output.$inspections.value! | |||
| , consumptions: output.$consumptions.value! | |||
| , notes: output.$notes.value! | |||
| , files: output.$files.value! | |||
| , signatures: output.$signatures.value! | |||
| , parts: output.$parts.value! | |||
| , statuses: output.$statuses.value! | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlWorkOrder>.WrappedType, _ input: mdlWorkOrder.Input){ | |||
| output.number = input.number; | |||
| output.specialinstruction = input.specialinstruction; | |||
| output.scheduledstartdate = input.scheduledstartdate; | |||
| output.scheduledenddate = input.scheduledenddate; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.$customer.id = input.customer.id!; | |||
| output.$machine.id = input.machine.id!; | |||
| output.$priority.id = input.priority.id!; | |||
| output.$reason.id = input.reason.id!; | |||
| output.$incompletereason.id = input.incompletereason.id!; | |||
| output.$workorderstatuses.value = input.workorderstatuses!; | |||
| output.$userss.value = input.users!; | |||
| output.$inspections.value = input.inspections!; | |||
| output.$consumptions.value = input.consumptions!; | |||
| output.$notes.value = input.notes!; | |||
| output.$files.value = input.files!; | |||
| output.$signatures.value = input.signatures!; | |||
| output.$parts.value = input.parts!; | |||
| output.$statuses.value = input.statuses!; | |||
| } | |||
| func createUnit(_ input: mdlWorkOrder.Input) -> mdlWorkOrder { | |||
| return mdlWorkOrder( | |||
| id: input.id ?? nil | |||
| , number: input.number | |||
| , specialinstruction: input.specialinstruction | |||
| , scheduledstartdate: input.scheduledstartdate | |||
| , scheduledenddate: input.scheduledenddate | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , customer: input.customer | |||
| , machine: input.machine | |||
| , priority: input.priority | |||
| , reason: input.reason | |||
| , incompletereason: input.incompletereason | |||
| , users: input.users! | |||
| , workorderstatuses: input.workorderstatuses! | |||
| , inspections: input.inspections! | |||
| , consumptions: input.consumptions! | |||
| , notes: input.notes! | |||
| , files: input.files! | |||
| , signatures: input.signatures! | |||
| , parts: input.parts! | |||
| , statuses: input.statuses! | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlWorkOrder>.WrappedType, req: Request) -> EventLoopFuture<mdlWorkOrder.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlWorkOrder.Output( | |||
| id: output.id! | |||
| , number: output.number | |||
| , specialinstruction: output.specialinstruction | |||
| , scheduledstartdate: output.scheduledstartdate | |||
| , scheduledenddate: output.scheduledenddate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , customer: output.$customer.value! | |||
| , machine: output.$machine.value! | |||
| , priority: output.$priority.value! | |||
| , reason: output.$reason.value! | |||
| , incompletereason: output.$incompletereason.value! | |||
| , workorderstatuses: output.$workorderstatuses.value! | |||
| , users: output.$userss.value! | |||
| , inspections: output.$inspections.value! | |||
| , consumptions: output.$consumptions.value! | |||
| , notes: output.$notes.value! | |||
| , files: output.$files.value! | |||
| , signatures: output.$signatures.value! | |||
| , parts: output.$parts.value! | |||
| , statuses: output.$statuses.value! | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlWorkOrder, _ req: Request, _ input: mdlWorkOrder.Input) -> EventLoopFuture<mdlWorkOrder.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlWorkOrder.Output( | |||
| id: output.id! | |||
| , number: output.number | |||
| , specialinstruction: output.specialinstruction | |||
| , scheduledstartdate: output.scheduledstartdate | |||
| , scheduledenddate: output.scheduledenddate | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , customer: input.customer | |||
| , machine: input.machine | |||
| , priority: input.priority | |||
| , reason: input.reason | |||
| , incompletereason: input.incompletereason | |||
| , workorderstatuses: input.workorderstatuses! | |||
| , users: input.users! | |||
| , inspections: input.inspections! | |||
| , consumptions: input.consumptions! | |||
| , notes: input.notes! | |||
| , files: input.files! | |||
| , signatures: input.signatures! | |||
| , parts: input.parts! | |||
| , statuses: input.statuses! | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension WorkOrderCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("workorders") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,155 @@ | |||
| // | |||
| // WorkOrderStatusCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class WorkOrderStatusCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlWorkOrderStatus.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrderStatus.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlWorkOrderStatus.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrderStatus.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<Page<mdlWorkOrderStatus.Output>>{ | |||
| 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<mdlWorkOrderStatus.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlWorkOrderStatus.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension WorkOrderStatusCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlWorkOrderStatus> { | |||
| let query = mdlWorkOrderStatus.query(on: req.db).with(\.$workorder).with(\.$status) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlWorkOrderStatus) -> mdlWorkOrderStatus.Output { | |||
| return mdlWorkOrderStatus.Output( | |||
| id: output.id!, | |||
| workorder: output.$workorder.value!, | |||
| status: output.$status.value!, | |||
| date: output.date!, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlWorkOrderStatus>.WrappedType, _ input: mdlWorkOrderStatus.Input){ | |||
| output.$workorder.id = input.workorder.id!; | |||
| output.$status.id = input.status.id!; | |||
| output.date = input.date; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlWorkOrderStatus.Input) -> mdlWorkOrderStatus { | |||
| return mdlWorkOrderStatus( | |||
| id: input.id ?? nil | |||
| , status: input.status | |||
| , workorder: input.workorder | |||
| , date: input.date | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlWorkOrderStatus>.WrappedType, req: Request) -> EventLoopFuture<mdlWorkOrderStatus.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlWorkOrderStatus.Output( | |||
| id: output.id! | |||
| , workorder: output.workorder | |||
| , status: output.status | |||
| , date: output.date! | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlWorkOrderStatus, _ req: Request, _ input: mdlWorkOrderStatus.Input) -> EventLoopFuture<mdlWorkOrderStatus.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlWorkOrderStatus.Output( | |||
| id: output.id! | |||
| , workorder: input.workorder | |||
| , status: input.status | |||
| , date: output.date! | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension WorkOrderStatusCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("workorderstatuses") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // WorkOrderUserCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class WorkOrderUserCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlWorkOrderUser.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrderUser.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlWorkOrderUser.Output>{ | |||
| let input = try req.content.decode(mdlWorkOrderUser.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<Page<mdlWorkOrderUser.Output>>{ | |||
| 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<mdlWorkOrderUser.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlWorkOrderUser.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension WorkOrderUserCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlWorkOrderUser> { | |||
| let query = mdlWorkOrderUser.query(on: req.db).with(\.$workorder).with(\.$user) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlWorkOrderUser) -> mdlWorkOrderUser.Output { | |||
| return mdlWorkOrderUser.Output( | |||
| id: output.id!, | |||
| user: output.$user.value!, | |||
| workorder: output.$workorder.value!, | |||
| assigned: output.assigned, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlWorkOrderUser>.WrappedType, _ input: mdlWorkOrderUser.Input){ | |||
| output.$user.id = input.user.id!; | |||
| output.$workorder.id = input.workorder.id!; | |||
| output.assigned = input.assigned; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlWorkOrderUser.Input) -> mdlWorkOrderUser { | |||
| return mdlWorkOrderUser( | |||
| id: input.id ?? nil | |||
| , user: input.user | |||
| , workorder: input.workorder | |||
| , assigned: input.assigned | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlWorkOrderUser>.WrappedType, req: Request) -> EventLoopFuture<mdlWorkOrderUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlWorkOrderUser.Output( | |||
| id: output.id! | |||
| , user: output.user | |||
| , workorder: output.workorder | |||
| , assigned: output.assigned | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlWorkOrderUser, _ req: Request, _ input: mdlWorkOrderUser.Input) -> EventLoopFuture<mdlWorkOrderUser.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlWorkOrderUser.Output( | |||
| id: output.id! | |||
| , user: input.user | |||
| , workorder: input.workorder | |||
| , assigned: output.assigned | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension WorkOrderUserCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("workorderusers") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // XCustomerMachineCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class XCustomerMachineCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlXCustomerMachine.Output>{ | |||
| let input = try req.content.decode(mdlXCustomerMachine.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlXCustomerMachine.Output>{ | |||
| let input = try req.content.decode(mdlXCustomerMachine.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<Page<mdlXCustomerMachine.Output>>{ | |||
| 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<mdlXCustomerMachine.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlXCustomerMachine.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension XCustomerMachineCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlXCustomerMachine> { | |||
| let query = mdlXCustomerMachine.query(on: req.db).with(\.$customer).with(\.$machine) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlXCustomerMachine) -> mdlXCustomerMachine.Output { | |||
| return mdlXCustomerMachine.Output( | |||
| id: output.id!, | |||
| customer: output.$customer.value!, | |||
| machine: output.$machine.value!, | |||
| createdate: output.createdate, | |||
| isactive: output.isactive, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlXCustomerMachine>.WrappedType, _ input: mdlXCustomerMachine.Input){ | |||
| output.$customer.id = input.customer.id!; | |||
| output.$machine.id = input.machine.id! | |||
| output.createdate = input.createdate; | |||
| output.isactive = input.isactive; | |||
| output.createuserid = input.createuserid; | |||
| output.updatedate = input.updatedate; | |||
| output.updateuserid = input.updateuserid | |||
| } | |||
| func createUnit(_ input: mdlXCustomerMachine.Input) -> mdlXCustomerMachine { | |||
| return mdlXCustomerMachine( | |||
| id: input.id ?? nil | |||
| , customer: input.customer | |||
| , machine: input.machine | |||
| , createuserid: input.createuserid ?? -1 | |||
| , isactive: input.isactive | |||
| , createdate: input.createdate | |||
| , updatedate: input.updatedate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlXCustomerMachine>.WrappedType, req: Request) -> EventLoopFuture<mdlXCustomerMachine.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlXCustomerMachine.Output( | |||
| id: output.id! | |||
| , customer: output.customer | |||
| , machine: output.machine | |||
| , createdate: output.createdate | |||
| , isactive: output.isactive | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlXCustomerMachine, _ req: Request, _ input: mdlXCustomerMachine.Input) -> EventLoopFuture<mdlXCustomerMachine.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlXCustomerMachine.Output( | |||
| id: output.id! | |||
| , customer: output.customer | |||
| , machine: output.machine | |||
| , createdate: output.createdate | |||
| , isactive: output.isactive | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension XCustomerMachineCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("xcustomermachines") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,151 @@ | |||
| // | |||
| // XFluidViscosityCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/10/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class XFluidViscosityCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlXFluidViscosity.Output>{ | |||
| let input = try req.content.decode(mdlXFluidViscosity.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlXFluidViscosity.Output>{ | |||
| let input = try req.content.decode(mdlXFluidViscosity.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<Page<mdlXFluidViscosity.Output>>{ | |||
| 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<mdlXFluidViscosity.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlXFluidViscosity.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension XFluidViscosityCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlXFluidViscosity> { | |||
| let query = mdlXFluidViscosity.query(on: req.db).with(\.$fluid).with(\.$viscosity) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlXFluidViscosity) -> mdlXFluidViscosity.Output { | |||
| return mdlXFluidViscosity.Output( | |||
| id: output.id!, | |||
| fluid: output.$fluid.value!, | |||
| viscosity: output.$viscosity.value!, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid, | |||
| sortorder: output.sortorder | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlXFluidViscosity>.WrappedType, _ input: mdlXFluidViscosity.Input){ | |||
| output.$fluid.id = input.fluid.id!; | |||
| output.$viscosity.id = input.viscosity.id!; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| output.sortorder = input.sortorder | |||
| } | |||
| func createUnit(_ input: mdlXFluidViscosity.Input) -> mdlXFluidViscosity { | |||
| return mdlXFluidViscosity( | |||
| id: input.id ?? nil | |||
| , fluid: input.fluid | |||
| , viscosity: input.viscosity | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| , sortorder: input.sortorder | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlXFluidViscosity>.WrappedType, req: Request) -> EventLoopFuture<mdlXFluidViscosity.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlXFluidViscosity.Output( | |||
| id: output.id! | |||
| , fluid: output.fluid | |||
| , viscosity: output.viscosity | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , sortorder: output.sortorder | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlXFluidViscosity, _ req: Request, _ input: mdlXFluidViscosity.Input) -> EventLoopFuture<mdlXFluidViscosity.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlXFluidViscosity.Output( | |||
| id: output.id! | |||
| , fluid: input.fluid | |||
| , viscosity: input.viscosity | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| , sortorder: output.sortorder | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension XFluidViscosityCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("xfluidviscosities") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| // | |||
| // XItemResponseTypeCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/9/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class XItemResponseTypeCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlXItemResponseType.Output>{ | |||
| let input = try req.content.decode(mdlXItemResponseType.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlXItemResponseType.Output>{ | |||
| let input = try req.content.decode(mdlXItemResponseType.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<Page<mdlXItemResponseType.Output>>{ | |||
| 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<mdlXItemResponseType.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlXItemResponseType.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension XItemResponseTypeCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlXItemResponseType> { | |||
| let query = mdlXItemResponseType.query(on: req.db).with(\.$item).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: mdlXItemResponseType) -> mdlXItemResponseType.Output { | |||
| return mdlXItemResponseType.Output( | |||
| id: output.id!, | |||
| item: output.$item.value!, | |||
| responsetype: output.$responsetype.value!, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlXItemResponseType>.WrappedType, _ input: mdlXItemResponseType.Input){ | |||
| output.$item.id = input.item.id!; | |||
| output.$responsetype.id = input.responsetype.id!; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlXItemResponseType.Input) -> mdlXItemResponseType { | |||
| return mdlXItemResponseType( | |||
| id: input.id ?? nil | |||
| , item: input.item | |||
| , responsetype: input.responsetype | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlXItemResponseType>.WrappedType, req: Request) -> EventLoopFuture<mdlXItemResponseType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlXItemResponseType.Output( | |||
| id: output.id! | |||
| , item: output.item | |||
| , responsetype: output.responsetype | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlXItemResponseType, _ req: Request, _ input: mdlXItemResponseType.Input) -> EventLoopFuture<mdlXItemResponseType.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlXItemResponseType.Output( | |||
| id: output.id! | |||
| , item: input.item | |||
| , responsetype: input.responsetype | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension XItemResponseTypeCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("xitemresponsetypes") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,150 @@ | |||
| // | |||
| // XUserModuleCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/5/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class XUserModuleCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlXUserModule.Output>{ | |||
| let input = try req.content.decode(mdlXUserModule.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlXUserModule.Output>{ | |||
| let input = try req.content.decode(mdlXUserModule.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<Page<mdlXUserModule.Output>>{ | |||
| 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<mdlXUserModule.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlXUserModule.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension XUserModuleCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlXUserModule> { | |||
| let query = mdlXUserModule.query(on: req.db).with(\.$user).with(\.$module) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlXUserModule) -> mdlXUserModule.Output { | |||
| return mdlXUserModule.Output( | |||
| id: output.id!, | |||
| user: output.$user.value!, | |||
| module: output.$module.value!, | |||
| isactive: output.isactive, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlXUserModule>.WrappedType, _ input: mdlXUserModule.Input){ | |||
| output.$user.id = input.user.id!; | |||
| output.$module.id = input.module.id!; | |||
| output.isactive = input.isactive; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlXUserModule.Input) -> mdlXUserModule { | |||
| return mdlXUserModule( | |||
| id: input.id ?? nil | |||
| , user: input.user | |||
| , module: input.module | |||
| , isactive: input.isactive | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlXUserModule>.WrappedType, req: Request) -> EventLoopFuture<mdlXUserModule.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlXUserModule.Output( | |||
| id: output.id! | |||
| , user: output.$user.value! | |||
| , module: output.$module.value! | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlXUserModule, _ req: Request, _ input: mdlXUserModule.Input) -> EventLoopFuture<mdlXUserModule.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlXUserModule.Output( | |||
| id: output.id! | |||
| , user: input.user | |||
| , module: input.module | |||
| , isactive: output.isactive | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension XUserModuleCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("xusermodules") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,144 @@ | |||
| // | |||
| // XUserRoleCtrl.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/4/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class XUserRoleCtrl{ | |||
| //Create Unit | |||
| func create(req: Request) throws -> EventLoopFuture<mdlXUserRole.Output>{ | |||
| let input = try req.content.decode(mdlXUserRole.Input.self) | |||
| let output = self.createUnit(input) | |||
| return self.save(output, req, input) | |||
| } | |||
| //TODO Create a method to update linked objects | |||
| //Update Unit | |||
| func update(req: Request) throws -> EventLoopFuture<mdlXUserRole.Output>{ | |||
| let input = try req.content.decode(mdlXUserRole.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<Page<mdlXUserRole.Output>>{ | |||
| 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<mdlXUserRole.Output>{ | |||
| return try qbase(req: req).first().unwrap(or: Abort(.internalServerError)).map{self.createRead($0)} | |||
| } | |||
| //Delete 1 Division | |||
| func delete(req: Request) throws -> EventLoopFuture<HTTPStatus>{ | |||
| guard let id = req.parameters.get("id", as: Int.self) else{ | |||
| throw Abort(.badRequest) | |||
| } | |||
| return mdlXUserRole.find(id, on: req.db).unwrap(or: Abort(.notFound)).flatMap{ $0.delete(on: req.db)}.map{.ok} | |||
| } | |||
| } | |||
| extension XUserRoleCtrl{ | |||
| //Query Settings | |||
| func qbase(req: Request) throws -> QueryBuilder<mdlXUserRole> { | |||
| let query = mdlXUserRole.query(on: req.db).with(\.$user).with(\.$role) | |||
| if let id = req.parameters.get("id", as: Int.self){ | |||
| return query.filter(\.$id == id) | |||
| } else{ | |||
| return query | |||
| } | |||
| } | |||
| //create Output | |||
| func createRead(_ output: mdlXUserRole) -> mdlXUserRole.Output { | |||
| return mdlXUserRole.Output( | |||
| id: output.id!, | |||
| user: output.$user.value!, | |||
| role: output.$role.value!, | |||
| createdate: output.createdate, | |||
| createuserid: output.createuserid, | |||
| updatedate: output.updatedate, | |||
| updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| func mapOutput(_ output: Optional<mdlXUserRole>.WrappedType, _ input: mdlXUserRole.Input){ | |||
| output.$user.id = input.user.id!; | |||
| output.$role.id = input.role.id!; | |||
| output.createdate = input.createdate; | |||
| output.updatedate = input.updatedate; | |||
| output.createuserid = input.createuserid; | |||
| output.updateuserid = input.updateuserid; | |||
| } | |||
| func createUnit(_ input: mdlXUserRole.Input) -> mdlXUserRole { | |||
| return mdlXUserRole( | |||
| id: input.id ?? nil | |||
| , user: input.user | |||
| , role: input.role | |||
| , createuserid: input.createuserid ?? -1 | |||
| , createdate: input.createdate | |||
| , updateuserid: input.updateuserid ?? -1 | |||
| , updatedate: input.updatedate | |||
| ) | |||
| } | |||
| //update function | |||
| func save(_ output: Optional<mdlXUserRole>.WrappedType, req: Request) -> EventLoopFuture<mdlXUserRole.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{mdlXUserRole.Output( | |||
| id: output.id! | |||
| , user: output.user | |||
| , role: output.role | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| //create function | |||
| func save(_ output: mdlXUserRole, _ req: Request, _ input: mdlXUserRole.Input) -> EventLoopFuture<mdlXUserRole.Output> { | |||
| return output | |||
| .save(on: req.db) | |||
| .map{ | |||
| mdlXUserRole.Output( | |||
| id: output.id! | |||
| , user: input.user | |||
| , role: input.role | |||
| , createdate: output.createdate | |||
| , createuserid: output.createuserid | |||
| , updatedate: output.updatedate | |||
| , updateuserid: output.updateuserid | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| extension XUserRoleCtrl: RouteCollection{ | |||
| func boot(routes: RoutesBuilder) throws{ | |||
| let apigroup = routes.grouped("xuserroles") | |||
| apigroup.get("", use: readAll) | |||
| apigroup.get(":id", use: read) | |||
| apigroup.post("", use: create) | |||
| apigroup.post(":id", use: update) | |||
| apigroup.delete(":id", use: delete) | |||
| } | |||
| } | |||
| @@ -0,0 +1,89 @@ | |||
| # Table creation order | |||
| #001. DataType | |||
| #002. Unit | |||
| #003. Division | |||
| #004. LabSetting | |||
| #005. Location | |||
| #006. Gate | |||
| #007. Customer | |||
| #008. User | |||
| #009. Role | |||
| #010. XUserRole | |||
| #011. InputType | |||
| #012. ComparisonType | |||
| #013. Compartment | |||
| #014. CompartmentGroup | |||
| #015. CompartmentLocation | |||
| #016. IncompleteReason | |||
| #017. JobSite | |||
| #018. Level | |||
| #019. License | |||
| #020. NoteType | |||
| #021. Priority | |||
| #022. Reason | |||
| #023. RepairType | |||
| #024. SignatureType | |||
| #025. Status | |||
| #026. ValueType | |||
| #027. Module | |||
| #028. ContactType | |||
| #029. Contact -- Parents(Customer<optional> Location<optional> Equipment<optional> WorkOrder<optional>) --Children(ContactMethods) | |||
| #030. Product Children(Model) | |||
| #031. Make Children(Model) | |||
| #032. Model -- Parents(Product Make) -- Children(Equipment) | |||
| #033. MachineType replaces EquipmentType | |||
| #034. Machine //Replaces Equipment | |||
| #035. MachineNumber (This is for serialized numbers) | |||
| #036. MachineMeter (allowd for multiple meter readings) | |||
| #037. XCustomerMachine | |||
| #038. ResponseType | |||
| #039. UserDefinedCode replaces SMSCCode | |||
| #040. Category | |||
| #041. Item | |||
| #042. XItemResponseType replaces ItemResponseType | |||
| #043. Spec | |||
| #044. SpecItem | |||
| #045. SpecItemValue | |||
| #046. Fluid | |||
| #047. Viscosity | |||
| #048. XFluidViscosity | |||
| #049. XUserModule | |||
| #050. InspectionType | |||
| #051. InspectionLevel | |||
| #052. Part | |||
| #053. Template | |||
| #054. TemplateCategory | |||
| #055. TemplateCategoryItem was TemplateItemSpec | |||
| #056. TemplateCategoryItemSpec new table | |||
| #057. WorkOrder | |||
| #058. WorkOrderStatus | |||
| #059. WorkOrderUser | |||
| #060. Inspection | |||
| #061. InspectionCategory | |||
| #062. InspectionCategoryItem was InspectionItem | |||
| #063. InspectionCategoryItemResponseType was InspectionItemResponseType | |||
| #064. InspectionCategoryItemSpec was InspectionItemSpec | |||
| #065. InspectionCategoryItemSpecItem was InspectionItemSpecItem | |||
| #066. InspectionCategoryItemSpecItemTest was InspectionItemSpecItemTest | |||
| #067. InspectionCategoryItemSpecItemValue was InspectionItemSpecItemValue | |||
| #068. OilSample | |||
| #069. OilSampleItem | |||
| #070. OilSampleLabel | |||
| #071. CPCLCommand | |||
| #072. CPCLCommandOrder | |||
| #073. CPCLCommandFieldName | |||
| #074. CPCLCommandParameter | |||
| #075. CPCLCommandParameterValue | |||
| #076. Consumption | |||
| #077. ConsumptionItem | |||
| @@ -0,0 +1,120 @@ | |||
| // | |||
| // File.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/2/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCPCLTemplate: Model, Content{ | |||
| static let schema = "CPCLTemplate" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| //@Parent(key: "userId") var user: mdlUser | |||
| @Parent(key: "oilSampleLabelId") var oilsamplelabel: mdlOilSampleLabel | |||
| @Children(for: \.$cpcltemplate) var commands: [mdlCPCLTemplateCommand] | |||
| init(){} | |||
| init(id: Int?){ | |||
| self.id = id | |||
| self.isactive = true | |||
| self.createuserid = -1 | |||
| self.updateuserid = -1 | |||
| self.$oilsamplelabel.id = -1 | |||
| } | |||
| init(name: String){ | |||
| self.name = name | |||
| self.isactive = true | |||
| self.createuserid = -1 | |||
| self.updateuserid = -1 | |||
| self.$oilsamplelabel.id = mdlOilSampleLabel(id: 1).id! | |||
| } | |||
| init(id: Int? = nil, name: String, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, oilsamplelabel: mdlOilSampleLabel, commands: [mdlCPCLTemplateCommand]?){ | |||
| self.id = id | |||
| self.name = name | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$oilsamplelabel.id = oilsamplelabel.id! | |||
| } | |||
| } | |||
| extension mdlCPCLTemplate { | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let oilsamplelabel: mdlOilSampleLabel | |||
| let commands: [mdlCPCLTemplateCommand]? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let oilsamplelabel: mdlOilSampleLabel | |||
| let commands: [mdlCPCLTemplateCommand]? | |||
| } | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("CPCLTemplate") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("isActive", .bool) | |||
| .field("oilSampleLabelId", .int, .required, .references("OilSampleLabel", "id")) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("CPCLTemplate").delete() | |||
| } | |||
| } | |||
| // Uncomment if you need to seed the table. | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [mdlCPCLTemplate] = [ | |||
| .init(name: "Default") | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| mdlCPCLTemplate.query(on: database).delete() | |||
| } | |||
| } | |||
| // | |||
| } | |||
| @@ -0,0 +1,167 @@ | |||
| // | |||
| // File.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 11/2/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCPCLTemplateCommand: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let cmd: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let cpcltemplate: mdlCPCLTemplate | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let cmd: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let cpcltemplate: mdlCPCLTemplate | |||
| } | |||
| static let schema = "CPCLTemplateCommand" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "cmd") var cmd: String | |||
| @Field(key: "sortOrder") var sortorder: Int | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Parent(key: "cpclTemplateId") var cpcltemplate: mdlCPCLTemplate | |||
| init(){} | |||
| init(cmd: String, sortorder: Int){ | |||
| self.cmd = cmd | |||
| self.sortorder = sortorder | |||
| self.isactive = true | |||
| self.createuserid = -1 | |||
| self.updateuserid = -1 | |||
| self.$cpcltemplate.id = mdlCPCLTemplate(id: 1).id! | |||
| } | |||
| init(id: Int? = nil, cmd: String, sortorder: Int, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, cpcltemplate: mdlCPCLTemplate){ | |||
| self.id = id | |||
| self.cmd = cmd | |||
| self.sortorder = sortorder | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$cpcltemplate.id = cpcltemplate.id! | |||
| } | |||
| } | |||
| extension mdlCPCLTemplateCommand { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("CPCLTemplateCommand") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("cmd", .string) | |||
| .field("sortOrder", .int) | |||
| .field("isActive", .bool) | |||
| .field("cpclTemplateId", .int, .required, .references("CPCLTemplate", "id")) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("CPCLTemplateCommand").delete() | |||
| } | |||
| } | |||
| //* Uncomment if you need to seed the table. | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [mdlCPCLTemplateCommand] = [ | |||
| .init(cmd: "! 0 200 200 600 1 \r\n", sortorder: 1), | |||
| .init(cmd: "VB PDF-417 34 100 XD 3 YD 5 C 3 S 2 PDF Data \r\n", sortorder: 2), | |||
| .init(cmd: "[Dealer Code]|[Serial Number]|[Unit]|[Make]|[Jobsite]|[Model]|[]|[Compartment]|[]|[Meter Reading]|[Hours on Oil]|[Fluid Brand]|[Fluid Viscosity]|[Fluid Changed]|[Filter Changed]|[Oil Added Unit]|[Oil Added]|[Work Order Number]|[Oil Sample Date Barcode]|[Comment]|[Compartment Code]|\r\n", sortorder: 3), | |||
| .init(cmd: "ENDPDF \r\n", sortorder: 4), | |||
| .init(cmd: "T 0 0 215 500 Comment\r\n", sortorder: 5), | |||
| .init(cmd: "L 215 495 700 495 1 \r\n", sortorder: 6), | |||
| .init(cmd: "T 5 0 215 474 [Comment]\r\n", sortorder: 7), | |||
| .init(cmd: "T 0 0 215 390 Oil Brand\r\n", sortorder: 8), | |||
| .init(cmd: "L 215 385 447 385 1 \r\n", sortorder: 9), | |||
| .init(cmd: "T 5 0 215 364 [Fluid Brand]\r\n", sortorder: 10), | |||
| .init(cmd: "T 0 0 538 390 Oil Weight\r\n", sortorder: 11), | |||
| .init(cmd: "L 538 385 700 385 1 \r\n", sortorder: 12), | |||
| .init(cmd: "T 5 0 538 364 [Fluid Viscosity]\r\n", sortorder: 13), | |||
| .init(cmd: "T 0 0 468 335 Level\r\n", sortorder: 14), | |||
| .init(cmd: "L 468 330 700 330 1 \r\n", sortorder: 15), | |||
| .init(cmd: "T 5 0 468 309 [Level]\r\n", sortorder: 16), | |||
| .init(cmd: "T 0 0 215 335 Oil Added\r\n", sortorder: 17), | |||
| .init(cmd: "L 215 330 447 330 1 \r\n", sortorder: 18), | |||
| .init(cmd: "T 5 0 215 309 [Oil Added] [Oil Added Unit]\r\n", sortorder: 19), | |||
| .init(cmd: "T 0 0 215 445 Oil Chgd\r\n", sortorder: 20), | |||
| .init(cmd: "L 215 440 447 440 1 \r\n", sortorder: 21), | |||
| .init(cmd: "T 5 0 215 419 [Oil Changed]\r\n", sortorder: 22), | |||
| .init(cmd: "T 0 0 468 445 Filter Chgd\r\n", sortorder: 23), | |||
| .init(cmd: "L 468 440 700 440 1 \r\n", sortorder: 24), | |||
| .init(cmd: "T 5 0 468 419 [Filter Changed]\r\n", sortorder: 25), | |||
| .init(cmd: "T 0 0 215 225 Mtr Reading\r\n", sortorder: 26), | |||
| .init(cmd: "L 215 220 447 220 1 \r\n", sortorder: 27), | |||
| .init(cmd: "T 5 0 215 199 [Meter Reading]\r\n", sortorder: 28), | |||
| .init(cmd: "T 0 0 215 280 Hrs on Oil\r\n", sortorder: 29), | |||
| .init(cmd: "L 215 275 447 275 1 \r\n", sortorder: 30), | |||
| .init(cmd: "T 5 0 215 254 [Hours on Oil]\r\n", sortorder: 31), | |||
| .init(cmd: "T 0 0 215 170 Unit No\r\n", sortorder: 32), | |||
| .init(cmd: "L 215 165 447 165 1 \r\n", sortorder: 33), | |||
| .init(cmd: "T 5 0 215 144 [Unit]\r\n", sortorder: 34), | |||
| .init(cmd: "T 0 0 468 170 Serial No\r\n", sortorder: 35), | |||
| .init(cmd: "L 468 165 700 165 1 \r\n", sortorder: 36), | |||
| .init(cmd: "T 5 0 468 144 [Serial Number]\r\n", sortorder: 37), | |||
| .init(cmd: "T 0 0 468 115 Model\r\n", sortorder: 38), | |||
| .init(cmd: "L 468 110 700 110 1 \r\n", sortorder: 39), | |||
| .init(cmd: "T 5 0 468 89 [Model]\r\n", sortorder: 40), | |||
| .init(cmd: "T 0 0 215 115 Make\r\n", sortorder: 41), | |||
| .init(cmd: "L 215 110 447 110 1 \r\n", sortorder: 42), | |||
| .init(cmd: "T 5 0 215 89 [Make]\r\n", sortorder: 43), | |||
| .init(cmd: "T 0 0 215 60 Sample Taken From\r\n", sortorder: 44), | |||
| .init(cmd: "L 215 55 700 55 1 \r\n", sortorder: 45), | |||
| .init(cmd: "T 5 0 215 34 [Compartment]\r\n", sortorder: 46), | |||
| .init(cmd: "T 0 0 468 225 Sample Date\r\n", sortorder: 47), | |||
| .init(cmd: "L 468 220 700 220 1 \r\n", sortorder: 48), | |||
| .init(cmd: "T 5 0 468 199 [Oil Sample Date Label]\r\n", sortorder: 49), | |||
| .init(cmd: "T 5 0 15 5 [Customer]\r\n", sortorder: 50), | |||
| .init(cmd: "T 5 0 600 5 [Work Order Number]\r\n", sortorder: 51), | |||
| .init(cmd: "FORM \r\n", sortorder: 52), | |||
| .init(cmd: "PRINT \r\n", sortorder: 53) | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| mdlCPCLTemplateCommand.query(on: database).delete() | |||
| } | |||
| } | |||
| // | |||
| } | |||
| @@ -0,0 +1,108 @@ | |||
| // | |||
| // Category.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/26/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCategory: Model, Content{ | |||
| static let schema = "Category" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Children(for: \.$category) var items: [mdlItem] | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, items: [mdlItem]?){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$items.value = items | |||
| } | |||
| } | |||
| extension mdlCategory{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let items: [mdlItem]? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let items: [mdlItem]? | |||
| } | |||
| } | |||
| extension mdlCategory { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("Category") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("isActive", .bool) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("Category").delete() | |||
| } | |||
| } | |||
| /* Uncomment if you need to seed the table. | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [<#Model#>] = [ | |||
| <#init#> | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| <#Model#>.query(on: database).delete() | |||
| } | |||
| } | |||
| */ | |||
| } | |||
| @@ -0,0 +1,113 @@ | |||
| // | |||
| // ComparisonType.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlComparisonType: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let specitems: [mdlSpecItem]? | |||
| let inspectioncategoryitemspecitems: [mdlInspectionCategoryItemSpecItem]? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let specitems: [mdlSpecItem]? | |||
| let inspectioncategoryitemspecitems: [mdlInspectionCategoryItemSpecItem]? | |||
| } | |||
| static let schema = "ComparisonType" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Children(for: \.$comparisontype) var specitems: [mdlSpecItem] | |||
| @Children(for: \.$comparisontype) var inspectioncategoryitemspecitems: [mdlInspectionCategoryItemSpecItem] | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, specitems: [mdlSpecItem]?, inspectioncategoryitemspecitems: [mdlInspectionCategoryItemSpecItem]?){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$specitems.value = specitems | |||
| self.$inspectioncategoryitemspecitems.value = inspectioncategoryitemspecitems | |||
| } | |||
| //Seeding | |||
| init(name: String, description: String, createuserid: Int? = -1, updateuserid: Int? = -1){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| } | |||
| } | |||
| extension mdlComparisonType { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("ComparisonType") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("ComparisonType").delete() | |||
| } | |||
| } | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [mdlComparisonType] = [ | |||
| .init(name: "Range", description: "must be between a maximum and minimum", createuserid: -1, updateuserid: -1), | |||
| .init(name: "Min", description: "must be greater than or equal", createuserid: -1, updateuserid: -1), | |||
| .init(name: "Max", description: "must be less than or equal", createuserid: -1, updateuserid: -1), | |||
| .init(name: "Equals", description: "must be equal", createuserid: -1, updateuserid: -1), | |||
| .init(name: "Variance", description: "must be between the base plus or minus a variance", createuserid: -1, updateuserid: -1) | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| mdlComparisonType.query(on: database).delete() | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,89 @@ | |||
| // | |||
| // Compartment.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCompartment: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let code: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let code: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| static let schema = "Compartment" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "code") var code: String | |||
| @Field(key: "sortOrder") var sortorder: Int | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, code: String, sortorder: Int, isactive: Bool = true, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.code = code | |||
| self.sortorder = sortorder | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| } | |||
| } | |||
| extension mdlCompartment { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("Compartment") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("code", .string) | |||
| .field("sortOrder", .int) | |||
| .field("isActive", .bool) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("Compartment").delete() | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,85 @@ | |||
| // | |||
| // CompartmentGroup.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCompartmentGroup: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| static let schema = "CompartmentGroup" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "sortOrder") var sortorder: Int | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, sortorder: Int, isactive: Bool = true, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.sortorder = sortorder | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| } | |||
| } | |||
| extension mdlCompartmentGroup { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("CompartmentGroup") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("sortOrder", .int) | |||
| .field("isActive", .int) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("CompartmentGroup").delete() | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,89 @@ | |||
| // | |||
| // File.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlCompartmentLocation: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let code: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let code: String | |||
| let sortorder: Int | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| } | |||
| static let schema = "CompartmentLocation" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "code") var code: String | |||
| @Field(key: "sortOrder") var sortorder: Int | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, code: String, sortorder: Int, isactive: Bool = true, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.code = code | |||
| self.sortorder = sortorder | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| } | |||
| } | |||
| extension mdlCompartmentLocation { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("CompartmentLocation") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("code", .string) | |||
| .field("sortOrder", .int) | |||
| .field("isActive", .bool) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("CompartmentLocation").delete() | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,57 @@ | |||
| // | |||
| // File.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/29/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlConsumption: Model, Content{ | |||
| struct input{ | |||
| let id: Int? | |||
| let segment: String | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let consumptionitems: [mdlConsumption] | |||
| } | |||
| struct output{ | |||
| let id: Int? | |||
| let segment: String | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let consumptionitems: [mdlConsumption] | |||
| } | |||
| static let schema = "Consumption" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "segment") var segment: String | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Parent(key: "workOrderId") var workorder: mdlWorkOrder | |||
| @Children(for: \.$consumption) var consumptionitems: [mdlConsumptionItem] | |||
| init(){} | |||
| init(id: Int? = nil, segment: String, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, workorder: mdlWorkOrder, consumptionitems: [mdlConsumptionItem] ){ | |||
| self.id = id | |||
| self.segment = segment | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$workorder.id = workorder.id! | |||
| self.$consumptionitems.value = consumptionitems | |||
| } | |||
| } | |||
| @@ -0,0 +1,77 @@ | |||
| // | |||
| // File.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/29/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlConsumptionItem: Model, Content{ | |||
| struct input{ | |||
| let id: Int? | |||
| let fluidname: String | |||
| let viscosityname: String | |||
| let quantity: Int | |||
| let sortorder: Int | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let consumption: mdlConsumption | |||
| } | |||
| struct output{ | |||
| let id: Int? | |||
| let fluidname: String | |||
| let viscosityname: String | |||
| let quantity: Int | |||
| let sortorder: Int | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let consumption: mdlConsumption | |||
| } | |||
| static let schema = "ConsumptionItem" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "fluidName") var fluidname: String | |||
| @Field(key: "viscosityName") var viscosityname: String | |||
| @Field(key: "quantity") var quantity: Int | |||
| @Field(key: "sortOrder") var sortorder: Int | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Parent(key: "consumptionId") var consumption: mdlConsumption | |||
| init(){} | |||
| init(id: Int? = nil | |||
| , fluidname: String | |||
| , viscosityname: String | |||
| , quantity: Int | |||
| , sortorder: Int | |||
| , createuserid: Int? = -1 | |||
| , createdate: Date? = nil | |||
| , updateuserid: Int? = -1 | |||
| , updatedate: Date? = nil | |||
| , consumption: mdlConsumption | |||
| ){ | |||
| self.id = id | |||
| self.fluidname = fluidname | |||
| self.viscosityname = viscosityname | |||
| self.quantity = quantity | |||
| self.sortorder = sortorder | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$consumption.id = consumption.id! | |||
| } | |||
| } | |||
| @@ -0,0 +1,118 @@ | |||
| // | |||
| // Contact.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlContact: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let firstname: String | |||
| let lastname: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let customer: mdlCustomer | |||
| let location: mdlLocation | |||
| let contacttypes: [mdlContactMethod]? | |||
| let files: [mdlFile]? | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let firstname: String | |||
| let lastname: String | |||
| let isactive: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let customer: mdlCustomer | |||
| let location: mdlLocation | |||
| let contacttypes: [mdlContactMethod]? | |||
| let files: [mdlFile]? | |||
| } | |||
| static let schema = "Contact" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "firstName") var firstname: String | |||
| @Field(key: "lastName") var lastname: String | |||
| @Field(key: "isActive") var isactive: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Parent(key: "customerId") var customer: mdlCustomer | |||
| @Parent(key: "locationId") var location: mdlLocation | |||
| @Children(for: \.$contact) var contacttypes: [mdlContactMethod] | |||
| @Children(for: \.$contact) var files: [mdlFile] | |||
| init(){} | |||
| init(id: Int? = nil, firstname: String, lastname: String, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, customer: mdlCustomer, location: mdlLocation, contacttypes: [mdlContactMethod]?, files: [mdlFile]?){ | |||
| self.id = id | |||
| self.firstname = firstname | |||
| self.lastname = lastname | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$customer.id = customer.id! | |||
| self.$location.id = location.id! | |||
| self.$contacttypes.value = contacttypes | |||
| self.$files.value = files | |||
| } | |||
| } | |||
| extension mdlContact { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("Contact") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("customerId", .int, .references("Customer", "id")) | |||
| .field("locationId", .int, .references("Location", "id")) | |||
| .field("firstName", .string) | |||
| .field("lastName", .string) | |||
| .field("isActive", .bool) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("Contact").delete() | |||
| } | |||
| } | |||
| /* | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [<#Model#>] = [ | |||
| <#init#> | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| <#Model#>.query(on: database).delete() | |||
| } | |||
| } | |||
| */ | |||
| } | |||
| @@ -0,0 +1,125 @@ | |||
| // | |||
| // ContactMethod.swift | |||
| // | |||
| // | |||
| // Created by Michiel Carman on 10/25/21. | |||
| // | |||
| import Foundation | |||
| import Vapor | |||
| import Fluent | |||
| import FluentPostgresDriver | |||
| final class mdlContactMethod: Model, Content{ | |||
| struct Input: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let line1: String | |||
| let line2: String | |||
| let line3: String | |||
| let line4: String | |||
| let primary: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let contact: mdlContact | |||
| } | |||
| struct Output: Content{ | |||
| let id: Int? | |||
| let name: String | |||
| let description: String | |||
| let line1: String | |||
| let line2: String | |||
| let line3: String | |||
| let line4: String | |||
| let primary: Bool | |||
| let createdate: Date? | |||
| let createuserid: Int? | |||
| let updatedate: Date? | |||
| let updateuserid: Int? | |||
| let contact: mdlContact | |||
| } | |||
| static let schema = "ContactMethod" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "name") var name: String | |||
| @Field(key: "description") var description: String | |||
| @Field(key: "line1") var line1: String | |||
| @Field(key: "line2") var line2: String | |||
| @Field(key: "line3") var line3: String | |||
| @Field(key: "line4") var line4: String | |||
| @Field(key: "primary") var primary: Bool | |||
| @Field(key: "createUserId" ) var createuserid: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "updateUserId") var updateuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @Parent(key: "contactId") var contact: mdlContact | |||
| init(){} | |||
| init(id: Int? = nil, name: String, description: String, line1: String, line2: String, line3: String, line4: String, primary: Bool = false, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, contact: mdlContact){ | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.line1 = line1 | |||
| self.line2 = line2 | |||
| self.line3 = line3 | |||
| self.line4 = line4 | |||
| self.primary = primary | |||
| self.createuserid = createuserid | |||
| self.createdate = createdate | |||
| self.updateuserid = updateuserid | |||
| self.updatedate = updatedate | |||
| self.$contact.id = contact.id! | |||
| } | |||
| } | |||
| extension mdlContactMethod { | |||
| struct create: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| return database.schema("ContactMethod") | |||
| .field("id", .int, .identifier(auto: true)) | |||
| .field("primary", .bool) | |||
| .field("name", .string) | |||
| .field("description", .string) | |||
| .field("line1", .string) | |||
| .field("line2", .string) | |||
| .field("line3", .string) | |||
| .field("line4", .string) | |||
| .field("contactId", .int) | |||
| .field("createUserId", .int) | |||
| .field("createDate", .datetime) | |||
| .field("updateUserId", .int) | |||
| .field("updateDate", .datetime) | |||
| .create() | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| database.schema("ContactMethod").delete() | |||
| } | |||
| } | |||
| /* | |||
| struct seed: Migration { | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| // 1 | |||
| let array: [<#Model#>] = [ | |||
| <#init#> | |||
| ] | |||
| // 2 | |||
| return array.map { obj in | |||
| obj.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| // 3 | |||
| <#Model#>.query(on: database).delete() | |||
| } | |||
| } | |||
| */ | |||
| } | |||