Update module meta for discovery result
This commit is contained in:
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
discovery "github.com/cortezaproject/corteza-server/discovery/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/pkg/locale"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
@@ -32,9 +33,7 @@ type (
|
||||
}
|
||||
|
||||
ModuleMeta struct {
|
||||
Discovery struct {
|
||||
//ResponseMeta discovery.ResponseMeta `json:"response_meta"`
|
||||
} `json:"discovery"`
|
||||
Discovery discovery.ModuleMeta `json:"discovery"`
|
||||
}
|
||||
|
||||
ModuleFilter struct {
|
||||
|
||||
@@ -51,10 +51,6 @@ type (
|
||||
}
|
||||
|
||||
NamespaceMeta struct {
|
||||
Discovery struct {
|
||||
//ResponseMeta discovery.ResponseMeta `json:"response_meta"`
|
||||
} `json:"discovery"`
|
||||
|
||||
// Temporary icon & logo URLs
|
||||
// @todo rework this when we rework attachment management
|
||||
Icon string `json:"icon,omitempty"`
|
||||
|
||||
@@ -46,24 +46,6 @@ endpoints:
|
||||
- { name: namespaceID, type: uint64, title: Namespace ID }
|
||||
- { name: moduleID, type: uint64, title: Module ID }
|
||||
|
||||
- name: composeNamespacesMeta
|
||||
method: POST
|
||||
title: ModuleMeta
|
||||
path: "/compose/namespaces/{namespaceID}/meta"
|
||||
parameters:
|
||||
path:
|
||||
- { name: namespaceID, type: uint64, title: Namespace ID }
|
||||
- { name: moduleID, type: uint64, title: Module ID }
|
||||
|
||||
- name: composeModuleMeta
|
||||
method: POST
|
||||
title: ModuleMeta
|
||||
path: "/compose/namespaces/{namespaceID}/modules/{moduleID}/meta"
|
||||
parameters:
|
||||
path:
|
||||
- { name: namespaceID, type: uint64, title: Namespace ID }
|
||||
- { name: moduleID, type: uint64, title: Module ID }
|
||||
|
||||
- path: "/feed"
|
||||
entrypoint: feed
|
||||
title: Change feed
|
||||
|
||||
@@ -23,18 +23,14 @@ type (
|
||||
ComposeNamespaces(context.Context, *request.ResourcesComposeNamespaces) (interface{}, error)
|
||||
ComposeModules(context.Context, *request.ResourcesComposeModules) (interface{}, error)
|
||||
ComposeRecords(context.Context, *request.ResourcesComposeRecords) (interface{}, error)
|
||||
ComposeNamespacesMeta(context.Context, *request.ResourcesComposeNamespacesMeta) (interface{}, error)
|
||||
ComposeModuleMeta(context.Context, *request.ResourcesComposeModuleMeta) (interface{}, error)
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
Resources struct {
|
||||
SystemUsers func(http.ResponseWriter, *http.Request)
|
||||
ComposeNamespaces func(http.ResponseWriter, *http.Request)
|
||||
ComposeModules func(http.ResponseWriter, *http.Request)
|
||||
ComposeRecords func(http.ResponseWriter, *http.Request)
|
||||
ComposeNamespacesMeta func(http.ResponseWriter, *http.Request)
|
||||
ComposeModuleMeta func(http.ResponseWriter, *http.Request)
|
||||
SystemUsers func(http.ResponseWriter, *http.Request)
|
||||
ComposeNamespaces func(http.ResponseWriter, *http.Request)
|
||||
ComposeModules func(http.ResponseWriter, *http.Request)
|
||||
ComposeRecords func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -102,38 +98,6 @@ func NewResources(h ResourcesAPI) *Resources {
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
ComposeNamespacesMeta: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewResourcesComposeNamespacesMeta()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.ComposeNamespacesMeta(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
ComposeModuleMeta: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewResourcesComposeModuleMeta()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.ComposeModuleMeta(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
}
|
||||
@@ -146,7 +110,5 @@ func (h Resources) MountRoutes(r chi.Router, middlewares ...func(http.Handler) h
|
||||
r.Get("/resources/compose/namespaces", h.ComposeNamespaces)
|
||||
r.Get("/resources/compose/namespaces/{namespaceID}/modules", h.ComposeModules)
|
||||
r.Get("/resources/compose/namespaces/{namespaceID}/modules/{moduleID}/records", h.ComposeRecords)
|
||||
r.Post("/resources/compose/namespaces/{namespaceID}/meta", h.ComposeNamespacesMeta)
|
||||
r.Post("/resources/compose/namespaces/{namespaceID}/modules/{moduleID}/meta", h.ComposeModuleMeta)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -365,14 +365,6 @@ func (d composeResources) recordValues(ctx context.Context, rec *cmpTypes.Record
|
||||
return rval
|
||||
}
|
||||
|
||||
func (d composeResources) UpdateNamespacesMeta(ctx context.Context) (rsp interface{}, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d composeResources) UpdateModuleMeta(ctx context.Context) (rsp interface{}, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// getUrlToResource construct page url for compose resources
|
||||
func (d composeResources) getUrlToResource(page pageDetail) (url string) {
|
||||
var (
|
||||
|
||||
@@ -95,50 +95,6 @@ type (
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
}
|
||||
|
||||
ResourcesComposeNamespacesMeta struct {
|
||||
// NamespaceID PATH parameter
|
||||
//
|
||||
// Namespace ID
|
||||
NamespaceID uint64 `json:",string"`
|
||||
|
||||
// ModuleID PATH parameter
|
||||
//
|
||||
// Module ID
|
||||
ModuleID uint64 `json:",string"`
|
||||
|
||||
// Limit GET parameter
|
||||
//
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
}
|
||||
|
||||
ResourcesComposeModuleMeta struct {
|
||||
// NamespaceID PATH parameter
|
||||
//
|
||||
// Namespace ID
|
||||
NamespaceID uint64 `json:",string"`
|
||||
|
||||
// ModuleID PATH parameter
|
||||
//
|
||||
// Module ID
|
||||
ModuleID uint64 `json:",string"`
|
||||
|
||||
// Limit GET parameter
|
||||
//
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
}
|
||||
)
|
||||
|
||||
// NewResourcesSystemUsers request
|
||||
@@ -376,157 +332,3 @@ func (r *ResourcesComposeRecords) Fill(req *http.Request) (err error) {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewResourcesComposeNamespacesMeta request
|
||||
func NewResourcesComposeNamespacesMeta() *ResourcesComposeNamespacesMeta {
|
||||
return &ResourcesComposeNamespacesMeta{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeNamespacesMeta) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"namespaceID": r.NamespaceID,
|
||||
"moduleID": r.ModuleID,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeNamespacesMeta) GetNamespaceID() uint64 {
|
||||
return r.NamespaceID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeNamespacesMeta) GetModuleID() uint64 {
|
||||
return r.ModuleID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeNamespacesMeta) GetLimit() uint {
|
||||
return r.Limit
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeNamespacesMeta) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *ResourcesComposeNamespacesMeta) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
// GET params
|
||||
tmp := req.URL.Query()
|
||||
|
||||
if val, ok := tmp["limit"]; ok && len(val) > 0 {
|
||||
r.Limit, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var val string
|
||||
// path params
|
||||
|
||||
val = chi.URLParam(req, "namespaceID")
|
||||
r.NamespaceID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = chi.URLParam(req, "moduleID")
|
||||
r.ModuleID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewResourcesComposeModuleMeta request
|
||||
func NewResourcesComposeModuleMeta() *ResourcesComposeModuleMeta {
|
||||
return &ResourcesComposeModuleMeta{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeModuleMeta) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"namespaceID": r.NamespaceID,
|
||||
"moduleID": r.ModuleID,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeModuleMeta) GetNamespaceID() uint64 {
|
||||
return r.NamespaceID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeModuleMeta) GetModuleID() uint64 {
|
||||
return r.ModuleID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeModuleMeta) GetLimit() uint {
|
||||
return r.Limit
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ResourcesComposeModuleMeta) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *ResourcesComposeModuleMeta) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
// GET params
|
||||
tmp := req.URL.Query()
|
||||
|
||||
if val, ok := tmp["limit"]; ok && len(val) > 0 {
|
||||
r.Limit, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["pageCursor"]; ok && len(val) > 0 {
|
||||
r.PageCursor, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var val string
|
||||
// path params
|
||||
|
||||
val = chi.URLParam(req, "namespaceID")
|
||||
r.NamespaceID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = chi.URLParam(req, "moduleID")
|
||||
r.ModuleID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ type (
|
||||
Namespaces(ctx context.Context, limit uint, cur string) (*documents.Response, error)
|
||||
Modules(ctx context.Context, namespaceID uint64, limit uint, cur string) (*documents.Response, error)
|
||||
Records(ctx context.Context, namespaceID, moduleID uint64, limit uint, cur string) (*documents.Response, error)
|
||||
|
||||
UpdateNamespacesMeta(ctx context.Context) (interface{}, error)
|
||||
UpdateModuleMeta(ctx context.Context) (interface{}, error)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -45,11 +42,3 @@ func (ctrl resources) ComposeModules(ctx context.Context, r *request.ResourcesCo
|
||||
func (ctrl resources) ComposeRecords(ctx context.Context, r *request.ResourcesComposeRecords) (interface{}, error) {
|
||||
return ctrl.cmp.Records(ctx, r.NamespaceID, r.ModuleID, r.Limit, r.PageCursor)
|
||||
}
|
||||
|
||||
func (ctrl resources) ComposeNamespacesMeta(ctx context.Context, r *request.ResourcesComposeNamespacesMeta) (interface{}, error) {
|
||||
return ctrl.cmp.UpdateNamespacesMeta(ctx)
|
||||
}
|
||||
|
||||
func (ctrl resources) ComposeModuleMeta(ctx context.Context, r *request.ResourcesComposeModuleMeta) (interface{}, error) {
|
||||
return ctrl.cmp.UpdateModuleMeta(ctx)
|
||||
}
|
||||
|
||||
@@ -22,4 +22,37 @@ type (
|
||||
Title string `json:"title"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
/*
|
||||
"discovery": {
|
||||
"public": {
|
||||
"result": [
|
||||
{
|
||||
lang: "", // en, fr
|
||||
fields: [] // “names”, ..
|
||||
}
|
||||
]
|
||||
} // struct
|
||||
},
|
||||
"private": {
|
||||
"response": []
|
||||
}
|
||||
}
|
||||
*/
|
||||
ModuleMeta struct {
|
||||
Public AccessJson `json:"public"`
|
||||
Private AccessJson `json:"private"`
|
||||
Protected AccessJson `json:"protected"`
|
||||
}
|
||||
|
||||
AccessJson struct {
|
||||
Result Result `json:"result"`
|
||||
}
|
||||
|
||||
Result struct {
|
||||
Lang string `json:"lang"`
|
||||
Fields []string `json:"fields"`
|
||||
|
||||
// @todo? TBD? excludeModuleFields, includeModuleFields <- if passed filter module field accordingly.
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user