Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

108 строки
3.4 KiB

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