mirror of
https://github.com/absmach/supermq.git
synced 2026-08-07 11:44:41 +00:00
NOISSUE - Add Readers and Consumers SDK (#33)
* refactor: aligh bootstrap with new supermq architecture Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: rename env variables Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * style: add empty line to config files and bootstrap docker compose file Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: add supermq sdk to magistrala sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: extend supermq sdk in magistrala sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * reafctor: update responses Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * feat: add readers and consumers sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * ci(messages.go): fix filename Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * feat: add readers sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: remove notifier interface Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: remove notifier interface Signed-off-by: Felix Gateru <felix.gateru@gmail.com> --------- Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/internal/testsutil"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
grpcChannelsV1 "github.com/absmach/supermq/api/grpc/channels/v1"
|
||||
grpcClientsV1 "github.com/absmach/supermq/api/grpc/clients/v1"
|
||||
apiutil "github.com/absmach/supermq/api/http/util"
|
||||
@@ -22,7 +23,6 @@ import (
|
||||
svcerr "github.com/absmach/supermq/pkg/errors/service"
|
||||
"github.com/absmach/supermq/pkg/transformers/senml"
|
||||
"github.com/absmach/supermq/readers"
|
||||
"github.com/absmach/supermq/readers/api"
|
||||
"github.com/absmach/supermq/readers/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package readers
|
||||
|
||||
import "errors"
|
||||
|
||||
const (
|
||||
// EqualKey represents the equal comparison operator key.
|
||||
EqualKey = "eq"
|
||||
// LowerThanKey represents the lower-than comparison operator key.
|
||||
LowerThanKey = "lt"
|
||||
// LowerThanEqualKey represents the lower-than-or-equal comparison operator key.
|
||||
LowerThanEqualKey = "le"
|
||||
// GreaterThanKey represents the greater-than-or-equal comparison operator key.
|
||||
GreaterThanKey = "gt"
|
||||
// GreaterThanEqualKey represents the greater-than-or-equal comparison operator key.
|
||||
GreaterThanEqualKey = "ge"
|
||||
)
|
||||
|
||||
// ErrReadMessages indicates failure occurred while reading messages from database.
|
||||
var ErrReadMessages = errors.New("failed to read messages from database")
|
||||
|
||||
// MessageRepository specifies message reader API.
|
||||
//
|
||||
//go:generate mockery --name MessageRepository --output=./mocks --filename messages.go --quiet --note "Copyright (c) Abstract Machines"
|
||||
type MessageRepository interface {
|
||||
// ReadAll skips given number of messages for given channel and returns next
|
||||
// limited number of messages.
|
||||
ReadAll(chanID string, pm PageMetadata) (MessagesPage, error)
|
||||
}
|
||||
|
||||
// Message represents any message format.
|
||||
type Message interface{}
|
||||
|
||||
// MessagesPage contains page related metadata as well as list of messages that
|
||||
// belong to this page.
|
||||
type MessagesPage struct {
|
||||
PageMetadata
|
||||
Total uint64
|
||||
Messages []Message
|
||||
}
|
||||
|
||||
// PageMetadata represents the parameters used to create database queries.
|
||||
type PageMetadata struct {
|
||||
Offset uint64 `json:"offset"`
|
||||
Limit uint64 `json:"limit"`
|
||||
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"`
|
||||
Comparator string `json:"comparator,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"`
|
||||
Aggregation string `json:"aggregation,omitempty"`
|
||||
Interval string `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
// ParseValueComparator convert comparison operator keys into mathematic anotation.
|
||||
func ParseValueComparator(query map[string]interface{}) string {
|
||||
comparator := "="
|
||||
val, ok := query["comparator"]
|
||||
if ok {
|
||||
switch val.(string) {
|
||||
case EqualKey:
|
||||
comparator = "="
|
||||
case LowerThanKey:
|
||||
comparator = "<"
|
||||
case LowerThanEqualKey:
|
||||
comparator = "<="
|
||||
case GreaterThanKey:
|
||||
comparator = ">"
|
||||
case GreaterThanEqualKey:
|
||||
comparator = ">="
|
||||
}
|
||||
}
|
||||
|
||||
return comparator
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package mocks contains mocks for testing purposes.
|
||||
package mocks
|
||||
@@ -1,57 +0,0 @@
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
// Copyright (c) Abstract Machines
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
readers "github.com/absmach/magistrala/readers"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MessageRepository is an autogenerated mock type for the MessageRepository type
|
||||
type MessageRepository struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// ReadAll provides a mock function with given fields: chanID, pm
|
||||
func (_m *MessageRepository) ReadAll(chanID string, pm readers.PageMetadata) (readers.MessagesPage, error) {
|
||||
ret := _m.Called(chanID, pm)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ReadAll")
|
||||
}
|
||||
|
||||
var r0 readers.MessagesPage
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, readers.PageMetadata) (readers.MessagesPage, error)); ok {
|
||||
return rf(chanID, pm)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, readers.PageMetadata) readers.MessagesPage); ok {
|
||||
r0 = rf(chanID, pm)
|
||||
} else {
|
||||
r0 = ret.Get(0).(readers.MessagesPage)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, readers.PageMetadata) error); ok {
|
||||
r1 = rf(chanID, pm)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// NewMessageRepository creates a new instance of MessageRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMessageRepository(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MessageRepository {
|
||||
mock := &MessageRepository{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
Reference in New Issue
Block a user