leonsuke

StudentAPIController

Apr 3rd, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. 'use strict'
  2. const Students = use('App/Models/Student')
  3.  
  4. class StudentAPIController {
  5. async index({ response }) {
  6. let student = await Students.all();
  7.  
  8. return response.json(student);
  9. }
  10.  
  11.  
  12. async show({ params, response }) {
  13. const student_detail = await Students.find(params.student_id)
  14.  
  15. if (!student_detail) {
  16. return response.json({
  17. code: '404',
  18. message: 'User not found'
  19. })
  20. }
  21.  
  22. return response.json({
  23. 'data': student_detail
  24. })
  25. }
  26. }
  27.  
  28. module.exports = StudentAPIController
Advertisement
Add Comment
Please, Sign In to add comment