Skip to content

Commit

Permalink
Game API?
Browse files Browse the repository at this point in the history
  • Loading branch information
silasary committed Aug 11, 2019
1 parent 6b3bf7b commit d30b982
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion logsite/api.py
Expand Up @@ -5,7 +5,7 @@
from shared_web.api import return_json, validate_api_key

from . import APP, importing
from .data import match
from .data import game, match


@APP.route('/api/admin/')
Expand All @@ -32,6 +32,10 @@ def match_exists(match_id: int) -> Response:
def match_data(match_id: int) -> Response:
return return_json(match.get_match(match_id))

@APP.route('/api/game/<game_id>')
def game_data(game_id: int) -> Response:
return return_json(game.get_game(game_id))

@APP.route('/api/upload', methods=['POST'])
def upload() -> Response:
error = validate_api_key()
Expand Down
11 changes: 11 additions & 0 deletions logsite/data/game.py
Expand Up @@ -22,11 +22,22 @@ def sanitized_log(self) -> str:
# If we want to remove chat, or OOB messages, do that here.
return self.log.strip()

def to_dict(self):
return {
'id': self.id,
'match_id': self.match_id,
'winner': self.winner,
'log': self.log,
}

def insert_game(game_id: int, match_id: int, game_lines: str) -> None:
local = Game(id=game_id, match_id=match_id, log=game_lines)
db.merge(local) # This will replace an old version of the game, if one exists.
db.commit()

def get_game(game_id: int) -> Game:
return Game.query.filter_by(id=game_id).one_or_none()

class Line(fsa.Model): #type: ignore
id = sa.Column(fsa.Integer, primary_key=True, autoincrement=True)
game_id = sa.Column(sa.Integer, sa.ForeignKey('game.id'), nullable=False)
Expand Down

0 comments on commit d30b982

Please sign in to comment.