gammatools/app/routes/get_creature.py

20 lines
722 B
Python

from flask import request
from flask_restx import Resource, Namespace, reqparse
from app.tables.creature import Creatures
namespace = Namespace('rules', description='Gamma World Rules')
parser = reqparse.RequestParser()
parser.add_argument('creature', type=str, required=False, help='the name of a Gamma World creature to search for.')
@namespace.route('/creature') # resolves to: /rules/creature
class RollEncounter(Resource):
@namespace.expect(parser)
def get(self):
creatures = Creatures()
creature = request.args.get('creature', default=None, type=str)
if creature is None:
return creatures.get_creature_list(), 200
return creatures.get_creature(creature), 200