<commit_before>import Vapor
import HTTP
import FluentMongo

//demo code
/*
 let drop = Droplet()
 
 drop.get { req in
 return try drop.view.make("welcome", [
 "message": drop.localization[req.lang, "welcome", "title"]
 ])
 }
 
 drop.resource("posts", PostController())
 
 drop.run()
 */

//参考 https://segmentfault.com/a/1190000008421393?utm_source=tuicool&utm_medium=referral
final class UserMongoDB: Model {
    var exists: Bool = false
    
    var id: Node?
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        name = try node.extract("name")
    }
    
    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            "name": name
            ])
    }
    
    static func prepare(_ database: Database) throws {
        try database.create("users") { users in
            users.id()
            users.string("name")
        }
    }
    
    static func revert(_ database: Database) throws {
        try database.delete("users")
    }
}

let mongo = try MongoDriver(database: "fox-db", user: "fox", password: "<PASSWORD>", host: "ds023052.mlab.com", port: 23052)
let db = Database(mongo)
let drop = Droplet()
drop.database = db
drop.preparations.append(UserMongoDB.self)

drop.post("login"){ req in
    guard let name = req.data["name"]?.string else{
        throw Abort.badRequest
    }
    var abc = UserMongoDB(name: name)
    try abc.save()
    return abc
}

drop.get("login"){req in
    // var abc = UserMongoDB(name: "abcdefg")
    // try abc.save()
    //    return try JSON(["memo":"mongoDB result id:\(abc.id!), name:\(abc.name)])
    return try JSON(["memo":"另可用postman测试post方法, Headers空，Body参数为name=xx"])
}

drop.get("index"){
    return try drop.view.make("welcome", ["message": "hello vapor"])
}

drop.run()
<commit_msg>test html/leaf file<commit_after>import Vapor
import HTTP
import FluentMongo

//demo code
/*
 let drop = Droplet()
 
 drop.get { req in
 return try drop.view.make("welcome", [
 "message": drop.localization[req.lang, "welcome", "title"]
 ])
 }
 
 drop.resource("posts", PostController())
 
 drop.run()
 */

//参考 https://segmentfault.com/a/1190000008421393?utm_source=tuicool&utm_medium=referral
final class UserMongoDB: Model {
    var exists: Bool = false
    
    var id: Node?
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        name = try node.extract("name")
    }
    
    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            "name": name
            ])
    }
    
    static func prepare(_ database: Database) throws {
        try database.create("users") { users in
            users.id()
            users.string("name")
        }
    }
    
    static func revert(_ database: Database) throws {
        try database.delete("users")
    }
}

let mongo = try MongoDriver(database: "fox-db", user: "fox", password: "<PASSWORD>", host: "ds023052.mlab.com", port: 23052)
let db = Database(mongo)
let drop = Droplet()
drop.database = db
drop.preparations.append(UserMongoDB.self)

drop.post("login"){ req in
    guard let name = req.data["name"]?.string else{
        throw Abort.badRequest
    }
    var abc = UserMongoDB(name: name)
    try abc.save()
    return abc
}

drop.get("login"){req in
    // var abc = UserMongoDB(name: "abcdefg")
    // try abc.save()
    //    return try JSON(["memo":"mongoDB result id:\(abc.id!), name:\(abc.name)])
    return try JSON(["memo":"另可用postman测试post方法, Headers空，Body参数为name=xx!!!!!!!!!!!"])
}

drop.get("index"){
    return try drop.view.make("welcome", ["message": "hello vapor"])
}

drop.get("index2"){
    return try drop.view.make("welcome", ["message": "hello vapor index2"])
}

drop.run()

{'fraction_non_alphanumeric': 0.15199797673242285, 'fraction_numerical': 0.014162873039959535, 'mean_word_length': 2.720602069614299, 'pattern_counts': {'":': 13, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5410711', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1320, 'n_words': 318}