From fedbe1c422ff49229d425d449c64062199ab6bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Novakovi=C4=87?= Date: Tue, 15 Jan 2019 18:51:06 +0100 Subject: [PATCH] NOISSUE - Update doc and fix empty key bug (#544) * Update docs with new connection endpoints Signed-off-by: Aleksandar Novakovic * Fix empty key bug Return key that was absent from things that are returned in connections endpoint. Signed-off-by: Aleksandar Novakovic --- docs/provisioning.md | 62 ++++++++++++++++++++++++++++++++------- things/postgres/things.go | 4 +-- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/docs/provisioning.md b/docs/provisioning.md index eb3f0d74..6f36c1d9 100644 --- a/docs/provisioning.md +++ b/docs/provisioning.md @@ -96,6 +96,9 @@ Date: Tue, 10 Apr 2018 10:50:12 GMT Content-Length: 1105 { + "total": 2, + "offset": 0, + "limit": 10, "things": [ { "id": "81380742-7116-4f6f-9800-14fe464f6773", @@ -170,6 +173,9 @@ Date: Tue, 10 Apr 2018 11:38:06 GMT Content-Length: 139 { + "total": 1, + "offset": 0, + "limit": 10, "channels": [ { "id": "19daa7a8-a489-4571-8714-ef1a214ed914", @@ -218,22 +224,58 @@ curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -X PUT -H You can observe which things are connected to specific channel: ``` -curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: " https://localhost/channels/ +curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: " https://localhost/channels//things ``` -You should receive response with the lists of connected things in `connected` field -similar to this one: +Response that you'll get should look like this: ``` { - "id": "19daa7a8-a489-4571-8714-ef1a214ed914", - "name": "mychan", - "connected": [ + "total": 2, + "offset": 0, + "limit": 10, + "things": [ { - "id": "81380742-7116-4f6f-9800-14fe464f6773", + "id": "3ffb3880-d1e6-4edd-acd9-4294d013f35b", "type": "device", - "name": "weio", - "key": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjMzNTQ1NzksImlzcyI6Im1haW5mbHV4Iiwic3ViIjoiODEzODA3NDItNzExNi00ZjZmLTk4MDAtMTRmZTQ2NGY2NzczIn0.5s8s1hlK-l30kQAyHxEZO_M2NIQw53MQuy7b3Wf3OOE" + "name": "d0", + "key": "b1996995-237a-4552-94b2-83ec2e92a040", + "metadata": "{}" + }, + { + "id": "94d166d6-6477-43dc-93b7-5c3707dbef1e", + "type": "app", + "name": "d1", + "key": "e4588a68-6028-4740-9f12-c356796aebe8", + "metadata": "{}" + } + ] +} +``` + +You can also observe to which channels is specified thing connected: + +``` +curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: " https://localhost/things//channels +``` + +Response that you'll get should look like this: + +``` +{ + "total": 2, + "offset": 0, + "limit": 10, + "channels": [ + { + "id": "5e62eb13-2695-4860-8d87-85b8a2f80fd4", + "name": "c1", + "metadata": "{}" + }, + { + "id": "c4b5e19a-7ffe-4172-b2c5-c8b9d570a165", + "name": "c0", + "metadata":"{}" } ] } @@ -243,4 +285,4 @@ If you want to disconnect your device from the channel, send following request: ``` curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -X DELETE -H "Authorization: " https://localhost/channels//things/ -``` \ No newline at end of file +``` diff --git a/things/postgres/things.go b/things/postgres/things.go index f5bef177..771b9de3 100644 --- a/things/postgres/things.go +++ b/things/postgres/things.go @@ -152,7 +152,7 @@ func (tr thingRepository) RetrieveAll(owner string, offset, limit uint64) things } func (tr thingRepository) RetrieveByChannel(owner, channel string, offset, limit uint64) things.ThingsPage { - q := `SELECT id, type, name, metadata + q := `SELECT id, type, name, key, metadata FROM things th INNER JOIN connections co ON th.id = co.thing_id @@ -171,7 +171,7 @@ func (tr thingRepository) RetrieveByChannel(owner, channel string, offset, limit for rows.Next() { t := things.Thing{Owner: owner} - if err := rows.Scan(&t.ID, &t.Type, &t.Name, &t.Metadata); err != nil { + if err := rows.Scan(&t.ID, &t.Type, &t.Name, &t.Key, &t.Metadata); err != nil { tr.log.Error(fmt.Sprintf("Failed to read retrieved thing due to %s", err)) return things.ThingsPage{} }