mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

* Add name field to Config Enable search by name. Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Create separate response for unknown Configs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Use meaningful names for filters Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add name search tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update API docs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Break mocks check into multiple lines Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Create new instances in a consistent way Reformat `return` statements. Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
119 lines
2.0 KiB
Go
119 lines
2.0 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
|
|
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.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
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateReq struct {
|
|
key string
|
|
id string
|
|
Channels []string `json:"channels"`
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
State bootstrap.State `json:"state"`
|
|
}
|
|
|
|
func (req updateReq) validate() error {
|
|
if req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
// Can't explicitly update state to NewThing or Created.
|
|
if req.State != bootstrap.Inactive &&
|
|
req.State != bootstrap.Active {
|
|
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
|
|
}
|
|
|
|
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.id == "" || req.key == "" {
|
|
return bootstrap.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.State != bootstrap.Inactive &&
|
|
req.State != bootstrap.Active {
|
|
return bootstrap.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|