Przeglądaj źródła

Modifications to api endpoints

main
rpm-mcarman 2 lat temu
rodzic
commit
2dade78375
100 zmienionych plików z 3622 dodań i 1462 usunięć
  1. +54
    -23
      Sources/App/Controllers/AuthControllers/cntrlRole.swift
  2. +49
    -18
      Sources/App/Controllers/AuthControllers/cntrlSegment.swift
  3. +51
    -24
      Sources/App/Controllers/AuthControllers/cntrlUser.swift
  4. +49
    -18
      Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift
  5. +49
    -18
      Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift
  6. +58
    -20
      Sources/App/Controllers/BaseControllers/cntrlCategory.swift
  7. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift
  8. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlContactType.swift
  9. +59
    -21
      Sources/App/Controllers/BaseControllers/cntrlDataType.swift
  10. +50
    -19
      Sources/App/Controllers/BaseControllers/cntrlDivision.swift
  11. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift
  12. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlFluid.swift
  13. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlFuel.swift
  14. +50
    -19
      Sources/App/Controllers/BaseControllers/cntrlGate.swift
  15. +52
    -18
      Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift
  16. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlInputType.swift
  17. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlJobSite.swift
  18. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlLevel.swift
  19. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlLocation.swift
  20. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlNoteType.swift
  21. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlPart.swift
  22. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlPriority.swift
  23. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlReason.swift
  24. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlRepairType.swift
  25. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift
  26. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift
  27. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlState.swift
  28. +49
    -18
      Sources/App/Controllers/BaseControllers/cntrlStatus.swift
  29. +58
    -20
      Sources/App/Controllers/BaseControllers/cntrlValueType.swift
  30. +48
    -27
      Sources/App/Controllers/BaseControllers/cntrlViscosity.swift
  31. +49
    -18
      Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift
  32. +48
    -27
      Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift
  33. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlContact.swift
  34. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift
  35. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift
  36. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift
  37. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlMake.swift
  38. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlModel.swift
  39. +51
    -20
      Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift
  40. +49
    -18
      Sources/App/Controllers/CustomerControllers/cntrlProduct.swift
  41. +17
    -0
      Sources/App/Controllers/GlobalFunctions/EncryptionController.swift
  42. +49
    -18
      Sources/App/Controllers/ItemControllers/cntrlItem.swift
  43. +49
    -18
      Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift
  44. +49
    -18
      Sources/App/Controllers/LabControllers/cntrlLabSetting.swift
  45. +49
    -18
      Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift
  46. +49
    -18
      Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift
  47. +49
    -18
      Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift
  48. +49
    -18
      Sources/App/Controllers/SpecControllers/cntrlSpec.swift
  49. +49
    -18
      Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift
  50. +49
    -18
      Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift
  51. +49
    -18
      Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift
  52. +49
    -18
      Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift
  53. +49
    -18
      Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift
  54. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift
  55. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift
  56. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift
  57. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift
  58. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift
  59. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift
  60. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift
  61. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift
  62. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift
  63. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift
  64. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift
  65. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift
  66. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift
  67. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift
  68. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift
  69. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift
  70. +50
    -19
      Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift
  71. +49
    -18
      Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift
  72. +4
    -5
      Sources/App/Models/AuthTables/mdlRole.swift
  73. +4
    -5
      Sources/App/Models/AuthTables/mdlSegment.swift
  74. +15
    -14
      Sources/App/Models/AuthTables/mdlUser.swift
  75. +6
    -7
      Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift
  76. +6
    -7
      Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift
  77. +4
    -5
      Sources/App/Models/BaseTables/mdlCategory.swift
  78. +4
    -5
      Sources/App/Models/BaseTables/mdlComparisonType.swift
  79. +4
    -5
      Sources/App/Models/BaseTables/mdlContactType.swift
  80. +4
    -5
      Sources/App/Models/BaseTables/mdlDataType.swift
  81. +4
    -5
      Sources/App/Models/BaseTables/mdlDivision.swift
  82. +4
    -5
      Sources/App/Models/BaseTables/mdlEquipmentType.swift
  83. +4
    -5
      Sources/App/Models/BaseTables/mdlFluid.swift
  84. +4
    -5
      Sources/App/Models/BaseTables/mdlFuel.swift
  85. +4
    -5
      Sources/App/Models/BaseTables/mdlGate.swift
  86. +4
    -5
      Sources/App/Models/BaseTables/mdlIncompleteReason.swift
  87. +4
    -5
      Sources/App/Models/BaseTables/mdlInputType.swift
  88. +4
    -5
      Sources/App/Models/BaseTables/mdlJobSite.swift
  89. +4
    -5
      Sources/App/Models/BaseTables/mdlLevel.swift
  90. +7
    -8
      Sources/App/Models/BaseTables/mdlLocation.swift
  91. +4
    -5
      Sources/App/Models/BaseTables/mdlNoteType.swift
  92. +4
    -5
      Sources/App/Models/BaseTables/mdlPart.swift
  93. +4
    -5
      Sources/App/Models/BaseTables/mdlPriority.swift
  94. +4
    -5
      Sources/App/Models/BaseTables/mdlReason.swift
  95. +4
    -5
      Sources/App/Models/BaseTables/mdlRepairType.swift
  96. +4
    -5
      Sources/App/Models/BaseTables/mdlSMSCCode.swift
  97. +4
    -5
      Sources/App/Models/BaseTables/mdlSignatureType.swift
  98. +4
    -5
      Sources/App/Models/BaseTables/mdlState.swift
  99. +4
    -5
      Sources/App/Models/BaseTables/mdlStatus.swift
  100. +4
    -5
      Sources/App/Models/BaseTables/mdlValueType.swift

+ 54
- 23
Sources/App/Controllers/AuthControllers/cntrlRole.swift Wyświetl plik

@@ -1,12 +1,15 @@
//
// File.swift
//
// cntrlRole.swift
//
// Created by Michiel Carman on 4/1/24.
//
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlRole: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlRole: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}

