diff --git a/custom_addons/encoach_exam_template/controllers/__pycache__/custom_exam.cpython-312.pyc b/custom_addons/encoach_exam_template/controllers/__pycache__/custom_exam.cpython-312.pyc index bb455e78..3fe8eb35 100644 Binary files a/custom_addons/encoach_exam_template/controllers/__pycache__/custom_exam.cpython-312.pyc and b/custom_addons/encoach_exam_template/controllers/__pycache__/custom_exam.cpython-312.pyc differ diff --git a/custom_addons/encoach_exam_template/controllers/custom_exam.py b/custom_addons/encoach_exam_template/controllers/custom_exam.py index 90e6ba5f..bd6eb9a9 100644 --- a/custom_addons/encoach_exam_template/controllers/custom_exam.py +++ b/custom_addons/encoach_exam_template/controllers/custom_exam.py @@ -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 # ------------------------------------------------------------------