Browse Source

Added endpoint to fetch total downloads number.

Frank de Jonge 6 years ago
parent
commit
c4ab136fde
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/Packagist/WebBundle/Controller/WebController.php

+ 11 - 0
src/Packagist/WebBundle/Controller/WebController.php

@@ -288,6 +288,17 @@ class WebController extends Controller
         );
     }
 
+    /**
+     * @Route("/statistics.json", name="stats_json", defaults={"_format"="json"}, methods={"GET"})
+     */
+    public function statsTotalsAction()
+    {
+        $downloads = $this->get('snc_redis.default_client')->get('downloads') ?: 0;
+        $totals = ['downloads' => $downloads];
+
+        return new JsonResponse(['totals' => $totals], 200);
+    }
+
     /**
      * @param Request $req
      *