|
@@ -1,24 +1,29 @@
|
|
import Vapor
|
|
import Vapor
|
|
|
|
|
|
final class Fortune: Model {
|
|
final class Fortune: Model {
|
|
-
|
|
|
|
|
|
+
|
|
static let entity = "fortune"
|
|
static let entity = "fortune"
|
|
-
|
|
|
|
|
|
+
|
|
var mongoId: Node?
|
|
var mongoId: Node?
|
|
var id: Node?
|
|
var id: Node?
|
|
var message: String
|
|
var message: String
|
|
-
|
|
|
|
|
|
+
|
|
static var idKey = "_id"
|
|
static var idKey = "_id"
|
|
-
|
|
|
|
|
|
+
|
|
// For internal Vapor use
|
|
// For internal Vapor use
|
|
var exists: Bool = false
|
|
var exists: Bool = false
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ init(id: Int, message: String) {
|
|
|
|
+ self.id = Node(id)
|
|
|
|
+ self.message = message
|
|
|
|
+ }
|
|
|
|
+
|
|
init(node: Node, in context: Context) throws {
|
|
init(node: Node, in context: Context) throws {
|
|
id = try node.extract("_id")
|
|
id = try node.extract("_id")
|
|
mongoId = try node.extract("id")
|
|
mongoId = try node.extract("id")
|
|
message = try node.extract("message")
|
|
message = try node.extract("message")
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
func makeNode(context: Context) throws -> Node {
|
|
func makeNode(context: Context) throws -> Node {
|
|
return try Node(node: [
|
|
return try Node(node: [
|
|
"id": mongoId,
|
|
"id": mongoId,
|
|
@@ -26,28 +31,28 @@ final class Fortune: Model {
|
|
"message": message
|
|
"message": message
|
|
])
|
|
])
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
func makeJSONNode() throws -> Node {
|
|
func makeJSONNode() throws -> Node {
|
|
return try Node(node: [
|
|
return try Node(node: [
|
|
"id": id?.int,
|
|
"id": id?.int,
|
|
"message": message
|
|
"message": message
|
|
])
|
|
])
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
func makeJSON() throws -> JSON {
|
|
func makeJSON() throws -> JSON {
|
|
let node = try makeJSONNode()
|
|
let node = try makeJSONNode()
|
|
return try JSON(node: node)
|
|
return try JSON(node: node)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
static func prepare(_ database: Database) throws {
|
|
static func prepare(_ database: Database) throws {
|
|
try database.create("Fortune") { fortune in
|
|
try database.create("Fortune") { fortune in
|
|
fortune.id("id")
|
|
fortune.id("id")
|
|
fortune.string("message")
|
|
fortune.string("message")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
static func revert(_ database: Database) throws {
|
|
static func revert(_ database: Database) throws {
|
|
try database.delete("Fortune")
|
|
try database.delete("Fortune")
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|