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 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'routes/api.php') 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(); }); -- cgit v1.2.3