2019-10-09 00:18:40 +00:00
|
|
|
from models.User import User, user_schema, users_schema
|
|
|
|
from models.GameRoom import GameRoom
|
|
|
|
from flask import Blueprint, request, jsonify, session
|
2019-10-09 05:53:37 +00:00
|
|
|
from ..decorators import jwt_required
|
2019-10-09 00:18:40 +00:00
|
|
|
|
|
|
|
api_rooms = Blueprint('api_rooms', __name__, url_prefix='/api/rooms')
|
|
|
|
|
2019-10-09 07:08:37 +00:00
|
|
|
@api_rooms.route('/<room_id>', methods=['GET'])
|
2019-10-09 00:18:40 +00:00
|
|
|
def get_room():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@api_rooms.route('/', methods=['GET'])
|
|
|
|
def get_rooms():
|
|
|
|
response = {"status" : "success"}
|
|
|
|
return jsonify(response)
|
|
|
|
|
|
|
|
# protected route
|
|
|
|
@api_rooms.route('/', methods=['POST'])
|
2019-10-09 05:53:37 +00:00
|
|
|
@jwt_required()
|
2019-10-09 00:18:40 +00:00
|
|
|
def post_room():
|
2019-10-09 05:53:37 +00:00
|
|
|
data = request.get_json()
|
|
|
|
try:
|
|
|
|
room = GameRoom(
|
|
|
|
name = data['name'],
|
|
|
|
description = data['description'],
|
|
|
|
private = data['private'],
|
|
|
|
language = data['language']
|
|
|
|
)
|
|
|
|
db.session.add(room)
|
|
|
|
db.session.commit()
|
|
|
|
response = {
|
|
|
|
'status': 'success',
|
|
|
|
'message': 'Succesfully registered.',
|
|
|
|
'gameRoom': room.id
|
|
|
|
}
|
|
|
|
return jsonify(response), 201
|
|
|
|
except Exception as e:
|
|
|
|
print(e.__dict__)
|
|
|
|
response = {
|
|
|
|
'status': 'fail',
|
|
|
|
'message': 'There was an error. Please try again.'
|
|
|
|
}
|
|
|
|
return jsonify(response), 401
|