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:
122
encoach_api/controllers/classrooms.py
Normal file
122
encoach_api/controllers/classrooms.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import logging
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
from .base import EncoachMixin
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ClassroomsController(EncoachMixin, http.Controller):
|
||||
|
||||
# --------------------------------------------------------------- list
|
||||
@http.route('/api/groups', type='http', auth='public', methods=['GET', 'OPTIONS'], csrf=False, cors='*')
|
||||
def list_groups(self, **kwargs):
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
domain = []
|
||||
participant = kwargs.get('participant')
|
||||
if participant:
|
||||
domain.append(('participant_ids', 'in', [int(participant)]))
|
||||
|
||||
admin = kwargs.get('admin')
|
||||
if admin:
|
||||
domain.append(('admin_ids', 'in', [int(admin)]))
|
||||
|
||||
entity_id = kwargs.get('entityID')
|
||||
if entity_id:
|
||||
domain.append(('entity_id', '=', int(entity_id)))
|
||||
|
||||
groups = request.env['encoach.group'].sudo().search(domain, order='name asc')
|
||||
return self._json_response([self._serialize_group(g) for g in groups])
|
||||
except Exception:
|
||||
_logger.exception("List groups error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
|
||||
# -------------------------------------------------------------- create
|
||||
@http.route('/api/groups', type='http', auth='public', methods=['POST', 'OPTIONS'], csrf=False, cors='*')
|
||||
def create_group(self, **kwargs):
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
body = self._get_json_body()
|
||||
if not body.get('name'):
|
||||
return self._error_response('Group name is required', 400)
|
||||
|
||||
vals = {
|
||||
'name': body['name'],
|
||||
'admin_ids': [(4, user.id)],
|
||||
}
|
||||
if body.get('entityID'):
|
||||
vals['entity_id'] = int(body['entityID'])
|
||||
|
||||
participant_ids = body.get('participants', [])
|
||||
if participant_ids:
|
||||
vals['participant_ids'] = [(4, int(pid)) for pid in participant_ids]
|
||||
|
||||
group = request.env['encoach.group'].sudo().create(vals)
|
||||
return self._json_response(self._serialize_group(group), status=201)
|
||||
except Exception:
|
||||
_logger.exception("Create group error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
|
||||
# -------------------------------------------------------------- update
|
||||
@http.route(
|
||||
'/api/groups/<int:group_id>', type='http', auth='public',
|
||||
methods=['PATCH', 'OPTIONS'], csrf=False, cors='*',
|
||||
)
|
||||
def update_group(self, group_id, **kwargs):
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
group = request.env['encoach.group'].sudo().browse(group_id)
|
||||
if not group.exists():
|
||||
return self._error_response('Group not found', 404)
|
||||
|
||||
body = self._get_json_body()
|
||||
vals = {}
|
||||
if 'name' in body:
|
||||
vals['name'] = body['name']
|
||||
|
||||
if 'participants' in body:
|
||||
vals['participant_ids'] = [(6, 0, [int(pid) for pid in body['participants']])]
|
||||
|
||||
if 'admins' in body:
|
||||
vals['admin_ids'] = [(6, 0, [int(aid) for aid in body['admins']])]
|
||||
|
||||
if vals:
|
||||
group.write(vals)
|
||||
|
||||
return self._json_response(self._serialize_group(group))
|
||||
except Exception:
|
||||
_logger.exception("Update group error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
|
||||
# -------------------------------------------------------------- delete
|
||||
@http.route(
|
||||
'/api/groups/<int:group_id>', type='http', auth='public',
|
||||
methods=['DELETE', 'OPTIONS'], csrf=False, cors='*',
|
||||
)
|
||||
def delete_group(self, group_id, **kwargs):
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
group = request.env['encoach.group'].sudo().browse(group_id)
|
||||
if not group.exists():
|
||||
return self._error_response('Group not found', 404)
|
||||
|
||||
group.unlink()
|
||||
return self._json_response({'ok': True})
|
||||
except Exception:
|
||||
_logger.exception("Delete group error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
Reference in New Issue
Block a user