api student
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
import json
|
||||
|
||||
class StudentAPI(http.Controller):
|
||||
@http.route('/student/students', type='http', auth='none', methods=['GET'])
|
||||
def get_students(self, **kwargs):
|
||||
token = kwargs.get('token')
|
||||
valid_token = 'token_123'
|
||||
|
||||
if not token or token != valid_token:
|
||||
return {
|
||||
'error': 'Unauthorized',
|
||||
"message": "Invalid API token"
|
||||
}, 401
|
||||
|
||||
students = request.env['student.student'].sudo().search([])
|
||||
student_list = []
|
||||
|
||||
for student in students:
|
||||
student_list.append({
|
||||
'id': student.id,
|
||||
'name': student.name,
|
||||
'email': student.email,
|
||||
'gender': student.gender,
|
||||
'phone': student.phone,
|
||||
})
|
||||
|
||||
return json.dumps({'students': student_list}, ensure_ascii=False)
|
||||
Reference in New Issue
Block a user