feat: add GET /api/exam/custom/list endpoint for Exams List page

- Lists custom exams with pagination, search, and status filter
- Returns exam sections for module badge display

Made-with: Cursor
This commit is contained in:
Yamen Ahmad
2026-04-12 11:07:38 +04:00
parent 953879d19a
commit 6df81afbf4
2 changed files with 31 additions and 0 deletions

View File

@@ -43,6 +43,37 @@ def _exam_to_dict(exam):
class EncoachCustomExamController(http.Controller):
# ------------------------------------------------------------------
# GET /api/exam/custom/list
# ------------------------------------------------------------------
@http.route('/api/exam/custom/list', type='http', auth='none',
methods=['GET'], csrf=False)
@jwt_required
def list_exams(self, **kw):
try:
Exam = request.env['encoach.exam.custom'].sudo()
search = kw.get('search', '').strip()
domain = []
if search:
domain = [('title', 'ilike', search)]
status = kw.get('status', '').strip()
if status:
domain.append(('status', '=', status))
total = Exam.search_count(domain)
page, per_page, offset = _paginate(kw)
exams = Exam.search(domain, limit=per_page, offset=offset,
order='id desc')
return _json_response({
'items': [_exam_to_dict(e) for e in exams],
'total': total,
'page': page,
'per_page': per_page,
})
except Exception as e:
_logger.exception('custom exam list failed')
return _error_response(str(e), 500)
# ------------------------------------------------------------------
# POST /api/exam/custom/create
# ------------------------------------------------------------------