NOISSUE - Fix SDK Messages response (#1064)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
d587921eda
commit
6e4e5b351a
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue