serve gamerooms index
This commit is contained in:
parent
254655eed4
commit
e6fa8a7e31
2 changed files with 22 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
from flask import Blueprint, request, jsonify, session
|
from flask import Blueprint, request, jsonify, session
|
||||||
from models.User import User, user_schema, users_schema
|
from models.User import User, user_schema, users_schema
|
||||||
from models.GameRoom import GameRoom
|
from models.GameRoom import GameRoom, rooms_schema, room_schema
|
||||||
from database import db
|
from database import db
|
||||||
from ..decorators import jwt_required
|
from ..decorators import jwt_required
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ def get_room():
|
||||||
|
|
||||||
@api_rooms.route('/', methods=['GET'])
|
@api_rooms.route('/', methods=['GET'])
|
||||||
def get_rooms():
|
def get_rooms():
|
||||||
response = {"status" : "success"}
|
rooms = GameRoom.query.all()
|
||||||
|
response = rooms_schema.dumps(rooms)
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
# protected route
|
# protected route
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
|
from marshmallow import fields
|
||||||
# TODO User >---< GameRoom
|
# TODO User >---< GameRoom
|
||||||
|
|
||||||
# ! Game Room >-< Users join table
|
# ! Game Room >-< Users join table
|
||||||
|
@ -40,3 +41,21 @@ class GameRoom(db.Model):
|
||||||
self.description = description
|
self.description = description
|
||||||
self.private = private
|
self.private = private
|
||||||
self.language = language
|
self.language = language
|
||||||
|
|
||||||
|
class LanguageSchema(ma.ModelSchema):
|
||||||
|
id = fields.Int()
|
||||||
|
name = fields.Str()
|
||||||
|
iso = fields.Str()
|
||||||
|
|
||||||
|
language_schema = LanguageSchema()
|
||||||
|
|
||||||
|
class RoomSchema(ma.ModelSchema):
|
||||||
|
id = fields.Int()
|
||||||
|
name = fields.Str()
|
||||||
|
description = fields.Str()
|
||||||
|
private = fields.Bool()
|
||||||
|
language = fields.Nested(LanguageSchema)
|
||||||
|
|
||||||
|
|
||||||
|
room_schema = RoomSchema()
|
||||||
|
rooms_schema = RoomSchema(many=True)
|
Loading…
Reference in a new issue