From 6e4e5b351a782112a24435d5667dacda05a33a2a Mon Sep 17 00:00:00 2001 From: Manuel Imperiale Date: Sat, 7 Mar 2020 05:02:26 +0100 Subject: [PATCH] NOISSUE - Fix SDK Messages response (#1064) Signed-off-by: Manuel Imperiale --- sdk/go/channels.go | 22 ++++++---------------- sdk/go/message.go | 9 ++------- sdk/go/responses.go | 23 ----------------------- sdk/go/sdk.go | 10 +++++----- sdk/go/things.go | 22 ++++++---------------- 5 files changed, 19 insertions(+), 67 deletions(-) diff --git a/sdk/go/channels.go b/sdk/go/channels.go index 61ce040f..d47abac9 100644 --- a/sdk/go/channels.go +++ b/sdk/go/channels.go @@ -121,17 +121,12 @@ func (sdk mfSDK) Channels(token string, offset, limit uint64, name string) (Chan } } - var p channelsPageRes - if err := json.Unmarshal(body, &p); err != nil { + var cp ChannelsPage + if err := json.Unmarshal(body, &cp); err != nil { return ChannelsPage{}, err } - return ChannelsPage{ - Channels: p.Channels, - Total: p.Total, - Offset: p.Offset, - Limit: p.Limit, - }, nil + return cp, nil } func (sdk mfSDK) ChannelsByThing(token, thingID string, offset, limit uint64) (ChannelsPage, error) { @@ -165,17 +160,12 @@ func (sdk mfSDK) ChannelsByThing(token, thingID string, offset, limit uint64) (C } } - var p channelsPageRes - if err := json.Unmarshal(body, &p); err != nil { + var cp ChannelsPage + if err := json.Unmarshal(body, &cp); err != nil { return ChannelsPage{}, err } - return ChannelsPage{ - Channels: p.Channels, - Total: p.Total, - Offset: p.Offset, - Limit: p.Limit, - }, nil + return cp, nil } func (sdk mfSDK) Channel(id, token string) (Channel, error) { diff --git a/sdk/go/message.go b/sdk/go/message.go index 16f1781b..402508be 100644 --- a/sdk/go/message.go +++ b/sdk/go/message.go @@ -84,17 +84,12 @@ func (sdk mfSDK) ReadMessages(chanName, token string) (MessagesPage, error) { } } - mp := messagesPageRes{} + mp := MessagesPage{} if err := json.Unmarshal(body, &mp); err != nil { return MessagesPage{}, err } - return MessagesPage{ - Total: mp.Total, - Offset: mp.Offset, - Limit: mp.Limit, - Messages: mp.Messages, - }, nil + return mp, nil } func (sdk *mfSDK) SetContentType(ct ContentType) error { diff --git a/sdk/go/responses.go b/sdk/go/responses.go index d3e33111..ecd9f8a2 100644 --- a/sdk/go/responses.go +++ b/sdk/go/responses.go @@ -3,8 +3,6 @@ package sdk -import "github.com/mainflux/mainflux" - type tokenRes struct { Token string `json:"token,omitempty"` } @@ -16,24 +14,3 @@ type createThingsRes struct { type createChannelsRes struct { Channels []Channel `json:"channels"` } - -type thingsPageRes struct { - Things []Thing `json:"things,omitempty"` - Total uint64 `json:"total"` - Offset uint64 `json:"offset"` - Limit uint64 `json:"limit"` -} - -type channelsPageRes struct { - Channels []Channel `json:"channels,omitempty"` - Total uint64 `json:"total"` - Offset uint64 `json:"offset"` - Limit uint64 `json:"limit"` -} - -type messagesPageRes struct { - Total uint64 `json:"total"` - Offset uint64 `json:"offset"` - Limit uint64 `json:"limit"` - Messages []mainflux.Message `json:"messages,omitempty"` -} diff --git a/sdk/go/sdk.go b/sdk/go/sdk.go index 91cc389d..d480cb99 100644 --- a/sdk/go/sdk.go +++ b/sdk/go/sdk.go @@ -9,7 +9,7 @@ import ( "fmt" "net/http" - "github.com/mainflux/mainflux" + "github.com/mainflux/mainflux/transformers/senml" ) const ( @@ -128,10 +128,10 @@ type ChannelsPage struct { // MessagesPage contains list of messages in a page with proper metadata. type MessagesPage struct { - Total uint64 `json:"total"` - Offset uint64 `json:"offset"` - Limit uint64 `json:"limit"` - Messages []mainflux.Message `json:"messages,omitempty"` + Total uint64 `json:"total"` + Offset uint64 `json:"offset"` + Limit uint64 `json:"limit"` + Messages []senml.Message `json:"messages,omitempty"` } // ConnectionIDs contains ID lists of things and channels to be connected diff --git a/sdk/go/things.go b/sdk/go/things.go index 7a154efe..2b3b0f39 100644 --- a/sdk/go/things.go +++ b/sdk/go/things.go @@ -124,17 +124,12 @@ func (sdk mfSDK) Things(token string, offset, limit uint64, name string) (Things } } - var p thingsPageRes - if err := json.Unmarshal(body, &p); err != nil { + var tp ThingsPage + if err := json.Unmarshal(body, &tp); err != nil { return ThingsPage{}, err } - return ThingsPage{ - Things: p.Things, - Total: p.Total, - Offset: p.Offset, - Limit: p.Limit, - }, nil + return tp, nil } func (sdk mfSDK) ThingsByChannel(token, chanID string, offset, limit uint64) (ThingsPage, error) { @@ -168,17 +163,12 @@ func (sdk mfSDK) ThingsByChannel(token, chanID string, offset, limit uint64) (Th } } - var p thingsPageRes - if err := json.Unmarshal(body, &p); err != nil { + var tp ThingsPage + if err := json.Unmarshal(body, &tp); err != nil { return ThingsPage{}, err } - return ThingsPage{ - Things: p.Things, - Total: p.Total, - Offset: p.Offset, - Limit: p.Limit, - }, nil + return tp, nil } func (sdk mfSDK) Thing(id, token string) (Thing, error) {