Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1123608c

Přidáno uživatelem Cajova-Houba před téměř 7 roky(ů)

#6638: Odebrany stare endpointy REST api, pridany nove podle navrhu z #6635.

Zobrazit rozdíly:

backend/app/Http/Controllers/DeviceController.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Zdenda
5
 * Date: 20.4.2018
6
 * Time: 20:09
7
 */
8

  
9
namespace App\Http\Controllers;
10

  
11
use App\Model\Device;
12
use Illuminate\Http\Request;
13

  
14
class DeviceController extends Controller
15
{
16
    public function getDevice(Request $request) {
17
        $address='';
18
        $showDirection=0;
19
        if ($request->has('address')) {
20
            $address = $request->input('address');
21
        }
22

  
23
        if ($request->has('showDirection')) {
24
            $showDirection = ($request->input('showDirection') === 1);
25
        }
26

  
27
        $device = new Device();
28
        $device->id = 1;
29
        $device->name = 'device';
30
        $device->street = $address;
31
        $device->town = $address;
32

  
33
        return response()->json($device);
34
    }
35

  
36
    /**
37
     * Vrati zarizeni podle id.
38
     * Url parametry:
39
     * dateFrom
40
     * dateTo
41
     * timeFrom
42
     * timeTo
43
     * direction
44
     *
45
     * @param Request $request
46
     * @param $id
47
     * @return \Symfony\Component\HttpFoundation\Response
48
     */
49
    public function getDeviceById(Request $request, $id) {
50

  
51

  
52
        $device = new Device();
53
        $device->id = $id;
54
        $device->name = 'device';
55
        $device->street = 'street';
56
        $device->town = 'town';
57

  
58
        return response()->json($device);
59
    }
60
}
backend/app/Http/Controllers/VehicleController.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Zdenda
5
 * Date: 20.4.2018
6
 * Time: 20:25
7
 */
8

  
9
namespace App\Http\Controllers;
10

  
11

  
12
use App\Model\Vehicle;
13

  
14
class VehicleController extends Controller
15
{
16
    /**
17
     * Vrati vsechny typy vozidel.
18
     */
19
    public function getAll() {
20
        $vehicles = [
21
            0 => Vehicle::create(0, 'neznámé'),
22
            1 => Vehicle::create(1, 'motocykl'),
23
            2 => Vehicle::create(2, 'osobní auto'),
24
            3 => Vehicle::create(4, 'dodávka')
25
        ];
26

  
27
        return $vehicles;
28
    }
29
}
backend/app/Http/routes.php
11 11
|
12 12
*/
13 13

  
14
$app->get('/', function () use ($app) {
15
    return $app->version();
16
});
14
$apiUrlRoot='/api/v1/';
17 15

  
18
$app->get('/hello', function() {
19
    return "world!";
16
$app->get('/', function ()  {
17
    return 'Funguje to.';
20 18
});
21 19

  
22
$app->get('/location', 'LocationController@getLocation');
20
/**
21
 * Parametry v url:
22
 * address
23
 * showDirection
24
 */
25
$app->get($apiUrlRoot.'devices', 'DeviceController@getDevice');
26

  
27
/**
28
 * Parametry v url:
29
 * dateFrom
30
 * dateTo
31
 * timeFrom
32
 * timeTo
33
 * direction
34
 */
35
$app->get($apiUrlRoot.'devices/{id}', 'DeviceController@getDeviceById');
23 36

  
24
$app->get('/location/{id}', 'LocationController@findById');
37
/**
38
 * Vrati vsechny typy aut.
39
 */
40
$app->get($apiUrlRoot.'vehicles', 'VehicleController@getAll');
backend/app/Model/Device.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Zdenda
5
 * Date: 20.4.2018
6
 * Time: 20:08
7
 */
8

  
9
namespace App\Model;
10

  
11

  
12
class Device
13
{
14
    public $id;
15
    public $street;
16
    public $town;
17
    public $name;
18

  
19
    public function __construct() {
20
    }
21
}
backend/app/Model/Vehicle.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Zdenda
5
 * Date: 20.4.2018
6
 * Time: 20:25
7
 */
8

  
9
namespace App\Model;
10

  
11

  
12
class Vehicle
13
{
14
    public $id;
15
    public $name;
16

  
17
    public static function create($id, $name) {
18
        $inst = new Vehicle();
19
        $inst->id = $id;
20
        $inst->name = $name;
21

  
22
        return $inst;
23
    }
24
}

Také k dispozici: Unified diff