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:
Binary file not shown.
@@ -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
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user