Changes in routes and functionality

parent 1d27c010
......@@ -21,8 +21,9 @@ body, αναφέρονται παρακάτω στις σχετικές παρα
| HTTP Method | Resource routes | Επιστρεφόμενη τιμή | Μέθοδος που καλείται στο [Gr\Gov\Minedu\Osteam\Slim\App](src/osteam/App.php) |
|-------------+-----------------+--------------------+--------------------------------------------------------------------------------|
| GET | amka/{amka}/{surname} | JSON μήνυμα | validateAmka |
| GET | amka/{amka}/{surname}?fields=[comma separated list of field names] | TEXT μήνυμα | validateAmka |
| GET | amka/{amka}/{surname} | TEXT κείμενο: true ή false | validateAmka |
| GET | amka/{amka}/{surname}/extended | JSON μήνυμα | validateAmka |
| GET | amka/{amka}/{surname}[/extended]?fields=[comma separated list of field names] | TEXT μήνυμα | validateAmka |
Η εφαρμογή δημιουργήθηκε με σημείο εκκίνησης το Slim Framework 3 Skeleton Application.
Περισσότερες λεπτομέρειες στη [σελίδα του Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton)
......@@ -60,10 +61,19 @@ body, αναφέρονται παρακάτω στις σχετικές παρα
> Στα παρακάτω δείγματα κλήσης θεωρείται ότι η εφαρμογή είναι διαθέσιμη στη διεύθυνση: http://generic.local.dev/public/
## Ανάκτηση πληροφοριών ΑΜΚΑ
## Έλεγχος εγκυρότητας ΑΜΚΑ
- `http://generic.local.dev/public/amka/12097301234/ΠΑΠΑΔΑΚΗΣ`
Δείγμα απάντησης
```
true
```
## Ανάκτηση πληροφοριών ΑΜΚΑ
- `http://generic.local.dev/public/amka/12097301234/ΠΑΠΑΔΑΚΗΣ/extended`
Δείγμα απάντησης
```json
{
......
......@@ -106,6 +106,7 @@ class App
*/
public function validateAmka($req, $res, $args)
{
$detailed_info = isset($args['extended']);
$amka = $args['amka'];
$surname = $args['surname'];
$bdate = '';
......@@ -122,22 +123,25 @@ class App
'surname' => $surname,
];
$fields_requested = $req->getQueryParam('fields', null);
$field_names = [];
if ($fields_requested) {
$field_names = explode(',', $fields_requested);
}
$detailed_info = $detailed_info || count($field_names) > 0;
$this->logger->info("validateAmka::{$amka}");
$result = $this->client->get($this->url, $data, array_merge([
"Authorization: Token {$this->key}",
'Content-Type: application/json'
], $this->headers)
);
$headers = array_merge([
"Authorization: Token {$this->key}",
'Content-Type: application/json'
], ($detailed_info ? $this->headers : []));
$result = $this->client->get($this->url, $data, $headers);
// request specific fields?
// if so, return string results
// or else respond with json
$fields_requested = $req->getQueryParam('fields', null);
$field_names = [];
if ($fields_requested) {
$field_names = explode(',', $fields_requested);
}
if (count($field_names) > 0) {
$result = json_decode($result, true);
$response_string = array_reduce($field_names, function ($r, $field_name) use ($result) {
......@@ -148,7 +152,12 @@ class App
}, '');
return $this->withTextReady($res, $response_string);
} else {
return $this->withJsonReady($res, $result);
if ($detailed_info) {
return $this->withJsonReady($res, $result);
} else {
$result = json_decode($result, true);
return $this->withTextReady($res, $result['match']);
}
}
}
......
<?php
$app->get('/amka/{amka}/{surname}', '\Gr\Gov\Minedu\Osteam\Slim\App:validateAmka');
$app->get('/amka/{amka}/{surname}[/extended]', '\Gr\Gov\Minedu\Osteam\Slim\App:validateAmka');
$app->any('/[{anythingelse}]', function ($request, $response, $args) {
$this->logger->info("Void response, no action route was enabled");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment