mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* Update metadata type in things service Update things service so that metadata has map type. Update repo implementation by adding sqlx lib. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add sqlx lib to bootstrap service Add sqlx lib to bootstrap service and update metadata field type. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update metadata in redis streams consumer Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update tests for bootstrap service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix mongo reader logging and driver version Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix mongo reader and writer Fix mongo reader and writer by updating driver version. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK with new metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update LoRa adapter with new metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update users service in order to use sqlx Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Replace anonymous struct with map Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update docs for LoRa adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix LoRa application metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix metadata format in LoRa docs Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add metadata2 var to SDK things test Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
177 lines
3.0 KiB
Go
177 lines
3.0 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package http
|
|
|
|
import "github.com/mainflux/mainflux/things"
|
|
|
|
const maxLimitSize = 100
|
|
|
|
type apiReq interface {
|
|
validate() error
|
|
}
|
|
|
|
type identityReq struct {
|
|
key string
|
|
}
|
|
|
|
func (req identityReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type addThingReq struct {
|
|
key string
|
|
Type string `json:"type"`
|
|
Name string `json:"name,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req addThingReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.Type == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateThingReq struct {
|
|
key string
|
|
id string
|
|
Type string `json:"type"`
|
|
Name string `json:"name,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateThingReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" || req.Type == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type createChannelReq struct {
|
|
key string
|
|
Name string `json:"name,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req createChannelReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateChannelReq struct {
|
|
key string
|
|
id string
|
|
Name string `json:"name,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateChannelReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type viewResourceReq struct {
|
|
key string
|
|
id string
|
|
}
|
|
|
|
func (req viewResourceReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listResourcesReq struct {
|
|
key string
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req *listResourcesReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.limit == 0 || req.limit > maxLimitSize {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listByConnectionReq struct {
|
|
key string
|
|
id string
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req listByConnectionReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
if req.limit == 0 || req.limit > maxLimitSize {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type connectionReq struct {
|
|
key string
|
|
chanID string
|
|
thingID string
|
|
}
|
|
|
|
func (req connectionReq) validate() error {
|
|
if req.key == "" {
|
|
return things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.chanID == "" || req.thingID == "" {
|
|
return things.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|