diff --git a/federation/rest.yaml b/federation/rest.yaml index 04b293b02..c021bb5f2 100644 --- a/federation/rest.yaml +++ b/federation/rest.yaml @@ -299,6 +299,11 @@ endpoints: name: moduleID required: true title: Module ID + get: + - name: composeModuleID + type: uint64 + required: false + title: Compose module id - name: listAll method: GET title: List of shared/exposed/mapped modules @@ -321,7 +326,7 @@ endpoints: - name: mapped type: bool required: false - title: List exposed modules + title: List mapped modules - title: Sync structure description: Sync structure diff --git a/federation/rest/manage_structure.go b/federation/rest/manage_structure.go index e38c57905..491b77c1c 100644 --- a/federation/rest/manage_structure.go +++ b/federation/rest/manage_structure.go @@ -109,8 +109,28 @@ func (ctrl ManageStructure) CreateMappings(ctx context.Context, r *request.Manag return service.DefaultModuleMapping.Create(ctx, mm) } +// ReadMappings outputs an object with the module mappings per each federation module func (ctrl ManageStructure) ReadMappings(ctx context.Context, r *request.ManageStructureReadMappings) (interface{}, error) { - return (service.DefaultModuleMapping).FindByID(ctx, r.ModuleID) + f := types.ModuleMappingFilter{ + NodeID: r.NodeID, + FederationModuleID: r.ModuleID, + } + + if r.ComposeModuleID > 0 { + f.ComposeModuleID = r.ComposeModuleID + } + + set, _, err := service.DefaultModuleMapping.Find(ctx, f) + + if err != nil { + return nil, err + } + + if len(set) != 1 { + return nil, service.ModuleMappingErrNotFound() + } + + return set[0], nil } // ListAll show the list of exposed / shared / mapped modules diff --git a/federation/rest/request/manageStructure.go b/federation/rest/request/manageStructure.go index 17cac1454..016a0dae0 100644 --- a/federation/rest/request/manageStructure.go +++ b/federation/rest/request/manageStructure.go @@ -172,6 +172,11 @@ type ( // // Module ID ModuleID uint64 `json:",string"` + + // ComposeModuleID GET parameter + // + // Compose module id + ComposeModuleID uint64 `json:",string"` } ManageStructureListAll struct { @@ -192,7 +197,7 @@ type ( // Mapped GET parameter // - // List exposed modules + // List mapped modules Mapped bool } ) @@ -728,8 +733,9 @@ func NewManageStructureReadMappings() *ManageStructureReadMappings { // Auditable returns all auditable/loggable parameters func (r ManageStructureReadMappings) Auditable() map[string]interface{} { return map[string]interface{}{ - "nodeID": r.NodeID, - "moduleID": r.ModuleID, + "nodeID": r.NodeID, + "moduleID": r.ModuleID, + "composeModuleID": r.ComposeModuleID, } } @@ -743,6 +749,11 @@ func (r ManageStructureReadMappings) GetModuleID() uint64 { return r.ModuleID } +// Auditable returns all auditable/loggable parameters +func (r ManageStructureReadMappings) GetComposeModuleID() uint64 { + return r.ComposeModuleID +} + // Fill processes request and fills internal variables func (r *ManageStructureReadMappings) Fill(req *http.Request) (err error) { if strings.ToLower(req.Header.Get("content-type")) == "application/json" { @@ -756,6 +767,18 @@ func (r *ManageStructureReadMappings) Fill(req *http.Request) (err error) { } } + { + // GET params + tmp := req.URL.Query() + + if val, ok := tmp["composeModuleID"]; ok && len(val) > 0 { + r.ComposeModuleID, err = payload.ParseUint64(val[0]), nil + if err != nil { + return err + } + } + } + { var val string // path params