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