1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-14 19:29:11 +08:00
Manuel Imperiale c8979ac297
NOISSUE - Add searchable Things name (#750)
* NOISSUE - Add searchable Things name

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix reviews

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add postgres schema validation and tests

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add namme tests in requests_test

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Typo fix

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Rm requests_test

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add name in ListThings loggins

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add invalidName var for tests

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Set maxNameSize to 1024

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix postgres test

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix total when filtering things by name

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix review

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2019-05-30 15:33:49 +02:00

200 lines
3.4 KiB
Go

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package http
import "github.com/mainflux/mainflux/things"
const maxLimitSize = 100
const maxNameSize = 1024
type apiReq interface {
validate() error
}
type addThingReq struct {
token string
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req addThingReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if len(req.Name) > maxNameSize {
return things.ErrMalformedEntity
}
return nil
}
type updateThingReq struct {
token string
id string
Name string `json:"name,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req updateThingReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.id == "" {
return things.ErrMalformedEntity
}
if len(req.Name) > maxNameSize {
return things.ErrMalformedEntity
}
return nil
}
type updateKeyReq struct {
token string
id string
Key string `json:"key"`
}
func (req updateKeyReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.id == "" || req.Key == "" {
return things.ErrMalformedEntity
}
return nil
}
type createChannelReq struct {
token string
Name string `json:"name,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req createChannelReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if len(req.Name) > maxNameSize {
return things.ErrMalformedEntity
}
return nil
}
type updateChannelReq struct {
token string
id string
Name string `json:"name,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req updateChannelReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.id == "" {
return things.ErrMalformedEntity
}
if len(req.Name) > maxNameSize {
return things.ErrMalformedEntity
}
return nil
}
type viewResourceReq struct {
token string
id string
}
func (req viewResourceReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.id == "" {
return things.ErrMalformedEntity
}
return nil
}
type listResourcesReq struct {
token string
offset uint64
limit uint64
name string
}
func (req *listResourcesReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.limit == 0 || req.limit > maxLimitSize {
return things.ErrMalformedEntity
}
if len(req.name) > maxNameSize {
return things.ErrMalformedEntity
}
return nil
}
type listByConnectionReq struct {
token string
id string
offset uint64
limit uint64
}
func (req listByConnectionReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.id == "" {
return things.ErrMalformedEntity
}
if req.limit == 0 || req.limit > maxLimitSize {
return things.ErrMalformedEntity
}
return nil
}
type connectionReq struct {
token string
chanID string
thingID string
}
func (req connectionReq) validate() error {
if req.token == "" {
return things.ErrUnauthorizedAccess
}
if req.chanID == "" || req.thingID == "" {
return things.ErrMalformedEntity
}
return nil
}