2019-10-07 22:14:47 +08:00
|
|
|
// Copyright (c) Mainflux
|
2019-01-09 22:42:23 +08:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux"
|
2019-02-22 21:54:09 +08:00
|
|
|
"github.com/mainflux/mainflux/bootstrap"
|
2019-01-09 22:42:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ mainflux.Response = (*removeRes)(nil)
|
|
|
|
_ mainflux.Response = (*configRes)(nil)
|
|
|
|
_ mainflux.Response = (*stateRes)(nil)
|
|
|
|
_ mainflux.Response = (*viewRes)(nil)
|
|
|
|
_ mainflux.Response = (*listRes)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type removeRes struct{}
|
|
|
|
|
|
|
|
func (res removeRes) Code() int {
|
|
|
|
return http.StatusNoContent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res removeRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res removeRes) Empty() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type configRes struct {
|
|
|
|
id string
|
|
|
|
created bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res configRes) Code() int {
|
|
|
|
if res.created {
|
|
|
|
return http.StatusCreated
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res configRes) Headers() map[string]string {
|
|
|
|
if res.created {
|
|
|
|
return map[string]string{
|
2019-03-05 00:41:38 +08:00
|
|
|
"Location": fmt.Sprintf("/things/configs/%s", res.id),
|
2019-01-09 22:42:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res configRes) Empty() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-01-30 23:40:37 +08:00
|
|
|
type channelRes struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Metadata interface{} `json:"metadata,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:42:23 +08:00
|
|
|
type viewRes struct {
|
|
|
|
MFThing string `json:"mainflux_id,omitempty"`
|
|
|
|
MFKey string `json:"mainflux_key,omitempty"`
|
2019-01-30 23:40:37 +08:00
|
|
|
Channels []channelRes `json:"mainflux_channels,omitempty"`
|
2019-01-09 22:42:23 +08:00
|
|
|
ExternalID string `json:"external_id"`
|
|
|
|
ExternalKey string `json:"external_key,omitempty"`
|
|
|
|
Content string `json:"content,omitempty"`
|
2019-02-06 17:28:54 +08:00
|
|
|
Name string `json:"name,omitempty"`
|
2019-01-30 23:40:37 +08:00
|
|
|
State bootstrap.State `json:"state"`
|
2019-01-09 22:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type listRes struct {
|
2019-02-22 21:54:09 +08:00
|
|
|
Total uint64 `json:"total"`
|
|
|
|
Offset uint64 `json:"offset"`
|
|
|
|
Limit uint64 `json:"limit"`
|
2019-01-09 22:42:23 +08:00
|
|
|
Configs []viewRes `json:"configs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res listRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res listRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res listRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type stateRes struct{}
|
|
|
|
|
|
|
|
func (res stateRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res stateRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res stateRes) Empty() bool {
|
|
|
|
return true
|
|
|
|
}
|
2020-04-01 21:54:26 +08:00
|
|
|
|
|
|
|
type errorRes struct {
|
|
|
|
Err string `json:"error"`
|
|
|
|
}
|