From 0d2180d9b488219e570d354d11ec3782f1b46024 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Tue, 2 Aug 2022 18:38:01 -0400 Subject: add a chart --- routes/api.php | 25 ++++++++++++++++++++++--- routes/web.php | 5 ++++- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'routes') diff --git a/routes/api.php b/routes/api.php index eb6fa48..4cbbd6d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,7 +2,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; - +use App\Models\Currency; +use App\Models\Rates; /* |-------------------------------------------------------------------------- | API Routes @@ -14,6 +15,24 @@ use Illuminate\Support\Facades\Route; | */ -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { - return $request->user(); +Route::get('rateseries/{name}', function(Request $request, $name) { + // If the Content-Type and Accept headers are set to 'application/json', + // this will return a JSON structure. This will be cleaned up later. + + $ret = array(); + + $currency = Currency::Where('name', $name)->first(); + + $rates = Rates::where('currency_id', $currency->id)->get(); + foreach($rates as $rate) { + $ret[] = ['x' => strtotime($rate->updated_at), 'y' => $rate->value]; + } + + return $ret; +}); + +Route::get('currency', function() { + // If the Content-Type and Accept headers are set to 'application/json', + // this will return a JSON structure. This will be cleaned up later. + return Currency::all(); }); diff --git a/routes/web.php b/routes/web.php index 9396c11..c7be55c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,7 +30,10 @@ Route::get('/', function () { $rates = new Collection(); foreach($ratesRaw as $r) { - $rates->push(Rates::find($r->id)); + $rate = Rates::find($r->id); + if($rate->currency->name != "Bitcoin") { + $rates->push($rate); + } } return view('welcome', ['currencies' => Currency::all(), 'rates' => $rates]); }); -- cgit v1.2.3