gammatools/app/routes/get_creature.py

19 lines
745 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, 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):
creature = request.args.get('creature', default=None, type=str)
if creature is None:
return {'error': 'Provide the name of a Gamma World creature to search for'}, 400
creatures = Creatures()
return creatures.get_creature(creature), 200