26 lines
987 B
Python
26 lines
987 B
Python
from flask import request
|
|
from flask_restx import Resource, Namespace
|
|
|
|
from app.functions.build_character_sheet import build_character_sheet
|
|
|
|
namespace = Namespace('rules', description='Gamma World Rules')
|
|
|
|
VALID_CHARTYPES = ["human", "humanoid", "mutant", "cyborg"]
|
|
|
|
|
|
@namespace.route('/character') # resolves to: /rules/character
|
|
class GenerateCharacter(Resource):
|
|
@namespace.doc(params={'chartype': 'The Character Type for the new character'})
|
|
def get(self):
|
|
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
|