Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

104 Zeilen
3.4 KiB

  1. //
  2. // mdlTemplateItemSpec.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 2/16/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. import Foundation
  10. import FluentKit
  11. final class mdlTemplateItemSpec: Model, Content {
  12. static let schema = "templateItemSpec"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Parent(key: "templateCategoryId") var templatecategory: mdlTemplateCategory
  15. @OptionalParent(key: "itemId") var item: mdlItem?
  16. @OptionalParent(key: "specId") var spec: mdlSpec?
  17. @Field(key: "sortOrder") var sortorder: Int?
  18. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  19. @Field(key: "createUserId") var createuserid: Int?
  20. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  21. @Field(key: "updateUserId") var updateuserid: Int?
  22. init() { }
  23. init(id: Int? = nil,
  24. categoryid: Int,
  25. itemid: Int? = nil,
  26. specid: Int? = nil,
  27. sortorder: Int? = 0,
  28. createuserid: Int? = nil,
  29. updateuserid: Int? = nil
  30. ) {
  31. self.id = id
  32. self.$templatecategory.$id.value = categoryid
  33. self.$item.$id.value = itemid
  34. self.$spec.$id.value = specid
  35. self.sortorder = sortorder
  36. self.createuserid = createuserid
  37. self.updateuserid = updateuserid
  38. }
  39. }
  40. extension mdlTemplateItemSpec{
  41. struct Create: AsyncMigration {
  42. func prepare(on database: Database) async throws {
  43. try await database.schema("templateItemSpec")
  44. .field("id", .int, .identifier(auto: true))
  45. .field("templateCategoryId", .int, .references("templateCategory", "id"))
  46. .field("itemId", .int, .references("item", "id"))
  47. .field("specId", .int, .references("spec", "id"))
  48. .field("sortOrder", .int)
  49. .field("createDate", .datetime)
  50. .field("createUserId", .int)
  51. .field("updateDate", .datetime)
  52. .field("updateUserId", .int)
  53. .create()
  54. }
  55. func revert(on database: Database) async throws {
  56. try await database.schema("templateItemSpec").delete()
  57. }
  58. }
  59. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlTemplateItemSpec>{
  60. let query = mdlTemplateItemSpec.query(on: req.db)
  61. .with(\.$templatecategory)
  62. .with(\.$item)
  63. .with(\.$spec)
  64. if let x = req.parameters.get("x"){
  65. let dataQuery = req.parameters.get("x")
  66. let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!)
  67. let x = decryptedString.components(separatedBy: ":")
  68. ///This call is the standard get by id call
  69. if (x.count == 1){
  70. let id = Int(x[0])!
  71. return query.filter(\.$id == id)
  72. }
  73. ///Optional else if if there are multiple parameters in the call
  74. ///You must include an else for each call that has parameters
  75. ///Need to check the endpoint to get the right filter statements
  76. ///else if(x.count == 2){
  77. /// let username = x[0]
  78. /// let password = x[1]
  79. /// return query.filter(\.$username == username).filter(\.$password == password)
  80. ///}
  81. else{
  82. throw Abort(.badRequest)
  83. }
  84. }
  85. else{
  86. return query
  87. }
  88. }
  89. }