aboutsummaryrefslogtreecommitdiff
path: root/routes/api.php
blob: 4cbbd6d2254b5164fb5a715028839b3fdd883e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Models\Currency;
use App\Models\Rates;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

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();
});