EnCoach Odoo 19 custom modules

Full backend implementation with custom Odoo modules:
- encoach_api: Core API, user management, JWT auth
- encoach_exam: Exam generation (reading, writing, listening, speaking)
- encoach_evaluate: AI-powered evaluation (writing, speaking)
- encoach_training: Training tips and walkthrough
- encoach_storage: File storage management
- encoach_payment: Stripe, PayPal, Paymob integration
- encoach_mail: Email notifications

Made-with: Cursor
This commit is contained in:
Talal Sharabi
2026-03-14 16:46:46 +04:00
commit f5b627256f
168 changed files with 13428 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import json
import logging
from odoo import http
from odoo.http import request
from .base import EncoachMixin
_logger = logging.getLogger(__name__)
class SessionsController(EncoachMixin, http.Controller):
# -------------------------------------------------------------- save
@http.route('/api/sessions', type='http', auth='public', methods=['POST', 'OPTIONS'], csrf=False, cors='*')
def save_session(self, **kwargs):
try:
user = self._authenticate()
if not user:
return self._error_response('Unauthorized', 401)
body = self._get_json_body()
session_id = body.get('_id') or body.get('id')
Session = request.env['encoach.session'].sudo()
vals = {}
if body.get('examId'):
vals['exam_id'] = int(body['examId'])
if body.get('module'):
vals['module'] = body['module']
if body.get('answers') is not None:
vals['answers'] = json.dumps(body['answers']) if isinstance(body['answers'], dict) else body['answers']
if body.get('startedAt'):
vals['started_at'] = body['startedAt']
if body.get('completedAt'):
vals['completed_at'] = body['completedAt']
if body.get('assignmentId'):
vals['assignment_id'] = int(body['assignmentId'])
if session_id:
record = Session.browse(int(session_id))
if record.exists():
record.write(vals)
return self._json_response(self._serialize_session(record))
vals['user_id'] = user.id
record = Session.create(vals)
return self._json_response(self._serialize_session(record), status=201)
except Exception:
_logger.exception("Save session error")
return self._error_response('Internal server error', 500)
# ------------------------------------------------------------- delete
@http.route(
'/api/sessions/<int:sid>', type='http', auth='public',
methods=['DELETE', 'OPTIONS'], csrf=False, cors='*',
)
def delete_session(self, sid, **kwargs):
try:
user = self._authenticate()
if not user:
return self._error_response('Unauthorized', 401)
session = request.env['encoach.session'].sudo().browse(sid)
if not session.exists():
return self._error_response('Session not found', 404)
session.unlink()
return self._json_response({'ok': True})
except Exception:
_logger.exception("Delete session error")
return self._error_response('Internal server error', 500)