ProgressController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\ProgressChapter;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Response;
  6. class ProgressController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return Response
  12. */
  13. public function index(Request $request)
  14. {
  15. //
  16. $select = ['book', 'para', 'lang', 'progress', 'channel_id', 'title', 'last_chapter_completed_at', 'updated_at'];
  17. switch ($request->input('view')) {
  18. case 'channel':
  19. $table = ProgressChapter::select($select)
  20. ->whereIn('channel_id', explode('_', $request->input('channels', '')));
  21. break;
  22. default:
  23. return $this->error('invalid view', 400, 400);
  24. break;
  25. }
  26. if ($request->has('lang')) {
  27. $table = $table->where('lang', $request->input('lang'));
  28. }
  29. if ($request->has('book')) {
  30. $table = $table->where('book', $request->input('book'));
  31. }
  32. $count = $table->count();
  33. $table = $table->orderBy(
  34. $request->input('order', 'completed_at'),
  35. $request->input('dir', 'desc')
  36. );
  37. $table = $table->skip($request->input('offset', 0))
  38. ->take($request->input('limit', 10));
  39. $result = $table->get();
  40. return $this->ok(
  41. [
  42. 'rows' => $result->toArray(),
  43. 'total' => $count,
  44. ]
  45. );
  46. }
  47. /**
  48. * Store a newly created resource in storage.
  49. */
  50. public function store(Request $request)
  51. {
  52. //
  53. }
  54. /**
  55. * Display the specified resource.
  56. */
  57. public function show(string $id)
  58. {
  59. //
  60. }
  61. /**
  62. * Update the specified resource in storage.
  63. */
  64. public function update(Request $request, string $id)
  65. {
  66. //
  67. }
  68. /**
  69. * Remove the specified resource from storage.
  70. */
  71. public function destroy(string $id)
  72. {
  73. //
  74. }
  75. }