mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* Use separate table for Channels Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add inital event sourcing subscription Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel update sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Thing remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update service add method marshalling metadata Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Make separate methods for connection update Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add diconnect event sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Configs repository mock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix service tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update repository tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update API docs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Location header Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update README.md Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix tests mutex lock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix method names in logs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
150 lines
2.4 KiB
Go
150 lines
2.4 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package api
|
|
|
|
import "github.com/mainflux/mainflux/bootstrap"
|
|
|
|
type apiReq interface {
|
|
validate() error
|
|
}
|
|
|
|
type addReq struct {
|
|
key string
|
|
ThingID string `json:"thing_id"`
|
|
ExternalID string `json:"external_id"`
|
|
ExternalKey string `json:"external_key"`
|
|
Channels []string `json:"channels"`
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
func (req addReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.ExternalID == "" || req.ExternalKey == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type entityReq struct {
|
|
key string
|
|
id string
|
|
}
|
|
|
|
func (req entityReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateReq struct {
|
|
key string
|
|
id string
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
func (req updateReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateConnReq struct {
|
|
key string
|
|
id string
|
|
Channels []string `json:"channels"`
|
|
}
|
|
|
|
func (req updateConnReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listReq struct {
|
|
key string
|
|
filter bootstrap.Filter
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req listReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.limit == 0 || req.limit > maxLimit {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type bootstrapReq struct {
|
|
key string
|
|
id string
|
|
}
|
|
|
|
func (req bootstrapReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type changeStateReq struct {
|
|
key string
|
|
id string
|
|
State bootstrap.State `json:"state"`
|
|
}
|
|
|
|
func (req changeStateReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
if req.State != bootstrap.Inactive &&
|
|
req.State != bootstrap.Active {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|