gammatools/app/routes/get_creature.py

20 lines
722 B
Python
Raw Normal View History

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()
2024-07-03 13:52:13 +00:00
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):
2024-07-03 13:52:13 +00:00
creatures = Creatures()
creature = request.args.get('creature', default=None, type=str)
if creature is None:
2024-07-03 13:52:13 +00:00
return creatures.get_creature_list(), 200
return creatures.get_creature(creature), 200
2024-07-03 13:52:13 +00:00