<commit_before>import Vapor
import FluentProvider
import HTTP

final class Game: Model {
    let storage = Storage()

    // MARK: Properties and database keys

    /// The column names for `id` and `content` in the database
    struct Keys {
        static let idKey       = "id"
        static let teamPlayers = "team_players"
        static let startTime   = "start_time"
        static let finished    = "finished"
    }

    enum TeamPlayersCount: Int {
        case one = 1
        case two
    }

    var teamPlayers: TeamPlayersCount
    var startTime: Date
    var finished: Bool

    /// Creates a new Post
    init(teamPlayers: Int,
         startTime: Date,
         finished: Bool) throws {
        guard let playersCount = TeamPlayersCount(rawValue: teamPlayers) else {
            throw Abort(.badRequest)
        }
        self.teamPlayers = playersCount
        self.startTime = startTime
        self.finished = finished
    }

    // MARK: Fluent Serialization

    /// Initializes the Post from the
    /// database row
    init(row: Row) throws {
        teamPlayers = try row.get(Game.Keys.teamPlayers)
        startTime = try row.get(Game.Keys.startTime)
        finished = try row.get(Game.Keys.finished)
    }

    // Serializes the Post to the database
    func makeRow() throws -> Row {
        var row = Row()
        try row.set(Game.Keys.teamPlayers, teamPlayers.rawValue)
        try row.set(Game.Keys.startTime, startTime)
        try row.set(Game.Keys.finished, finished)
        return row
    }
}

// MARK: Fluent Preparation

extension Game: Preparation {
    /// Prepares a table/collection in the database
    /// for storing Posts
    static func prepare(_ database: Database) throws {
        try database.create(self) { builder in
            builder.id()
            builder.int(Game.Keys.teamPlayers)
            builder.date(Game.Keys.startTime)
            builder.bool(Game.Keys.finished, default: false)
        }
    }

    /// Undoes what was done in `prepare`
    static func revert(_ database: Database) throws {
        try database.delete(self)
    }
}

// MARK: JSON

// How the model converts from / to JSON.
// For example when:
//     - Creating a new Post (POST /posts)
//     - Fetching a post (GET /posts, GET /posts/:id)
//
extension Game: JSONConvertible {
    convenience init(json: JSON) throws {
        try self.init(
            teamPlayers: json.get(Game.Keys.teamPlayers),
            startTime: json.get(Game.Keys.startTime),
            finished: json.get(Game.Keys.finished)
        )
    }

    func makeJSON() throws -> JSON {
        var json = JSON()
        try json.set(Game.Keys.idKey, id)
        try json.set(Game.Keys.teamPlayers, teamPlayers.rawValue)
        try json.set(Game.Keys.startTime, startTime)
        try json.set(Game.Keys.finished, finished)
        return json
    }
}

extension Game: Timestampable { }

// MARK: HTTP

// This allows Post models to be returned
// directly in route closures
extension Game: ResponseRepresentable { }

extension Game: Updateable {

    // Updateable keys are called when `post.update(for: req)` is called.
    // Add as many updateable keys as you like here.
    static var updateableKeys: [UpdateableKey<Game>] {
        return [
            // If the request contains a String at key "content"
            // the setter callback will be called.
            UpdateableKey(Game.Keys.startTime, Date.self) { game, value in
                game.startTime = value
            },
            UpdateableKey(Game.Keys.finished, Bool.self) { game, value in
                game.finished = value
            }
        ]
    }
}



<commit_msg>Change team player type to int<commit_after>import Vapor
import FluentProvider
import HTTP

final class Game: Model {
    let storage = Storage()

    // MARK: Properties and database keys

    /// The column names for `id` and `content` in the database
    struct Keys {
        static let idKey       = "id"
        static let teamPlayers = "team_players"
        static let startTime   = "start_time"
        static let finished    = "finished"
    }

    var teamPlayers: Int
    var startTime: Date
    var finished: Bool

    /// Creates a new Post
    init(teamPlayers: Int,
         startTime: Date,
         finished: Bool) {
        self.teamPlayers = teamPlayers
        self.startTime = startTime
        self.finished = finished
    }

    // MARK: Fluent Serialization

    /// Initializes the Post from the
    /// database row
    init(row: Row) throws {
        teamPlayers = try row.get(Game.Keys.teamPlayers)
        startTime = try row.get(Game.Keys.startTime)
        finished = try row.get(Game.Keys.finished)
    }

    // Serializes the Post to the database
    func makeRow() throws -> Row {
        var row = Row()
        try row.set(Game.Keys.teamPlayers, teamPlayers)
        try row.set(Game.Keys.startTime, startTime)
        try row.set(Game.Keys.finished, finished)
        return row
    }
}

// MARK: Fluent Preparation

extension Game: Preparation {
    /// Prepares a table/collection in the database
    /// for storing Posts
    static func prepare(_ database: Database) throws {
        try database.create(self) { builder in
            builder.id()
            builder.int(Game.Keys.teamPlayers)
            builder.date(Game.Keys.startTime)
            builder.bool(Game.Keys.finished, default: false)
        }
    }

    /// Undoes what was done in `prepare`
    static func revert(_ database: Database) throws {
        try database.delete(self)
    }
}


// MARK: JSON

// How the model converts from / to JSON.
// For example when:
//     - Creating a new Post (POST /posts)
//     - Fetching a post (GET /posts, GET /posts/:id)
//
extension Game: JSONConvertible {
    convenience init(json: JSON) throws {
        try self.init(
            teamPlayers: json.get(Game.Keys.teamPlayers),
            startTime: json.get(Game.Keys.startTime),
            finished: json.get(Game.Keys.finished)
        )
    }

    func makeJSON() throws -> JSON {
        var json = JSON()
        try json.set(Game.Keys.idKey, id)
        try json.set(Game.Keys.teamPlayers, teamPlayers)
        try json.set(Game.Keys.startTime, startTime)
        try json.set(Game.Keys.finished, finished)
        return json
    }
}

extension Game: Timestampable { }

// MARK: HTTP

// This allows Post models to be returned
// directly in route closures
extension Game: ResponseRepresentable { }

extension Game: Updateable {

    // Updateable keys are called when `post.update(for: req)` is called.
    // Add as many updateable keys as you like here.
    static var updateableKeys: [UpdateableKey<Game>] {
        return [
            // If the request contains a String at key "content"
            // the setter callback will be called.
            UpdateableKey(Game.Keys.startTime, Date.self) { game, value in
                game.startTime = value
            },
            UpdateableKey(Game.Keys.finished, Bool.self) { game, value in
                game.finished = value
            }
        ]
    }
}




{'fraction_non_alphanumeric': 0.09499014916971574, 'fraction_numerical': 0.00014072614691809738, 'mean_word_length': 2.0554600171969044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '6174438', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1960, 'n_words': 616}