Skip to content

Commit

Permalink
NOISSUE - Fix SDK Messages response (#1064)
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
  • Loading branch information
manuio authored Mar 7, 2020
1 parent a7f394a commit 3967e7d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 67 deletions.
22 changes: 6 additions & 16 deletions sdk/go/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 2 additions & 7 deletions sdk/go/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 0 additions & 23 deletions sdk/go/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package sdk

import "github.com/mainflux/mainflux"

type tokenRes struct {
Token string `json:"token,omitempty"`
}
Expand All @@ -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"`
}
10 changes: 5 additions & 5 deletions sdk/go/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"net/http"

"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/transformers/senml"
)

const (
Expand Down Expand Up @@ -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
Expand Down
22 changes: 6 additions & 16 deletions sdk/go/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3967e7d

Please sign in to comment.