Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d58f0fda

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

#6638: Prejmenovana tabulka vozidla na vozidlo. Pridana zbyla implementace rest api. Pridany zbyle modely.

Zobrazit rozdíly:

backend/app/Http/Controllers/DeviceController.php
10 10

  
11 11
use App\Model\Device;
12 12
use App\Model\Zarizeni;
13
use App\Model\Zaznam;
13 14
use Illuminate\Http\Request;
14 15

  
15 16
class DeviceController extends Controller
16 17
{
17 18
    public function getDevice(Request $request) {
18
        $address='';
19
        $town = null;
20
        $street = null;
19 21
        $showDirection=0;
20 22
        if ($request->has('address')) {
21 23
            $address = $request->input('address');
24
            // todo: what is a format of address ?
25
            $addressParts = explode(";", $address);
26
            if (count($addressParts) == 2) {
27
                $town = $addressParts[0];
28
                $street = $addressParts[1];
29
            }
22 30
        }
23 31

  
24 32
        if ($request->has('showDirection')) {
25 33
            $showDirection = ($request->input('showDirection') === 1);
26 34
        }
27 35

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

  
34
//        return response()->json($device);
35
        return Zarizeni::findByAddressJoinAddress('Česká Kubice', 'Česká Kubice');
36
        return Zarizeni::findByAddressJoinAddress($street, $town);
36 37
    }
37 38

  
38 39
    /**
......
50 51
     */
51 52
    public function getDeviceById(Request $request, $id) {
52 53

  
53
        return Zarizeni::findByIdJoinAddress($id);
54
        $dateFrom = null;
55
        $dateTo = null;
56
        $timeFrom = null;
57
        $timeTo = null;
58
        $direction = null;
59

  
60
        // nacti parametry
61
        if ($request->has('dateFrom')) {
62
            $dateFrom = $request->input('dateFrom');
63
        }
64
        if ($request->has('dateTo')) {
65
            $dateTo = $request->input('dateTo');
66
        }
67
        if ($request->has('timeFrom')) {
68
            $timeFrom = $request->input('timeFrom');
69
        }
70
        if ($request->has('timeTo')) {
71
            $timeTo = $request->input('timeTo');
72
        }
73
        if ($request->has('direction')) {
74
            $direction = $request->input('direction');
75
        }
76

  
77
        $device = Zarizeni::findByIdJoinAddress($id);
78
        if ($device != null) {
79
            $device[0]->traffic = Zaznam::findByDevice($id, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction);
80
        }
81

  
82
        return $device;
54 83
    }
55 84

  
56 85
    public function getAll() {
57 86
        return Zarizeni::getAllJoinAddress();
58 87
    }
88

  
89
    public function lastDay() {
90
        return Zaznam::lastInsertedDate();
91
    }
59 92
}

Také k dispozici: Unified diff