summaryrefslogtreecommitdiff
path: root/html/app/routes/api.php
blob: 659c25ff341216b22eac9de5ae01cf279da91dce (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

use app\controllers\api\Common_api;
use app\controllers\api\Doc_api;

// api: tree of product-categories 
Route::add('/api/tree',
    function() {     Doc_api::tree(); },
    'get'
);

// api: database documentation
Route::add('/api/doc',
    function() {     Doc_api::dbDoc(); },
    'get'
);

Route::add('/api/url/([0-9a-zA-Z-_\/]*)',
    function($url) {            Common_api::category_by_url($url); }
);

// route: /api/table
Route::add('/api/([0-9a-zA-Z-_]*)',
    function($table) {          Common_api::table($table); },
    'get'
);

// route: /api/table/{id}
Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)',
    function($table, $id) {     Common_api::record($table, $id); },
    'get'
);


# // test on the go
# // find products with large differences on price between stores
# // ---
# Route::add('/api/price-diffs', function() {
#     $wtf = Registry::use('database')->runQuery("SELECT sku,
#         max(ProductPrice_OriginalPrice) as MX,
#         min(ProductPrice_OriginalPrice) as MN,
#         ((max(ProductPrice_OriginalPrice)-min(ProductPrice_OriginalPrice))/max(ProductPrice_OriginalPrice)) as Di
#         FROM prices
#         GROUP BY sku
#         ORDER BY Di desc
#         LIMIT 300",
#         []
#     );
#     reply_json([
#         'success' => true,
#         'result' => $wtf
#     ]); die();
# });


// route for testing...
// ---
Route::add('/test/([0-9a-zA-Z-_\/]*)',    function($test) {
    if (file_exists(TESTS_DIRECTORY . $test .'.php')) {
        if (!Benchmark::exist('start')) Benchmark::add_spot('start');
        require(TESTS_DIRECTORY . $test .'.php');
    } else {    echo "Test {$test} not exist";
    } die();
});