gammatools/app/routes/character.py

29 lines
1.1 KiB
Python

from flask import request
from flask_restx import Resource, Namespace, reqparse
from app.functions.build_character_sheet import build_character_sheet
namespace = Namespace('rules', description='Gamma World Rules')
parser = reqparse.RequestParser()
parser.add_argument('chartype', type=str, default='Human',
help='The Character Type for the new character (human, humanoid, mutant, cyborg)')
@namespace.route('/character') # resolves to: /rules/character
class GenerateCharacter(Resource):
@namespace.expect(parser)
def get(self):
valid_chartypes = ["human", "humanoid", "mutant", "cyborg"]
chartype = request.args.get('chartype', default='Human', type=str)
if chartype:
if chartype.lower() in valid_chartypes:
return build_character_sheet(chartype.lower()), 200
else:
return {
'error': 'Invalid character type provided.',
'valid_chartypes': valid_chartypes
}, 400
else:
return {'error': 'No character type provided', 'valid_chartypes': valid_chartypes}, 400