2019-10-07 08:14:47 -06:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 13:15:48 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-08-06 17:06:55 +02:00
|
|
|
package readers
|
|
|
|
|
2020-12-30 15:43:04 +01:00
|
|
|
import "errors"
|
2018-08-06 17:06:55 +02:00
|
|
|
|
|
|
|
// ErrNotFound indicates that requested entity doesn't exist.
|
|
|
|
var ErrNotFound = errors.New("entity not found")
|
|
|
|
|
|
|
|
// MessageRepository specifies message reader API.
|
|
|
|
type MessageRepository interface {
|
|
|
|
// ReadAll skips given number of messages for given channel and returns next
|
|
|
|
// limited number of messages.
|
2021-01-26 12:23:15 +01:00
|
|
|
ReadAll(chanID string, pm PageMetadata) (MessagesPage, error)
|
2019-04-25 00:18:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-30 15:43:04 +01:00
|
|
|
// Message represents any message format.
|
|
|
|
type Message interface{}
|
|
|
|
|
2019-04-25 00:18:43 +02:00
|
|
|
// MessagesPage contains page related metadata as well as list of messages that
|
|
|
|
// belong to this page.
|
|
|
|
type MessagesPage struct {
|
2021-01-26 12:23:15 +01:00
|
|
|
PageMetadata
|
2019-04-25 00:18:43 +02:00
|
|
|
Total uint64
|
2020-12-30 15:43:04 +01:00
|
|
|
Messages []Message
|
2018-08-06 17:06:55 +02:00
|
|
|
}
|
2021-01-26 12:23:15 +01:00
|
|
|
|
|
|
|
// PageMetadata represents the parameters used to create database queries
|
|
|
|
type PageMetadata struct {
|
|
|
|
Offset uint64 `json:"offset,omitempty"`
|
|
|
|
Limit uint64 `json:"limit,omitempty"`
|
|
|
|
Subtopic string `json:"subtopic,omitempty"`
|
|
|
|
Publisher string `json:"publisher,omitempty"`
|
|
|
|
Protocol string `json:"protocol,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Value float64 `json:"v,omitempty"`
|
|
|
|
BoolValue bool `json:"vb,omitempty"`
|
|
|
|
StringValue string `json:"vs,omitempty"`
|
|
|
|
DataValue string `json:"vd,omitempty"`
|
|
|
|
From float64 `json:"from,omitempty"`
|
|
|
|
To float64 `json:"to,omitempty"`
|
|
|
|
Format string `json:"format,omitempty"`
|
|
|
|
}
|