28 lines
801 B
Python
28 lines
801 B
Python
from flask import request, jsonify
|
|
from flask.views import MethodView
|
|
from services.session_service import SessionService
|
|
|
|
|
|
class SessionController(MethodView):
|
|
def __init__(self, session_service: SessionService):
|
|
self.session_service = session_service
|
|
|
|
def createRoom(self, data):
|
|
|
|
required_fields = [
|
|
"quiz_id",
|
|
"host_id",
|
|
"limit_participan",
|
|
]
|
|
for field in required_fields:
|
|
if field not in data:
|
|
return jsonify({"error": f"Missing field: {field}"}), 400
|
|
|
|
session = self.session_service.create_session(
|
|
quiz_id=data["quiz_id"],
|
|
host_id=data["host_id"],
|
|
limit_participan=data["limit_participan"],
|
|
)
|
|
|
|
return jsonify(session.dict()), 201
|