Added structure sync endpoints
This commit is contained in:
@@ -287,3 +287,29 @@ endpoints:
|
||||
type: bool
|
||||
required: false
|
||||
title: List exposed modules
|
||||
|
||||
- title: Sync structure
|
||||
description: Sync structure
|
||||
entrypoint: syncStructure
|
||||
path: ""
|
||||
authentication: []
|
||||
apis:
|
||||
- name: readExposedAll
|
||||
method: GET
|
||||
title: List all exposed modules changes
|
||||
path: "/exposed/modules/"
|
||||
parameters:
|
||||
get:
|
||||
- type: string
|
||||
name: query
|
||||
required: false
|
||||
title: Search query
|
||||
- type: uint
|
||||
name: limit
|
||||
title: Limit
|
||||
- type: string
|
||||
name: pageCursor
|
||||
title: Page cursor
|
||||
- type: string
|
||||
name: sort
|
||||
title: Sort items
|
||||
@@ -0,0 +1,63 @@
|
||||
package handlers
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
//
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
"net/http"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/federation/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
)
|
||||
|
||||
type (
|
||||
// Internal API interface
|
||||
SyncStructureAPI interface {
|
||||
ReadExposedAll(context.Context, *request.SyncStructureReadExposedAll) (interface{}, error)
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
SyncStructure struct {
|
||||
ReadExposedAll func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
)
|
||||
|
||||
func NewSyncStructure(h SyncStructureAPI) *SyncStructure {
|
||||
return &SyncStructure{
|
||||
ReadExposedAll: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewSyncStructureReadExposedAll()
|
||||
if err := params.Fill(r); err != nil {
|
||||
logger.LogParamError("SyncStructure.ReadExposedAll", r, err)
|
||||
resputil.JSON(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.ReadExposedAll(r.Context(), params)
|
||||
if err != nil {
|
||||
logger.LogControllerError("SyncStructure.ReadExposedAll", r, err, params.Auditable())
|
||||
resputil.JSON(w, err)
|
||||
return
|
||||
}
|
||||
logger.LogControllerCall("SyncStructure.ReadExposedAll", r, params.Auditable())
|
||||
if !serveHTTP(value, w, r) {
|
||||
resputil.JSON(w, value)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (h SyncStructure) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middlewares...)
|
||||
r.Get("/exposed/modules/", h.ReadExposedAll)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package request
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
//
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/pkg/payload"
|
||||
"github.com/go-chi/chi"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// dummy vars to prevent
|
||||
// unused imports complain
|
||||
var (
|
||||
_ = chi.URLParam
|
||||
_ = multipart.ErrMessageTooLarge
|
||||
_ = payload.ParseUint64s
|
||||
)
|
||||
|
||||
type (
|
||||
// Internal API interface
|
||||
SyncStructureReadExposedAll struct {
|
||||
// Query GET parameter
|
||||
//
|
||||
// Search query
|
||||
Query string
|
||||
|
||||
// Limit GET parameter
|
||||
//
|
||||
// Limit
|
||||
Limit uint
|
||||
|
||||
// PageCursor GET parameter
|
||||
//
|
||||
// Page cursor
|
||||
PageCursor string
|
||||
|
||||
// Sort GET parameter
|
||||
//
|
||||
// Sort items
|
||||
Sort string
|
||||
}
|
||||
)
|
||||
|
||||
// NewSyncStructureReadExposedAll request
|
||||
func NewSyncStructureReadExposedAll() *SyncStructureReadExposedAll {
|
||||
return &SyncStructureReadExposedAll{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r SyncStructureReadExposedAll) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"query": r.Query,
|
||||
"limit": r.Limit,
|
||||
"pageCursor": r.PageCursor,
|
||||
"sort": r.Sort,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r SyncStructureReadExposedAll) GetQuery() string {
|
||||
return r.Query
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r SyncStructureReadExposedAll) GetLimit() uint {
|
||||
return r.Limit
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r SyncStructureReadExposedAll) GetPageCursor() string {
|
||||
return r.PageCursor
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r SyncStructureReadExposedAll) GetSort() string {
|
||||
return r.Sort
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *SyncStructureReadExposedAll) Fill(req *http.Request) (err error) {
|
||||
if strings.ToLower(req.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(req.Body).Decode(r)
|
||||
|
||||
switch {
|
||||
case err == io.EOF:
|
||||
err = nil
|
||||
case err != nil:
|
||||
return fmt.Errorf("error parsing http request body: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// GET params
|
||||
tmp := req.URL.Query()
|
||||
|
||||
if val, ok := tmp["query"]; ok && len(val) > 0 {
|
||||
r.Query, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["sort"]; ok && len(val) > 0 {
|
||||
r.Sort, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -13,6 +13,7 @@ func MountRoutes(r chi.Router) {
|
||||
|
||||
// temporary because of acl
|
||||
handlers.NewManageStructure((ManageStructure{}.New())).MountRoutes(r)
|
||||
handlers.NewSyncStructure((SyncStructure{}.New())).MountRoutes(r)
|
||||
})
|
||||
|
||||
// Protect all _private_ routes
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/federation/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/federation/service"
|
||||
"github.com/cortezaproject/corteza-server/federation/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
)
|
||||
|
||||
type (
|
||||
SyncStructure struct{}
|
||||
|
||||
TempStruct struct {
|
||||
Filter types.ExposedModuleFilter `json:"filter"`
|
||||
Set types.ExposedModuleSet `json:"set"`
|
||||
}
|
||||
)
|
||||
|
||||
func (SyncStructure) New() *SyncStructure {
|
||||
return &SyncStructure{}
|
||||
}
|
||||
|
||||
func (ctrl SyncStructure) ReadExposedAll(ctx context.Context, r *request.SyncStructureReadExposedAll) (interface{}, error) {
|
||||
// TODO - fixed values for now
|
||||
|
||||
var (
|
||||
err error
|
||||
f = types.ExposedModuleFilter{
|
||||
NodeID: 276342359342989444,
|
||||
}
|
||||
)
|
||||
|
||||
if f.Paging, err = filter.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f.Sorting, err = filter.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list, f, err := (service.ExposedModule()).Find(context.Background(), f)
|
||||
|
||||
return TempStruct{
|
||||
Set: list,
|
||||
Filter: f,
|
||||
}, err
|
||||
}
|
||||
Reference in New Issue
Block a user