2020-11-23 11:34:29 +01:00
|
|
|
package groups
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ mainflux.Response = (*memberPageRes)(nil)
|
|
|
|
_ mainflux.Response = (*groupRes)(nil)
|
2021-03-04 10:29:03 +01:00
|
|
|
_ mainflux.Response = (*deleteRes)(nil)
|
|
|
|
_ mainflux.Response = (*assignRes)(nil)
|
|
|
|
_ mainflux.Response = (*unassignRes)(nil)
|
2020-11-23 11:34:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type memberPageRes struct {
|
|
|
|
pageRes
|
|
|
|
Members []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res memberPageRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res memberPageRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res memberPageRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-27 00:38:28 +02:00
|
|
|
type shareGroupRes struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res shareGroupRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res shareGroupRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res shareGroupRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:34:29 +01:00
|
|
|
type viewGroupRes struct {
|
2021-03-04 10:29:03 +01:00
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
OwnerID string `json:"owner_id"`
|
2020-11-23 11:34:29 +01:00
|
|
|
ParentID string `json:"parent_id,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
2021-03-04 10:29:03 +01:00
|
|
|
// Indicates a level in tree hierarchy from first group node - root.
|
|
|
|
Level int `json:"level"`
|
|
|
|
// Path in a tree consisting of group ids
|
|
|
|
// parentID1.parentID2.childID1
|
|
|
|
// e.g. 01EXPM5Z8HRGFAEWTETR1X1441.01EXPKW2TVK74S5NWQ979VJ4PJ.01EXPKW2TVK74S5NWQ979VJ4PJ
|
2020-11-23 11:34:29 +01:00
|
|
|
Path string `json:"path"`
|
2021-03-04 10:29:03 +01:00
|
|
|
Children []*viewGroupRes `json:"children,omitempty"`
|
2020-11-23 11:34:29 +01:00
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewGroupRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewGroupRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res viewGroupRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type groupRes struct {
|
|
|
|
id string
|
|
|
|
created bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res groupRes) Code() int {
|
|
|
|
if res.created {
|
|
|
|
return http.StatusCreated
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res groupRes) Headers() map[string]string {
|
|
|
|
if res.created {
|
|
|
|
return map[string]string{
|
|
|
|
"Location": fmt.Sprintf("/groups/%s", res.id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res groupRes) Empty() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type groupPageRes struct {
|
|
|
|
pageRes
|
|
|
|
Groups []viewGroupRes `json:"groups"`
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
type pageRes struct {
|
|
|
|
Limit uint64 `json:"limit,omitempty"`
|
|
|
|
Offset uint64 `json:"offset,omitempty"`
|
|
|
|
Total uint64 `json:"total"`
|
|
|
|
Level uint64 `json:"level"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:34:29 +01:00
|
|
|
func (res groupPageRes) Code() int {
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res groupPageRes) Headers() map[string]string {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res groupPageRes) Empty() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
type deleteRes struct{}
|
2020-11-23 11:34:29 +01:00
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res deleteRes) Code() int {
|
2020-11-23 11:34:29 +01:00
|
|
|
return http.StatusNoContent
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res deleteRes) Headers() map[string]string {
|
2020-11-23 11:34:29 +01:00
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res deleteRes) Empty() bool {
|
2020-11-23 11:34:29 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
type assignRes struct{}
|
2020-11-23 11:34:29 +01:00
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res assignRes) Code() int {
|
|
|
|
return http.StatusOK
|
2020-11-23 11:34:29 +01:00
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res assignRes) Headers() map[string]string {
|
2020-11-23 11:34:29 +01:00
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res assignRes) Empty() bool {
|
2020-11-23 11:34:29 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
type unassignRes struct{}
|
2020-11-23 11:34:29 +01:00
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res unassignRes) Code() int {
|
2020-11-23 11:34:29 +01:00
|
|
|
return http.StatusNoContent
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res unassignRes) Headers() map[string]string {
|
2020-11-23 11:34:29 +01:00
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
|
2021-03-04 10:29:03 +01:00
|
|
|
func (res unassignRes) Empty() bool {
|
2020-11-23 11:34:29 +01:00
|
|
|
return true
|
|
|
|
}
|
2021-03-04 10:29:03 +01:00
|
|
|
|
|
|
|
type errorRes struct {
|
|
|
|
Err string `json:"error"`
|
|
|
|
}
|