You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Twitter;
  5. use App\Tweet;
  6. use App\Events\NewTweetEvent, App\Events\TweetClaimedEvent;
  7. class DashboardController extends Controller
  8. {
  9. /**
  10. * Create a new controller instance.
  11. *
  12. * @return void
  13. */
  14. public function __construct()
  15. {
  16. $this->middleware('auth');
  17. }
  18. /**
  19. * Show the application dashboard.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function index()
  24. {
  25. return view('dashboard', [
  26. ]);
  27. }
  28. public function queue() {
  29. Tweet::claimed_timeout();
  30. $tweets = Tweet::queued()->get();
  31. $queue = [];
  32. foreach($tweets as $tweet) {
  33. $queue[] = new NewTweetEvent($tweet);
  34. }
  35. return response()->json(['queue'=>$queue]);
  36. }
  37. public function claim_tweet(Request $request) {
  38. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  39. if($tweet) {
  40. $tweet->claimed_at = date('Y-m-d H:i:s');
  41. $tweet->save();
  42. // Broadcast that this tweet was claimed
  43. event(new TweetClaimedEvent($tweet));
  44. }
  45. return response()->json(['result'=>'ok']);
  46. }
  47. }