25 lines
886 B
Python
25 lines
886 B
Python
|
from flask_restx import Resource, Namespace
|
||
|
from app.functions.roll_dices import roll_dices
|
||
|
from app.models.models import dice_model
|
||
|
from app.schemas.schemas import DiceSchema
|
||
|
|
||
|
namespace = Namespace('dice', description='Dice Operations')
|
||
|
dice_model = namespace.model('Dice', dice_model)
|
||
|
dice_schema = DiceSchema()
|
||
|
|
||
|
|
||
|
@namespace.route('/') # resolves to: /dice
|
||
|
class RollDice(Resource):
|
||
|
@namespace.expect(dice_model)
|
||
|
def post(self):
|
||
|
data = namespace.payload
|
||
|
errors = dice_schema.validate(data)
|
||
|
if errors:
|
||
|
return errors, 400
|
||
|
quantity = data.get('quantity')
|
||
|
geometry = data.get('geometry')
|
||
|
discard_lowest = data.get('discard_lowest')
|
||
|
if quantity is None or geometry is None:
|
||
|
return {"message": "Required dice data not provided"}, 400
|
||
|
return roll_dices(quantity, geometry, discard_lowest), 200
|