func index(req: Request) async throws -> [mdlRole] {
try await mdlRole.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlRole.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlRole{
return try await mdlRole.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlRole.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Role was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}

func create(req: Request) async throws -> mdlRole {
let obj = try req.content.decode(mdlRole.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlRole.self) else {
throw Abort(.notAcceptable, reason: "Role json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Role cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Role has been saved.")
}
return response
}

func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlRole.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlRole.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Role's ID was not supplied. Role will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Role. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Role has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/AuthControllers/cntrlSegment.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSegment.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSegment: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSegment: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSegment] {
try await mdlSegment.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSegment.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSegment{
return try await mdlSegment.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSegment.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Segment was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSegment {
let obj = try req.content.decode(mdlSegment.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSegment.self) else {
throw Abort(.notAcceptable, reason: "Segment json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Segment cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Segment has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSegment.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSegment.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Segment's ID was not supplied. Segment will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Segment. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Segment has been deleted.")
}
return response
}
}


+ 51
- 24
Sources/App/Controllers/AuthControllers/cntrlUser.swift Wyświetl plik

@@ -1,5 +1,5 @@
//
// File.swift
// cntrlUser.swift
//
//
// Created by Michiel Carman on 4/1/24.
@@ -18,43 +18,70 @@ struct cntrlUser: RouteCollection {
rts.get("login", ":x", use: login)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { todo in
rts.delete(use: delete)
}
}
func api(req: Request) async throws -> String{
return Environment.get("API_KEY")!
rts.delete(":x", use: delete)
}
func login(req: Request) async throws -> mdlUser{
return try await mdlUser.ObjQuery(req: req).first()!
func login(req: Request) async throws -> Response{
guard let obj = try? await mdlUser.ObjQuery(req: req).first() else {
throw Abort(.unauthorized, reason: "Username or Password or Both are invalid.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding data. User has been authenticated.")
}
return response
}

func index(req: Request) async throws -> [mdlUser] {
//try await mdlUser.query(on: req.db).with(\.$roles).all()
return try await mdlUser.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlUser.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlUser{
return try await mdlUser.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlUser.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "User was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}

func create(req: Request) async throws -> mdlUser {
let obj = try req.content.decode(mdlUser.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlUser.self) else {
throw Abort(.notAcceptable, reason: "User json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. User cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. User has been saved.")
}
return response
}

func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlUser.find(req.parameters.get("x"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlUser.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "User's ID was not supplied. User will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting User. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. User has been deleted.")
}
try await obj.delete(on: req.db)
return .noContent
return response
}
}

+ 49
- 18
Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlResponseType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlResponseType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlResponseType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlResponseType] {
try await mdlResponseType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlResponseType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlResponseType{
return try await mdlResponseType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlResponseType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ResponseType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlResponseType {
let obj = try req.content.decode(mdlResponseType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlResponseType.self) else {
throw Abort(.notAcceptable, reason: "ResponseType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ResponseType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ResponseType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlResponseType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlResponseType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ResponseType's ID was not supplied. ResponseType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ResponseType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ResponseType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlUnit.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlUnit: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlUnit: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlUnit] {
try await mdlUnit.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlUnit.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlUnit{
return try await mdlUnit.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlUnit.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Unit was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlUnit {
let obj = try req.content.decode(mdlUnit.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlUnit.self) else {
throw Abort(.notAcceptable, reason: "Unit json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Unit cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Unit has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlUnit.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlUnit.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Unit's ID was not supplied. Unit will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Unit. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Unit has been deleted.")
}
return response
}
}


+ 58
- 20
Sources/App/Controllers/BaseControllers/cntrlCategory.swift Wyświetl plik

@@ -1,5 +1,15 @@
//
// cntrlCategory.swift
//
//
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlCategory: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -7,34 +17,62 @@ struct cntrlCategory: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}

func index(req: Request) async throws -> [mdlCategory] {
try await mdlCategory.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlCategory.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlCategory{
return try await mdlCategory.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlCategory.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Category was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}

func create(req: Request) async throws -> mdlCategory {
let obj = try req.content.decode(mdlCategory.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlCategory.self) else {
throw Abort(.notAcceptable, reason: "Category json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Category cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Category has been saved.")
}
return response
}

func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlCategory.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlCategory.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Category's ID was not supplied. Category will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Category. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Category has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlComparisonType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlComparisonType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlComparisonType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlComparisonType] {
try await mdlComparisonType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlComparisonType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlComparisonType{
return try await mdlComparisonType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlComparisonType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ComparisonType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlComparisonType {
let obj = try req.content.decode(mdlComparisonType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlComparisonType.self) else {
throw Abort(.notAcceptable, reason: "ComparisonType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ComparisonType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ComparisonType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlComparisonType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlComparisonType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ComparisonType's ID was not supplied. ComparisonType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ComparisonType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ComparisonType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlContactType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlContactType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlContactType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlContactType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlContactType] {
try await mdlContactType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlContactType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlContactType{
return try await mdlContactType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlContactType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ContactType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlContactType {
let obj = try req.content.decode(mdlContactType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlContactType.self) else {
throw Abort(.notAcceptable, reason: "ContactType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ContactType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ContactType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlContactType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlContactType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ContactType's ID was not supplied. ContactType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ContactType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ContactType has been deleted.")
}
return response
}
}


+ 59
- 21
Sources/App/Controllers/BaseControllers/cntrlDataType.swift Wyświetl plik

@@ -1,40 +1,78 @@
//
// cntrlDataType.swift
//
//
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlDataTypes: RouteCollection {
struct cntrlDataType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let rts = routes.grouped("datatypes")
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}

func index(req: Request) async throws -> [mdlDataType] {
try await mdlDataType.ObjQuery(req: req).with(\.$units).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlDataType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlDataType{
return try await mdlDataType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlDataType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "DataType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}

func create(req: Request) async throws -> mdlDataType {
let obj = try req.content.decode(mdlDataType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlDataType.self) else {
throw Abort(.notAcceptable, reason: "DataType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. DataType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. DataType has been saved.")
}
return response
}

func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlDataType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlDataType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "DataType's ID was not supplied. DataType will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting DataType. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. DataType has been deleted.")
}
return response
}
}


+ 50
- 19
Sources/App/Controllers/BaseControllers/cntrlDivision.swift Wyświetl plik

@@ -1,12 +1,15 @@
//
// Division.swift
// cntrlDivision.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlDivision: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlDivision: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlDivision] {
try await mdlDivision.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlDivision.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlDivision{
return try await mdlDivision.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlDivision.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Division was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlDivision {
let obj = try req.content.decode(mdlDivision.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlDivision.self) else {
throw Abort(.notAcceptable, reason: "Division json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Division cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Division has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlDivision.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlDivision.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Division's ID was not supplied. Division will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Division. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Division has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlEquipmentType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlEquipmentType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlEquipmentType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlEquipmentType] {
try await mdlEquipmentType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlEquipmentType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlEquipmentType{
return try await mdlEquipmentType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlEquipmentType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "EquipmentType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlEquipmentType {
let obj = try req.content.decode(mdlEquipmentType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlEquipmentType.self) else {
throw Abort(.notAcceptable, reason: "EquipmentType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. EquipmentType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. EquipmentType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlEquipmentType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlEquipmentType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "EquipmentType's ID was not supplied. EquipmentType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting EquipmentType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. EquipmentType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlFluid.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlFluid.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlFluid: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlFluid: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlFluid] {
try await mdlFluid.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlFluid.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlFluid{
return try await mdlFluid.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlFluid.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Fluid was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlFluid {
let obj = try req.content.decode(mdlFluid.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlFluid.self) else {
throw Abort(.notAcceptable, reason: "Fluid json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Fluid cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Fluid has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlFluid.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlFluid.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Fluid's ID was not supplied. Fluid will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Fluid. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Fluid has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlFuel.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlFuel.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlFuel: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlFuel: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlFuel] {
try await mdlFuel.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlFuel.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlFuel{
return try await mdlFuel.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlFuel.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Fuel was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlFuel {
let obj = try req.content.decode(mdlFuel.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlFuel.self) else {
throw Abort(.notAcceptable, reason: "Fuel json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Fuel cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Fuel has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlFuel.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlFuel.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Fuel's ID was not supplied. Fuel will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Fuel. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Fuel has been deleted.")
}
return response
}
}


+ 50
- 19
Sources/App/Controllers/BaseControllers/cntrlGate.swift Wyświetl plik

@@ -1,12 +1,15 @@
//
// Gate.swift
// cntrlGate.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlGate: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlGate: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlGate] {
try await mdlGate.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlGate.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlGate{
return try await mdlGate.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlGate.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Gate was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlGate {
let obj = try req.content.decode(mdlGate.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlGate.self) else {
throw Abort(.notAcceptable, reason: "Gate json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Gate cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Gate has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlGate.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlGate.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Gate's ID was not supplied. Gate will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Gate. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Gate has been deleted.")
}
return response
}
}


+ 52
- 18
Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlIncompleteReason.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlIncompleteReason: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,31 +17,62 @@ struct cntrlIncompleteReason: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlIncompleteReason] {
try await mdlIncompleteReason.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlIncompleteReason.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlIncompleteReason{
return try await mdlIncompleteReason.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlIncompleteReason.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "IncompleteReason was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlIncompleteReason {
let obj = try req.content.decode(mdlIncompleteReason.self)
try await obj.save(on: req.db)
return obj
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlIncompleteReason.self) else {
throw Abort(.notAcceptable, reason: "IncompleteReason json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. IncompleteReason cannot be saved.")
}
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. IncompleteReason has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlIncompleteReason.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlIncompleteReason.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "IncompleteReason's ID was not supplied. IncompleteReason will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting IncompleteReason. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. IncompleteReason has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlInputType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInputType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInputType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInputType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInputType] {
try await mdlInputType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInputType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInputType{
return try await mdlInputType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInputType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InputType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInputType {
let obj = try req.content.decode(mdlInputType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInputType.self) else {
throw Abort(.notAcceptable, reason: "InputType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InputType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InputType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInputType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInputType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InputType's ID was not supplied. InputType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InputType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InputType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlJobSite.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlJobSite.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlJobSite: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlJobSite: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlJobSite] {
try await mdlJobSite.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlJobSite.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlJobSite{
return try await mdlJobSite.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlJobSite.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "JobSite was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlJobSite {
let obj = try req.content.decode(mdlJobSite.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlJobSite.self) else {
throw Abort(.notAcceptable, reason: "JobSite json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. JobSite cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. JobSite has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlJobSite.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlJobSite.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "JobSite's ID was not supplied. JobSite will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting JobSite. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. JobSite has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlLevel.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlLevel.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlLevel: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlLevel: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlLevel] {
try await mdlLevel.query(on: req.db).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlLevel.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlLevel{
return try await mdlLevel.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlLevel.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Level was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlLevel {
let obj = try req.content.decode(mdlLevel.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlLevel.self) else {
throw Abort(.notAcceptable, reason: "Level json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Level cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Level has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlLevel.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlLevel.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Level's ID was not supplied. Level will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Level. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Level has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlLocation.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlLocation.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlLocation: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlLocation: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlLocation] {
try await mdlLocation.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlLocation.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlLocation{
return try await mdlLocation.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlLocation.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Location was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlLocation {
let obj = try req.content.decode(mdlLocation.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlLocation.self) else {
throw Abort(.notAcceptable, reason: "Location json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Location cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Location has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlLocation.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlLocation.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Location's ID was not supplied. Location will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Location. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Location has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlNoteType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlNoteType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlNoteType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlNoteType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlNoteType] {
try await mdlNoteType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlNoteType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlNoteType{
return try await mdlNoteType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlNoteType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "NoteType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlNoteType {
let obj = try req.content.decode(mdlNoteType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlNoteType.self) else {
throw Abort(.notAcceptable, reason: "NoteType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. NoteType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. NoteType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlNoteType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlNoteType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "NoteType's ID was not supplied. NoteType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting NoteType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. NoteType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlPart.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlPart.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlPart: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlPart: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlPart] {
try await mdlPart.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlPart.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlPart{
return try await mdlPart.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlPart.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Part was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlPart {
let obj = try req.content.decode(mdlPart.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlPart.self) else {
throw Abort(.notAcceptable, reason: "Part json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Part cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Part has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlPart.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlPart.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Part's ID was not supplied. Part will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Part. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Part has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlPriority.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlPriority.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlPriority: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlPriority: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlPriority] {
try await mdlPriority.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlPriority.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlPriority{
return try await mdlPriority.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlPriority.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Priority was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlPriority {
let obj = try req.content.decode(mdlPriority.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlPriority.self) else {
throw Abort(.notAcceptable, reason: "Priority json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Priority cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Priority has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlPriority.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlPriority.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Priority's ID was not supplied. Priority will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Priority. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Priority has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlReason.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlReason.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlReason: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlReason: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlReason] {
try await mdlReason.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlReason.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlReason{
return try await mdlReason.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlReason.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Reason was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlReason {
let obj = try req.content.decode(mdlReason.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlReason.self) else {
throw Abort(.notAcceptable, reason: "Reason json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Reason cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Reason has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlReason.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlReason.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Reason's ID was not supplied. Reason will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Reason. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Reason has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlRepairType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlRepairType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2025.
//

import Fluent
import Vapor
import Crypto



struct cntrlRepairType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlRepairType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlRepairType] {
try await mdlRepairType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlRepairType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlRepairType{
return try await mdlRepairType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlRepairType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "RepairType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlRepairType {
let obj = try req.content.decode(mdlRepairType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlRepairType.self) else {
throw Abort(.notAcceptable, reason: "RepairType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. RepairType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. RepairType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlRepairType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlRepairType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "RepairType's ID was not supplied. RepairType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting RepairType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. RepairType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSMSCCode.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSMSCCode: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSMSCCode: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSMSCCode] {
try await mdlSMSCCode.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSMSCCode.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSMSCCode{
return try await mdlSMSCCode.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSMSCCode.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "SMSCCode was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSMSCCode {
let obj = try req.content.decode(mdlSMSCCode.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSMSCCode.self) else {
throw Abort(.notAcceptable, reason: "SMSCCode json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. SMSCCode cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SMSCCode has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSMSCCode.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSMSCCode.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "SMSCCode's ID was not supplied. SMSCCode will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting SMSCCode. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SMSCCode has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSignatureType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSignatureType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSignatureType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSignatureType] {
try await mdlSignatureType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSignatureType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSignatureType{
return try await mdlSignatureType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSignatureType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "SignatureType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSignatureType {
let obj = try req.content.decode(mdlSignatureType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSignatureType.self) else {
throw Abort(.notAcceptable, reason: "SignatureType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. SignatureType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SignatureType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSignatureType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSignatureType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "SignatureType's ID was not supplied. SignatureType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting SignatureType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SignatureType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlState.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlState.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlState: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlState: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlState] {
try await mdlState.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlState.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlState{
return try await mdlState.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlState.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "State was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlState {
let obj = try req.content.decode(mdlState.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlState.self) else {
throw Abort(.notAcceptable, reason: "State json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. State cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. State has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlState.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlState.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "State's ID was not supplied. State will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting State. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. State has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/BaseControllers/cntrlStatus.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlStatus.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlStatus: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlStatus: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlStatus] {
try await mdlStatus.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlStatus.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlStatus{
return try await mdlStatus.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlStatus.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Status was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlStatus {
let obj = try req.content.decode(mdlStatus.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlStatus.self) else {
throw Abort(.notAcceptable, reason: "Status json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Status cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Status has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlStatus.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlStatus.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Status's ID was not supplied. Status will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Status. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Status has been deleted.")
}
return response
}
}


+ 58
- 20
Sources/App/Controllers/BaseControllers/cntrlValueType.swift Wyświetl plik

@@ -1,5 +1,15 @@
//
// cntrlValueType.swift
//
//
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlValueType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -7,34 +17,62 @@ struct cntrlValueType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}

func index(req: Request) async throws -> [mdlValueType] {
try await mdlValueType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlValueType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlValueType{
return try await mdlValueType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlValueType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ValueType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}

func create(req: Request) async throws -> mdlValueType {
let obj = try req.content.decode(mdlValueType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlValueType.self) else {
throw Abort(.notAcceptable, reason: "ValueType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ValueType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ValueType has been saved.")
}
return response
}

func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlValueType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlValueType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ValueType's ID was not supplied. ValueType will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ValueType. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ValueType has been deleted.")
}
return response
}
}


+ 48
- 27
Sources/App/Controllers/BaseControllers/cntrlViscosity.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlViscosity.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlViscosity: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,44 +17,62 @@ struct cntrlViscosity: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlViscosity] {
try await mdlViscosity.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlViscosity.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlViscosity{
return try await mdlViscosity.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlViscosity.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Viscosity was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlViscosity {
let obj = try req.content.decode(mdlViscosity.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlViscosity.self) else {
throw Abort(.notAcceptable, reason: "Viscosity json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Viscosity cannot be saved.")
}
try await obj.save(on: req.db)
return obj
}
func update(req: Request) async throws -> mdlViscosity{
let obj = try req.content.decode(mdlViscosity.self)
let dbobj = try await mdlViscosity.query(on: req.db).filter(\.$id == obj.id!).first()!
dbobj.updatedate = Date()
dbobj.updateuserid = -1
try await dbobj.update(on: req.db)
return dbobj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Viscosity has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlViscosity.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlViscosity.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Viscosity's ID was not supplied. Viscosity will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Viscosity. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Viscosity has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlCompartment.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlCompartment: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlCompartment: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlCompartment] {
try await mdlCompartment.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlCompartment.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlCompartment{
return try await mdlCompartment.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlCompartment.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Compartment was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlCompartment {
let obj = try req.content.decode(mdlCompartment.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlCompartment.self) else {
throw Abort(.notAcceptable, reason: "Compartment json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Compartment cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Compartment has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlCompartment.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlCompartment.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Compartment's ID was not supplied. Compartment will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Compartment. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Compartment has been deleted.")
}
return response
}
}


+ 48
- 27
Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlCompartmentLocation.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlCompartmentLocation: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,44 +17,62 @@ struct cntrlCompartmentLocation: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlCompartmentLocation] {
try await mdlCompartmentLocation.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlCompartmentLocation.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlCompartmentLocation{
return try await mdlCompartmentLocation.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlCompartmentLocation.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "CompartmentLocation was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlCompartmentLocation {
let obj = try req.content.decode(mdlCompartmentLocation.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlCompartmentLocation.self) else {
throw Abort(.notAcceptable, reason: "CompartmentLocation json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. CompartmentLocation cannot be saved.")
}
try await obj.save(on: req.db)
return obj
}
func update(req: Request) async throws -> mdlCompartmentLocation{
let obj = try req.content.decode(mdlCompartmentLocation.self)
let dbobj = try await mdlCompartmentLocation.query(on: req.db).filter(\.$id == obj.id!).first()!
dbobj.updatedate = Date()
dbobj.updateuserid = -1
try await dbobj.update(on: req.db)
return dbobj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. CompartmentLocation has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlCompartmentLocation.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlCompartmentLocation.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "CompartmentLocation's ID was not supplied. CompartmentLocation will not be deleted")
}
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting CompartmentLocation. Make sure it has not children.")
}
try await obj.delete(on: req.db)
return .noContent
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. CompartmentLocation has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlContact.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlContact.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlContact: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlContact: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlContact] {
try await mdlContact.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlContact.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlContact{
return try await mdlContact.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlContact.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Contact was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlContact {
let obj = try req.content.decode(mdlContact.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlContact.self) else {
throw Abort(.notAcceptable, reason: "Contact json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Contact cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Contact has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlContact.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlContact.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Contact's ID was not supplied. Contact will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Contact. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Contact has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlContactInfo.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlContactInfo: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlContactInfo: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlContactInfo] {
try await mdlContactInfo.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlContactInfo.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlContactInfo{
return try await mdlContactInfo.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlContactInfo.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ContactInfo was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlContactInfo {
let obj = try req.content.decode(mdlContactInfo.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlContactInfo.self) else {
throw Abort(.notAcceptable, reason: "ContactInfo json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ContactInfo cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ContactInfo has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlContactInfo.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlContactInfo.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ContactInfo's ID was not supplied. ContactInfo will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ContactInfo. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ContactInfo has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlCustomer.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlCustomer: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlCustomer: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlCustomer] {
try await mdlCustomer.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlCustomer.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlCustomer{
return try await mdlCustomer.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlCustomer.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Customer was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlCustomer {
let obj = try req.content.decode(mdlCustomer.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlCustomer.self) else {
throw Abort(.notAcceptable, reason: "Customer json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Customer cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Customer has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlCustomer.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlCustomer.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Customer's ID was not supplied. Customer will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Customer. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Customer has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlEquipment.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlEquipment: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlEquipment: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlEquipment] {
try await mdlEquipment.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlEquipment.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlEquipment{
return try await mdlEquipment.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlEquipment.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Equipment was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlEquipment {
let obj = try req.content.decode(mdlEquipment.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlEquipment.self) else {
throw Abort(.notAcceptable, reason: "Equipment json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Equipment cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Equipment has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlEquipment.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlEquipment.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Equipment's ID was not supplied. Equipment will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Equipment. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Equipment has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlMake.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlMake.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlMake: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlMake: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlMake] {
try await mdlMake.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlMake.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlMake{
return try await mdlMake.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlMake.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Make was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlMake {
let obj = try req.content.decode(mdlMake.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlMake.self) else {
throw Abort(.notAcceptable, reason: "Make json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Make cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Make has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlMake.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlMake.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Make's ID was not supplied. Make will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Make. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Make has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlModel.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlModel.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlModel: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlModel: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlModel] {
try await mdlModel.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlModel.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlModel{
return try await mdlModel.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlModel.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Model was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlModel {
let obj = try req.content.decode(mdlModel.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlModel.self) else {
throw Abort(.notAcceptable, reason: "Model json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Model cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Model has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlModel.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlModel.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Model's ID was not supplied. Model will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Model. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Model has been deleted.")
}
return response
}
}


+ 51
- 20
Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift Wyświetl plik

@@ -1,47 +1,78 @@
//
// cntrlObjectProperty.swift
// cntrlObjProperty.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlObjProperty: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let rts = routes.grouped("objproperties")
let rts = routes.grouped("objectproperties")
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlObjProperty] {
try await mdlObjProperty.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlObjProperty.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlObjProperty{
return try await mdlObjProperty.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlObjProperty.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ObjProperty was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlObjProperty {
let obj = try req.content.decode(mdlObjProperty.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlObjProperty.self) else {
throw Abort(.notAcceptable, reason: "ObjProperty json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ObjProperty cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ObjProperty has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlObjProperty.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlObjProperty.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ObjProperty's ID was not supplied. ObjProperty will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ObjProperty. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ObjProperty has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/CustomerControllers/cntrlProduct.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlProduct.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlProduct: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlProduct: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlProduct] {
try await mdlProduct.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlProduct.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlProduct{
return try await mdlProduct.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlProduct.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Product was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlProduct {
let obj = try req.content.decode(mdlProduct.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlProduct.self) else {
throw Abort(.notAcceptable, reason: "Product json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Product cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Product has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlProduct.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlProduct.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Product's ID was not supplied. Product will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Product. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Product has been deleted.")
}
return response
}
}


+ 17
- 0
Sources/App/Controllers/GlobalFunctions/EncryptionController.swift Wyświetl plik

@@ -30,6 +30,23 @@ struct CustomCrypto{
}
return decryptedString
}
public static func EncryptString(input: String) throws -> String{
let apikey = Environment.get("API_KEY") ?? "rv0ywT7Ygwh01jP1dQWBP39ogjq5ladO+EoNUGcBVq0="
print(apikey)
guard let keyData = Data(base64Encoded: apikey) else{
fatalError("Invalid Base64 key data")
}
let encryptionKey = SymmetricKey(data: keyData)
guard let datatoEncrypt = input.data(using: .utf8) else{ fatalError("Invalid Data")}
do{
let sealedBox = try AES.GCM.seal(datatoEncrypt, using: encryptionKey)
guard let combined = sealedBox.combined else{ fatalError("Can't combine")}
let base64EncodedString = combined.base64EncodedString()
let urlEncodedString = base64EncodedString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
return urlEncodedString!
}
}
}



+ 49
- 18
Sources/App/Controllers/ItemControllers/cntrlItem.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlItem.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlItem: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlItem: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlItem] {
try await mdlItem.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlItem.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlItem{
return try await mdlItem.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlItem.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Item was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlItem {
let obj = try req.content.decode(mdlItem.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlItem.self) else {
throw Abort(.notAcceptable, reason: "Item json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Item cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Item has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlItem.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlItem.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Item's ID was not supplied. Item will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Item. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Item has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlItemResponseType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlItemResponseType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlItemResponseType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlItemResponseType] {
try await mdlItemResponseType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlItemResponseType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlItemResponseType{
return try await mdlItemResponseType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlItemResponseType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "ItemResponseType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlItemResponseType {
let obj = try req.content.decode(mdlItemResponseType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlItemResponseType.self) else {
throw Abort(.notAcceptable, reason: "ItemResponseType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. ItemResponseType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ItemResponseType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlItemResponseType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlItemResponseType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "ItemResponseType's ID was not supplied. ItemResponseType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting ItemResponseType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. ItemResponseType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/LabControllers/cntrlLabSetting.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlLabSetting.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlLabSetting: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlLabSetting: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlLabSetting] {
try await mdlLabSetting.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlLabSetting.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlLabSetting{
return try await mdlLabSetting.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlLabSetting.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "LabSetting was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlLabSetting {
let obj = try req.content.decode(mdlLabSetting.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlLabSetting.self) else {
throw Abort(.notAcceptable, reason: "LabSetting json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. LabSetting cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. LabSetting has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlLabSetting.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlLabSetting.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "LabSetting's ID was not supplied. LabSetting will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting LabSetting. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. LabSetting has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlXFluidViscosity.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlXFluidViscosity: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlXFluidViscosity: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlXFluidViscosity] {
try await mdlXFluidViscosity.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlXFluidViscosity.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlXFluidViscosity{
return try await mdlXFluidViscosity.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlXFluidViscosity.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "XFluidViscosity was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlXFluidViscosity {
let obj = try req.content.decode(mdlXFluidViscosity.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlXFluidViscosity.self) else {
throw Abort(.notAcceptable, reason: "XFluidViscosity json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. XFluidViscosity cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. XFluidViscosity has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlXFluidViscosity.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlXFluidViscosity.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "XFluidViscosity's ID was not supplied. XFluidViscosity will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting XFluidViscosity. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. XFluidViscosity has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlXUserRole.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlXUserRole: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlXUserRole: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlXUserRole] {
try await mdlXUserRole.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlXUserRole.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlXUserRole{
return try await mdlXUserRole.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlXUserRole.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "XUserRole was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlXUserRole {
let obj = try req.content.decode(mdlXUserRole.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlXUserRole.self) else {
throw Abort(.notAcceptable, reason: "XUserRole json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. XUserRole cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. XUserRole has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlXUserRole.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlXUserRole.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "XUserRole's ID was not supplied. XUserRole will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting XUserRole. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. XUserRole has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlOilSample.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlOilSample: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlOilSample: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlOilSample] {
try await mdlOilSample.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlOilSample.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlOilSample{
return try await mdlOilSample.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlOilSample.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "OilSample was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlOilSample {
let obj = try req.content.decode(mdlOilSample.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlOilSample.self) else {
throw Abort(.notAcceptable, reason: "OilSample json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. OilSample cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. OilSample has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlOilSample.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlOilSample.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "OilSample's ID was not supplied. OilSample will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting OilSample. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. OilSample has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/SpecControllers/cntrlSpec.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSpec.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSpec: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSpec: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSpec] {
try await mdlSpec.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSpec.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSpec{
return try await mdlSpec.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSpec.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Spec was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSpec {
let obj = try req.content.decode(mdlSpec.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSpec.self) else {
throw Abort(.notAcceptable, reason: "Spec json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Spec cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Spec has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSpec.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSpec.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Spec's ID was not supplied. Spec will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Spec. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Spec has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSpecItem.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSpecItem: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSpecItem: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSpecItem] {
try await mdlSpecItem.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSpecItem.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSpecItem{
return try await mdlSpecItem.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSpecItem.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "SpecItem was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSpecItem {
let obj = try req.content.decode(mdlSpecItem.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSpecItem.self) else {
throw Abort(.notAcceptable, reason: "SpecItem json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. SpecItem cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SpecItem has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSpecItem.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSpecItem.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "SpecItem's ID was not supplied. SpecItem will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting SpecItem. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SpecItem has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSpecItemValue.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSpecItemValue: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSpecItemValue: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSpecItemValue] {
try await mdlSpecItemValue.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSpecItemValue.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSpecItemValue{
return try await mdlSpecItemValue.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSpecItemValue.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "SpecItemValue was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSpecItemValue {
let obj = try req.content.decode(mdlSpecItemValue.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSpecItemValue.self) else {
throw Abort(.notAcceptable, reason: "SpecItemValue json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. SpecItemValue cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SpecItemValue has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSpecItemValue.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSpecItemValue.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "SpecItemValue's ID was not supplied. SpecItemValue will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting SpecItemValue. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. SpecItemValue has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlTemplate.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlTemplate: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlTemplate: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlTemplate] {
try await mdlTemplate.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplate.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlTemplate{
return try await mdlTemplate.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlTemplate.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Template was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlTemplate {
let obj = try req.content.decode(mdlTemplate.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlTemplate.self) else {
throw Abort(.notAcceptable, reason: "Template json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Template cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Template has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlTemplate.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplate.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Template's ID was not supplied. Template will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Template. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Template has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlTemplateCategory.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlTemplateCategory: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlTemplateCategory: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlTemplateCategory] {
try await mdlTemplateCategory.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplateCategory.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlTemplateCategory{
return try await mdlTemplateCategory.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlTemplateCategory.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "TemplateCategory was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlTemplateCategory {
let obj = try req.content.decode(mdlTemplateCategory.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlTemplateCategory.self) else {
throw Abort(.notAcceptable, reason: "TemplateCategory json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. TemplateCategory cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. TemplateCategory has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlTemplateCategory.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplateCategory.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "TemplateCategory's ID was not supplied. TemplateCategory will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting TemplateCategory. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. TemplateCategory has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlTemplateItemSpec.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlTemplateItemSpec: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlTemplateItemSpec: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlTemplateItemSpec] {
try await mdlTemplateItemSpec.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplateItemSpec.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlTemplateItemSpec{
return try await mdlTemplateItemSpec.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlTemplateItemSpec.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "TemplateItemSpec was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlTemplateItemSpec {
let obj = try req.content.decode(mdlTemplateItemSpec.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlTemplateItemSpec.self) else {
throw Abort(.notAcceptable, reason: "TemplateItemSpec json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. TemplateItemSpec cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. TemplateItemSpec has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlTemplateItemSpec.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlTemplateItemSpec.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "TemplateItemSpec's ID was not supplied. TemplateItemSpec will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting TemplateItemSpec. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. TemplateItemSpec has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlWorkOrderAttachment.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlWorkOrderAttachment: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlWorkOrderAttachment: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlWorkOrderAttachment] {
try await mdlWorkOrderAttachment.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderAttachment.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlWorkOrderAttachment{
return try await mdlWorkOrderAttachment.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlWorkOrderAttachment.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "WorkOrderAttachment was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlWorkOrderAttachment {
let obj = try req.content.decode(mdlWorkOrderAttachment.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlWorkOrderAttachment.self) else {
throw Abort(.notAcceptable, reason: "WorkOrderAttachment json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. WorkOrderAttachment cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderAttachment has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlWorkOrderAttachment.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderAttachment.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "WorkOrderAttachment's ID was not supplied. WorkOrderAttachment will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting WorkOrderAttachment. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderAttachment has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlConsumption.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlConsumption: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlConsumption: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlConsumption] {
try await mdlConsumption.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlConsumption.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlConsumption{
return try await mdlConsumption.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlConsumption.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Consumption was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlConsumption {
let obj = try req.content.decode(mdlConsumption.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlConsumption.self) else {
throw Abort(.notAcceptable, reason: "Consumption json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Consumption cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Consumption has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlConsumption.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlConsumption.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Consumption's ID was not supplied. Consumption will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Consumption. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Consumption has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspection.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspection: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspection: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspection] {
try await mdlInspection.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspection.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspection{
return try await mdlInspection.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspection.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Inspection was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspection {
let obj = try req.content.decode(mdlInspection.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspection.self) else {
throw Abort(.notAcceptable, reason: "Inspection json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Inspection cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Inspection has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspection.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspection.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Inspection's ID was not supplied. Inspection will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Inspection. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Inspection has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionCategory.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionCategory: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionCategory: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionCategory] {
return try await mdlInspectionCategory.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionCategory.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionCategory{
return try await mdlInspectionCategory.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionCategory.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionCategory was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionCategory {
let obj = try req.content.decode(mdlInspectionCategory.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionCategory.self) else {
throw Abort(.notAcceptable, reason: "InspectionCategory json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionCategory cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionCategory has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionCategory.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionCategory.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionCategory's ID was not supplied. <#Name#> will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionCategory. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionCategory has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItem.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItem: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItem: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItem] {
try await mdlInspectionItem.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItem.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItem{
return try await mdlInspectionItem.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItem.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItem was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItem {
let obj = try req.content.decode(mdlInspectionItem.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItem.self) else {
throw Abort(.notAcceptable, reason: "InspectionItem json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItem cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItem has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItem.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItem.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItem's ID was not supplied. InspectionItem will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItem. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItem has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItemResponse.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItemResponse: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItemResponse: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItemResponse] {
try await mdlInspectionItemResponse.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemResponse.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItemResponse{
return try await mdlInspectionItemResponse.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItemResponse.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItemResponse was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItemResponse {
let obj = try req.content.decode(mdlInspectionItemResponse.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItemResponse.self) else {
throw Abort(.notAcceptable, reason: "InspectionItemResponse json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItemResponse cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemResponse has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItemResponse.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemResponse.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItemResponse's ID was not supplied. InspectionItemResponse will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItemResponse. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemResponse has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItemSpec.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItemSpec: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItemSpec: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItemSpec] {
try await mdlInspectionItemSpec.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpec.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItemSpec{
return try await mdlInspectionItemSpec.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItemSpec.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItemSpec was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItemSpec {
let obj = try req.content.decode(mdlInspectionItemSpec.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItemSpec.self) else {
throw Abort(.notAcceptable, reason: "InspectionItemSpec json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItemSpec cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpec has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItemSpec.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpec.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItemSpec's ID was not supplied. InspectionItemSpec will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItemSpec. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpec has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItemSpecItem.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItemSpecItem: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItemSpecItem: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItemSpecItem] {
try await mdlInspectionItemSpecItem.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItem.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItemSpecItem{
return try await mdlInspectionItemSpecItem.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItemSpecItem.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItemSpecItem was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItemSpecItem {
let obj = try req.content.decode(mdlInspectionItemSpecItem.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItemSpecItem.self) else {
throw Abort(.notAcceptable, reason: "InspectionItemSpecItem json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItemSpecItem cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItem has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItemSpecItem.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItem.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItemSpecItem's ID was not supplied. InspectionItemSpecItem will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItemSpecItem. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItem has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItemSpecItemTest.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItemSpecItemTest: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItemSpecItemTest: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItemSpecItemTest] {
try await mdlInspectionItemSpecItemTest.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItemTest.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItemSpecItemTest{
return try await mdlInspectionItemSpecItemTest.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItemSpecItemTest.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItemSpecItemTest was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItemSpecItemTest {
let obj = try req.content.decode(mdlInspectionItemSpecItemTest.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItemSpecItemTest.self) else {
throw Abort(.notAcceptable, reason: "InspectionItemSpecItemTest json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItemSpecItemTest cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItemTest has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItemSpecItemTest.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItemTest.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItemSpecItemTest's ID was not supplied. InspectionItemSpecItemTest will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItemSpecItemTest. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItemTest has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionItemSpecItemValue.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionItemSpecItemValue: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionItemSpecItemValue: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionItemSpecItemValue] {
try await mdlInspectionItemSpecItemValue.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItemValue.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionItemSpecItemValue{
return try await mdlInspectionItemSpecItemValue.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionItemSpecItemValue.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionItemSpecItemValue was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionItemSpecItemValue {
let obj = try req.content.decode(mdlInspectionItemSpecItemValue.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionItemSpecItemValue.self) else {
throw Abort(.notAcceptable, reason: "InspectionItemSpecItemValue json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionItemSpecItemValue cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItemValue has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionItemSpecItemValue.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionItemSpecItemValue.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionItemSpecItemValue's ID was not supplied. InspectionItemSpecItemValue will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionItemSpecItemValue. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionItemSpecItemValue has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionLevel.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionLevel: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionLevel: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionLevel] {
try await mdlInspectionLevel.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionLevel.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionLevel{
return try await mdlInspectionLevel.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionLevel.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionLevel was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionLevel {
let obj = try req.content.decode(mdlInspectionLevel.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionLevel.self) else {
throw Abort(.notAcceptable, reason: "InspectionLevel json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionLevel cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionLevel has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionLevel.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionLevel.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionLevel's ID was not supplied. InspectionLevel will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionLevel. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionLevel has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlInspectionType.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlInspectionType: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlInspectionType: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlInspectionType] {
try await mdlInspectionType.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionType.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlInspectionType{
return try await mdlInspectionType.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlInspectionType.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "InspectionType was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlInspectionType {
let obj = try req.content.decode(mdlInspectionType.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlInspectionType.self) else {
throw Abort(.notAcceptable, reason: "InspectionType json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. InspectionType cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionType has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlInspectionType.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlInspectionType.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "InspectionType's ID was not supplied. InspectionType will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting InspectionType. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. InspectionType has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlNote.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlNote: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlNote: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlNote] {
try await mdlNote.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlNote.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlNote{
return try await mdlNote.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlNote.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Note was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlNote {
let obj = try req.content.decode(mdlNote.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlNote.self) else {
throw Abort(.notAcceptable, reason: "Note json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Note cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Note has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlNote.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlNote.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Note's ID was not supplied. Note will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Note. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Note has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlWorkOrderPart.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlWorkOrderPart: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlWorkOrderPart: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlWorkOrderPart] {
try await mdlWorkOrderPart.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderPart.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlWorkOrderPart{
return try await mdlWorkOrderPart.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlWorkOrderPart.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "WorkOrderPart was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlWorkOrderPart {
let obj = try req.content.decode(mdlWorkOrderPart.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlWorkOrderPart.self) else {
throw Abort(.notAcceptable, reason: "WorkOrderPart json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. WorkOrderPart cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderPart has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlWorkOrderPart.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderPart.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "WorkOrderPart's ID was not supplied. WorkOrderPart will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting WorkOrderPart. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderPart has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlSignature.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlSignature: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlSignature: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlSignature] {
try await mdlSignature.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlSignature.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlSignature{
return try await mdlSignature.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlSignature.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "Signature was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlSignature {
let obj = try req.content.decode(mdlSignature.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlSignature.self) else {
throw Abort(.notAcceptable, reason: "Signature json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. Signature cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Signature has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlSignature.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlSignature.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "Signature's ID was not supplied. Signature will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting Signature. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Signature has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlWorkOrder.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlWorkOrder: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlWorkOrder: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlWorkOrder] {
try await mdlWorkOrder.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrder.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlWorkOrder{
return try await mdlWorkOrder.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlWorkOrder.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "WorkOrder was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlWorkOrder {
let obj = try req.content.decode(mdlWorkOrder.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlWorkOrder.self) else {
throw Abort(.notAcceptable, reason: "WorkOrder json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. WorkOrder cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrder has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlWorkOrder.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrder.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "WorkOrder's ID was not supplied. WorkOrder will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting WorkOrder. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrder has been deleted.")
}
return response
}
}


+ 50
- 19
Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift Wyświetl plik

@@ -2,46 +2,77 @@
// cntrlWorkOrderFlow.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto

struct cntrlWorkorderFlow: RouteCollection {


struct cntrlWorkOrderFlow: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let rts = routes.grouped("workorderflows")
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlWorkOrderFlow] {
try await mdlWorkOrderFlow.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderFlow.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlWorkOrderFlow{
return try await mdlWorkOrderFlow.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlWorkOrderFlow.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "WorkOrderFlow was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlWorkOrderFlow {
let obj = try req.content.decode(mdlWorkOrderFlow.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlWorkOrderFlow.self) else {
throw Abort(.notAcceptable, reason: "WorkOrderFlow json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. WorkOrderFlow cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderFlow has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlWorkOrderFlow.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderFlow.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "WorkOrderFlow's ID was not supplied. WorkOrderFlow will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting WorkOrderFlow. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderFlow has been deleted.")
}
return response
}
}


+ 49
- 18
Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift Wyświetl plik

@@ -2,11 +2,14 @@
// cntrlWorkOrderSegment.swift
//
//
// Created by Michiel Carman on 4/1/24.
// Created by Michiel Carman on 4/5/2024.
//

import Fluent
import Vapor
import Crypto



struct cntrlWorkOrderSegment: RouteCollection {
func boot(routes: RoutesBuilder) throws {
@@ -14,34 +17,62 @@ struct cntrlWorkOrderSegment: RouteCollection {
rts.get(use: index)
rts.get(":x", use: read)
rts.post(use: create)
rts.group(":x") { rt in
rts.delete(use: delete)
}
///Add custom routes here
rts.delete(":x", use: delete)
//Additional routs added here
}
func index(req: Request) async throws -> [mdlWorkOrderSegment] {
try await mdlWorkOrderSegment.ObjQuery(req: req).all()
func index(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderSegment.ObjQuery(req: req).all() else {
throw Abort(.badGateway, reason: "Something went wrong with this api.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. Array could not be shown.")
}
return response
}
func read(req:Request) async throws -> mdlWorkOrderSegment{
return try await mdlWorkOrderSegment.ObjQuery(req: req).first()!
func read(req:Request) async throws -> Response{
guard let obj = try? await mdlWorkOrderSegment.ObjQuery(req: req).first() else{
throw Abort(.notFound, reason: "WorkOrderSegment was not found.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else {
throw Abort(.noContent, reason: "Something went wrong decoding object.")
}
return response
}
func create(req: Request) async throws -> mdlWorkOrderSegment {
let obj = try req.content.decode(mdlWorkOrderSegment.self)
func create(req: Request) async throws -> Response {
guard let obj = try? req.content.decode(mdlWorkOrderSegment.self) else {
throw Abort(.notAcceptable, reason: "WorkOrderSegment json not formatted correctly or is missing parents.")
}
var exists = false
if(obj.id != nil){
obj._$idExists = true
exists = true
}
guard let _ = try? await obj.save(on: req.db) else{
throw Abort(.conflict, reason: "Something conflicts in the database. WorkOrderSegment cannot be saved.")
}
try await obj.save(on: req.db)
return obj
guard let response = try? await obj.encodeResponse(status: exists ? .accepted : .created, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderSegment has been saved.")
}
return response
}
func delete(req: Request) async throws -> HTTPStatus {
guard let obj = try await mdlWorkOrderSegment.find(req.parameters.get("id"), on: req.db) else {
throw Abort(.notFound)
func delete(req: Request) async throws -> Response {
guard let obj = try? await mdlWorkOrderSegment.ObjQuery(req: req).first() else {
throw Abort(.notFound, reason: "WorkOrderSegment's ID was not supplied. WorkOrderSegment will not be deleted")
}
try await obj.delete(on: req.db)
return .noContent
guard let _ = try? await obj.delete(on: req.db) else{
throw Abort(.conflict, reason: "There was a conflict deleting WorkOrderSegment. Make sure it has not children.")
}
guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{
throw Abort(.noContent, reason: "Something went wrong decoding data. WorkOrderSegment has been deleted.")
}
return response
}
}


+ 4
- 5
Sources/App/Models/AuthTables/mdlRole.swift Wyświetl plik

@@ -92,12 +92,11 @@ extension mdlRole{
.with(\.$users)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/AuthTables/mdlSegment.swift Wyświetl plik

@@ -83,12 +83,11 @@ extension mdlSegment{
let query = mdlSegment.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 15
- 14
Sources/App/Models/AuthTables/mdlUser.swift Wyświetl plik

@@ -36,7 +36,7 @@ final class mdlUser: Model, Content {
@Timestamp(key: "updateDate", on: .update) var updatedate: Date?
@Field(key: "updateUserId") var updateuserid: Int?
init() { }
init() {}
init(id: Int? = nil, number: String? = nil, firstname: String? = nil, lastname: String? = nil, username: String? = nil, password: String? = nil, email: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, divisionid: Int? = nil, locationid: Int? = nil, gateid: Int? = nil) {
self.id = id
@@ -48,10 +48,9 @@ final class mdlUser: Model, Content {
self.password = password
self.email = email
self.isactive = isactive
self.$division.$id.value = divisionid!
self.$location.$id.value = locationid!
self.$gate.$id.value = gateid!
if(divisionid != nil) { self.$division.$id.value = divisionid }
if(locationid != nil) { self.$location.$id.value = locationid }
if(gateid != nil) { self.$gate.$id.value = gateid }
self.createuserid = createuserid
self.updateuserid = updateuserid
@@ -94,24 +93,26 @@ extension mdlUser{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
let p = req.url.path.components(separatedBy: "/")[4]
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call
///You must include an else for each call that has parameters
///Need to check the endpoint to get the right filter statements
else if(x.count == 2){
let username = x[0]
let password = x[1]
///
else if(array.count == 2 && p.uppercased() == "LOGIN"){
let username = array[0]
let password = array[1]
return query.filter(\.$username == username).filter(\.$password == password)
}
else{
throw Abort(.badRequest)
throw Abort(.badRequest, reason: "Parameter missmatch.")
}
}


+ 6
- 7
Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift Wyświetl plik

@@ -29,13 +29,13 @@ final class mdlResponseType: Model, Content {
init() { }
init(id: Int? = nil, name: String? = nil, color: String? = nil, isactive: Bool? = nil, repairtypeid: Int? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) {
init(id: Int? = nil, name: String? = nil, color: String? = nil, isactive: Bool? = nil, repairtypeid: Int, createuserid: Int? = nil, updateuserid: Int? = nil) {
self.id = id
self.name = name
self.color = color
self.isactive = isactive
self.$repairtype.$id.value = repairtypeid!
self.$repairtype.$id.value = repairtypeid
self.createuserid = createuserid
self.updateuserid = updateuserid
@@ -84,12 +84,11 @@ extension mdlResponseType{
.with(\.$responses)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 6
- 7
Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift Wyświetl plik

@@ -28,13 +28,13 @@ final class mdlUnit: Model, Content {
init() { }
init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, datatypeid: Int? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) {
init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, datatypeid: Int, createuserid: Int? = nil, updateuserid: Int? = nil) {
self.id = id
self.name = name
self.description = description
self.isactive = isactive
self.$datatype.$id.value = datatypeid!
self.$datatype.$id.value = datatypeid
self.createuserid = createuserid
self.updateuserid = updateuserid
@@ -67,12 +67,11 @@ extension mdlUnit{
.with(\.$datatype)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlCategory.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlCategory{
.with(\.$templatecategories)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlComparisonType.swift Wyświetl plik

@@ -80,12 +80,11 @@ extension mdlComparisonType{
let query = mdlComparisonType.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlContactType.swift Wyświetl plik

@@ -80,12 +80,11 @@ extension mdlContactType{
let query = mdlContactType.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlDataType.swift Wyświetl plik

@@ -82,12 +82,11 @@ extension mdlDataType{
.with(\.$units)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlDivision.swift Wyświetl plik

@@ -66,12 +66,11 @@ extension mdlDivision{
.with(\.$users)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlEquipmentType.swift Wyświetl plik

@@ -76,12 +76,11 @@ extension mdlEquipmentType{
let query = mdlEquipmentType.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlFluid.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlFluid{
let query = mdlFluid.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlFuel.swift Wyświetl plik

@@ -68,12 +68,11 @@ extension mdlFuel{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlGate.swift Wyświetl plik

@@ -65,12 +65,11 @@
.with(\.$users)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlIncompleteReason.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlIncompleteReason{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlInputType.swift Wyświetl plik

@@ -81,12 +81,11 @@ extension mdlInputType{
.with(\.$inspectionitems)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlJobSite.swift Wyświetl plik

@@ -79,12 +79,11 @@ extension mdlJobSite{
let query = mdlJobSite.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlLevel.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlLevel{
let query = mdlLevel.query(on: req.db)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 7
- 8
Sources/App/Models/BaseTables/mdlLocation.swift Wyświetl plik

@@ -50,7 +50,7 @@ final class mdlLocation: Model, Content {
isactive: Bool? = nil,
createuserid: Int? = nil,
updateuserid: Int? = nil,
stateid: Int? = nil,
stateid: Int,
unitid: Int? = nil
) {
self.id = id
@@ -67,8 +67,8 @@ final class mdlLocation: Model, Content {
self.createuserid = createuserid
self.updateuserid = updateuserid
self.$state.$id.value = stateid!
self.$unit.$id.value = unitid!
self.$state.$id.value = stateid
if(unitid != nil) {self.$unit.$id.value = unitid}
}
}

@@ -121,12 +121,11 @@ extension mdlLocation{
.with(\.$labsetting)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlNoteType.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlNoteType{
.with(\.$notes)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlPart.swift Wyświetl plik

@@ -63,12 +63,11 @@ extension mdlPart{
// .with(\.$<#parent/children#>)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlPriority.swift Wyświetl plik

@@ -82,12 +82,11 @@ extension mdlPriority{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlReason.swift Wyświetl plik

@@ -65,12 +65,11 @@ extension mdlReason{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlRepairType.swift Wyświetl plik

@@ -85,12 +85,11 @@ extension mdlRepairType{
.with(\.$units)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlSMSCCode.swift Wyświetl plik

@@ -63,12 +63,11 @@ extension mdlSMSCCode{
// .with(\.$<#parent/children#>)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlSignatureType.swift Wyświetl plik

@@ -78,12 +78,11 @@ extension mdlSignatureType{
// .with(\.$<#parent/children#>)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlState.swift Wyświetl plik

@@ -130,12 +130,11 @@ extension mdlState{
.with(\.$locations)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlStatus.swift Wyświetl plik

@@ -86,12 +86,11 @@ extension mdlStatus{
.with(\.$workorders)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


+ 4
- 5
Sources/App/Models/BaseTables/mdlValueType.swift Wyświetl plik

@@ -80,12 +80,11 @@ extension mdlValueType{
// .with(\.$<#parent/children#>)
if let x = req.parameters.get("x"){
let dataQuery = req.parameters.get("x")
let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
let x = decryptedString.components(separatedBy: ":")
let decryptedString = try CustomCrypto.DecryptString(input: x)
let array = decryptedString.components(separatedBy: ":")
///This call is the standard get by id call
if (x.count == 1){
let id = Int(x[0])!
if (array.count == 1){
let id = Int(array[0])!
return query.filter(\.$id == id)
}
///Optional else if if there are multiple parameters in the call


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików

Ładowanie…
Anuluj
Zapisz