25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

94 satır
2.9 KiB

  1. //
  2. // mdlSMSCCode.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 mdlSMSCCode: Model, Content {
  12. static let schema = "smscCode"
  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. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  18. @Field(key: "createUserId") var createuserid: Int?
  19. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  20. @Field(key: "updateUserId") var updateuserid: Int?
  21. init() { }
  22. init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) {
  23. self.id = id
  24. self.name = name
  25. self.description = description
  26. self.isactive = isactive
  27. self.createuserid = createuserid
  28. self.updateuserid = updateuserid
  29. }
  30. }
  31. extension mdlSMSCCode{
  32. struct Create: AsyncMigration {
  33. func prepare(on database: Database) async throws {
  34. try await database.schema("smscCode")
  35. .field("id", .int, .identifier(auto: true))
  36. .field("name", .string)
  37. .field("description", .string)
  38. .field("isActive", .bool)
  39. .field("createDate", .datetime)
  40. .field("createUserId", .int)
  41. .field("updateDate", .datetime)
  42. .field("updateUserId", .int)
  43. .create()
  44. }
  45. func revert(on database: Database) async throws {
  46. try await database.schema("smscCode").delete()
  47. }
  48. }
  49. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlSMSCCode>{
  50. let query = mdlSMSCCode.query(on: req.db)
  51. // .with(\.$<#parent/children#>)
  52. if let x = req.parameters.get("x"){
  53. let decryptedString = try CustomCrypto.DecryptString(input: x)
  54. let array = decryptedString.components(separatedBy: ":")
  55. ///This call is the standard get by id call
  56. if (array.count == 1){
  57. let id = Int(array[0])!
  58. return query.filter(\.$id == id)
  59. }
  60. ///Optional else if if there are multiple parameters in the call
  61. ///You must include an else for each call that has parameters
  62. ///Need to check the endpoint to get the right filter statements
  63. ///else if(x.count == 2){
  64. /// let username = x[0]
  65. /// let password = x[1]
  66. /// return query.filter(\.$username == username).filter(\.$password == password)
  67. ///}
  68. else{
  69. throw Abort(.badRequest)
  70. }
  71. }
  72. else{
  73. return query
  74. }
  75. }
  76. }