Rename all *List types to *Set, generated fields rebuilt
This commit is contained in:
@@ -84,6 +84,8 @@ endpoints:
|
||||
entrypoint: manageStructure
|
||||
path: "/nodes/{nodeID}"
|
||||
authentication: []
|
||||
imports:
|
||||
- github.com/cortezaproject/corteza-server/federation/types
|
||||
apis:
|
||||
- name: readExposed
|
||||
method: GET
|
||||
@@ -114,7 +116,7 @@ endpoints:
|
||||
name: composeModuleID
|
||||
required: true
|
||||
title: Compose module id
|
||||
- type: types.ModuleFieldList
|
||||
- type: types.ModuleFieldSet
|
||||
name: fields
|
||||
required: false
|
||||
title: Exposed module fields
|
||||
@@ -165,7 +167,7 @@ endpoints:
|
||||
name: composeModuleID
|
||||
required: true
|
||||
title: Compose module id
|
||||
- type: types.ModuleFieldMappingList
|
||||
- type: types.ModuleFieldMappingSet
|
||||
name: fields
|
||||
required: false
|
||||
title: Exposed module fields
|
||||
|
||||
@@ -11,14 +11,13 @@ package request
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza-server/federation/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/payload"
|
||||
"github.com/go-chi/chi"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/federation/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/payload"
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
// dummy vars to prevent
|
||||
@@ -57,7 +56,7 @@ type (
|
||||
// Fields POST parameter
|
||||
//
|
||||
// Exposed module fields
|
||||
Fields types.ModuleFieldList
|
||||
Fields types.ModuleFieldSet
|
||||
}
|
||||
|
||||
ManageStructureRemoveExposed struct {
|
||||
@@ -103,7 +102,7 @@ type (
|
||||
// Fields POST parameter
|
||||
//
|
||||
// Exposed module fields
|
||||
Fields types.ModuleFieldMappingList
|
||||
Fields types.ModuleFieldMappingSet
|
||||
}
|
||||
|
||||
ManageStructureReadMappings struct {
|
||||
@@ -218,7 +217,7 @@ func (r ManageStructureCreateExposed) GetComposeModuleID() uint64 {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ManageStructureCreateExposed) GetFields() types.ModuleFieldList {
|
||||
func (r ManageStructureCreateExposed) GetFields() types.ModuleFieldSet {
|
||||
return r.Fields
|
||||
}
|
||||
|
||||
@@ -249,12 +248,12 @@ func (r *ManageStructureCreateExposed) Fill(req *http.Request) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// if val, ok := req.Form["fields"]; ok && len(val) > 0 {
|
||||
// r.Fields, err = types.ModuleFieldList(val[0]), nil
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
//if val, ok := req.Form["fields[]"]; ok && len(val) > 0 {
|
||||
// r.Fields, err = types.ModuleFieldSet(val), nil
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -417,7 +416,7 @@ func (r ManageStructureCreateMappings) GetComposeModuleID() uint64 {
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ManageStructureCreateMappings) GetFields() types.ModuleFieldMappingList {
|
||||
func (r ManageStructureCreateMappings) GetFields() types.ModuleFieldMappingSet {
|
||||
return r.Fields
|
||||
}
|
||||
|
||||
@@ -448,12 +447,12 @@ func (r *ManageStructureCreateMappings) Fill(req *http.Request) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// if val, ok := req.Form["fields"]; ok && len(val) > 0 {
|
||||
// r.Fields, err = types.ModuleFieldMappingList(val[0]), nil
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
//if val, ok := req.Form["fields[]"]; ok && len(val) > 0 {
|
||||
// r.Fields, err = types.ModuleFieldMappingSet(val), nil
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
type (
|
||||
ExposedModule struct {
|
||||
ID uint64 `json:"moduleID,string"`
|
||||
NodeID uint64 `json:"nodeID,string"`
|
||||
ComposeModuleID uint64 `json:"composeModuleID,string"`
|
||||
Fields ModuleFieldList `json:"fields"`
|
||||
ID uint64 `json:"moduleID,string"`
|
||||
NodeID uint64 `json:"nodeID,string"`
|
||||
ComposeModuleID uint64 `json:"composeModuleID,string"`
|
||||
Fields ModuleFieldSet `json:"fields"`
|
||||
|
||||
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
ModuleFieldList []*ModuleField
|
||||
ModuleFieldSet []*ModuleField
|
||||
|
||||
ModuleField struct {
|
||||
Kind string `json:"kind"`
|
||||
@@ -18,17 +18,17 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (list ModuleFieldList) Value() (driver.Value, error) {
|
||||
func (list ModuleFieldSet) Value() (driver.Value, error) {
|
||||
return json.Marshal(list)
|
||||
}
|
||||
|
||||
func (list *ModuleFieldList) Scan(value interface{}) error {
|
||||
func (list *ModuleFieldSet) Scan(value interface{}) error {
|
||||
switch value.(type) {
|
||||
case nil:
|
||||
*list = ModuleFieldList{}
|
||||
*list = ModuleFieldSet{}
|
||||
case []uint8:
|
||||
if err := json.Unmarshal(value.([]byte), list); err != nil {
|
||||
return errors.New(fmt.Sprintf("Can not scan '%v' into ModuleFieldList", value))
|
||||
return errors.New(fmt.Sprintf("Can not scan '%v' into ModuleFieldSet", value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
ModuleFieldMappingList []*ModuleFieldMapping
|
||||
ModuleFieldMappingSet []*ModuleFieldMapping
|
||||
|
||||
ModuleFieldMapping struct {
|
||||
Origin ModuleField `json:"origin"`
|
||||
@@ -16,17 +16,17 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (list ModuleFieldMappingList) Value() (driver.Value, error) {
|
||||
func (list ModuleFieldMappingSet) Value() (driver.Value, error) {
|
||||
return json.Marshal(list)
|
||||
}
|
||||
|
||||
func (list *ModuleFieldMappingList) Scan(value interface{}) error {
|
||||
func (list *ModuleFieldMappingSet) Scan(value interface{}) error {
|
||||
switch value.(type) {
|
||||
case nil:
|
||||
*list = ModuleFieldMappingList{}
|
||||
*list = ModuleFieldMappingSet{}
|
||||
case []uint8:
|
||||
if err := json.Unmarshal(value.([]byte), list); err != nil {
|
||||
return errors.New(fmt.Sprintf("Can not scan '%v' into ModuleFieldMappingList", value))
|
||||
return errors.New(fmt.Sprintf("Can not scan '%v' into ModuleFieldMappingSet", value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
|
||||
type (
|
||||
ModuleMapping struct {
|
||||
FederationModuleID uint64 `json:"federationModuleID,string"`
|
||||
ComposeModuleID uint64 `json:"composeModuleID,string"`
|
||||
FieldMapping ModuleFieldMappingList `json:"fields"`
|
||||
FederationModuleID uint64 `json:"federationModuleID,string"`
|
||||
ComposeModuleID uint64 `json:"composeModuleID,string"`
|
||||
FieldMapping ModuleFieldMappingSet `json:"fields"`
|
||||
}
|
||||
|
||||
ModuleMappingFilter struct {
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
|
||||
type (
|
||||
SharedModule struct {
|
||||
ID uint64 `json:"moduleID,string"`
|
||||
NodeID uint64 `json:"nodeID,string"`
|
||||
Handle string `json:"handle"`
|
||||
Name string `json:"name"`
|
||||
ExternalFederationModuleID uint64 `json:"externalFederationModuleID,string"`
|
||||
Fields ModuleFieldList `json:"fields"`
|
||||
ID uint64 `json:"moduleID,string"`
|
||||
NodeID uint64 `json:"nodeID,string"`
|
||||
Handle string `json:"handle"`
|
||||
Name string `json:"name"`
|
||||
ExternalFederationModuleID uint64 `json:"externalFederationModuleID,string"`
|
||||
Fields ModuleFieldSet `json:"fields"`
|
||||
|
||||
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
|
||||
|
||||
@@ -26,7 +26,7 @@ type (
|
||||
UpsertFederationModuleMapping(ctx context.Context, rr ...*types.ModuleMapping) error
|
||||
|
||||
DeleteFederationModuleMapping(ctx context.Context, rr ...*types.ModuleMapping) error
|
||||
DeleteFederationModuleMappingBy(ctx context.Context) error
|
||||
DeleteFederationModuleMappingByFederationModuleIDComposeModuleID(ctx context.Context, federationModuleID uint64, composeModuleID uint64) error
|
||||
|
||||
TruncateFederationModuleMappings(ctx context.Context) error
|
||||
}
|
||||
@@ -74,9 +74,9 @@ func DeleteFederationModuleMapping(ctx context.Context, s FederationModuleMappin
|
||||
return s.DeleteFederationModuleMapping(ctx, rr...)
|
||||
}
|
||||
|
||||
// DeleteFederationModuleMappingBy Deletes FederationModuleMapping from store
|
||||
func DeleteFederationModuleMappingBy(ctx context.Context, s FederationModuleMappings) error {
|
||||
return s.DeleteFederationModuleMappingBy(ctx)
|
||||
// DeleteFederationModuleMappingByFederationModuleIDComposeModuleID Deletes FederationModuleMapping from store
|
||||
func DeleteFederationModuleMappingByFederationModuleIDComposeModuleID(ctx context.Context, s FederationModuleMappings, federationModuleID uint64, composeModuleID uint64) error {
|
||||
return s.DeleteFederationModuleMappingByFederationModuleIDComposeModuleID(ctx, federationModuleID, composeModuleID)
|
||||
}
|
||||
|
||||
// TruncateFederationModuleMappings Deletes all FederationModuleMappings from store
|
||||
|
||||
@@ -5,11 +5,10 @@ types:
|
||||
type: types.ModuleMapping
|
||||
|
||||
fields:
|
||||
- { field: FederationModuleID }
|
||||
- { field: ComposeModuleID }
|
||||
- { field: FederationModuleID, isPrimaryKey: true }
|
||||
- { field: ComposeModuleID, isPrimaryKey: true }
|
||||
- { field: FieldMapping, type: "json.Text" }
|
||||
|
||||
|
||||
lookups:
|
||||
- fields: [FederationModuleID, ComposeModuleID]
|
||||
description: |-
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/cortezaproject/corteza-server/federation/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
@@ -107,6 +106,15 @@ func (s Store) fetchFullPageOfFederationModuleMappings(
|
||||
err error
|
||||
)
|
||||
|
||||
// Make sure we always end our sort by primary keys
|
||||
if sort.Get("rel_federation_module") == nil {
|
||||
sort = append(sort, &filter.SortExpr{Column: "rel_federation_module"})
|
||||
}
|
||||
|
||||
if sort.Get("rel_compose_module") == nil {
|
||||
sort = append(sort, &filter.SortExpr{Column: "rel_compose_module"})
|
||||
}
|
||||
|
||||
// Apply sorting expr from filter to query
|
||||
if q, err = setOrderBy(q, sort, s.sortableFederationModuleMappingColumns()...); err != nil {
|
||||
return nil, err
|
||||
@@ -265,8 +273,10 @@ func (s Store) partialFederationModuleMappingUpdate(ctx context.Context, onlyCol
|
||||
|
||||
err = s.execUpdateFederationModuleMappings(
|
||||
ctx,
|
||||
squirrel.Eq{},
|
||||
s.internalFederationModuleMappingEncoder(res).Skip().Only(onlyColumns...))
|
||||
squirrel.Eq{
|
||||
s.preprocessColumn("cmd.rel_federation_module", ""): s.preprocessValue(res.FederationModuleID, ""), s.preprocessColumn("cmd.rel_compose_module", ""): s.preprocessValue(res.ComposeModuleID, ""),
|
||||
},
|
||||
s.internalFederationModuleMappingEncoder(res).Skip("rel_federation_module", "rel_compose_module").Only(onlyColumns...))
|
||||
if err != nil {
|
||||
return s.config.ErrorHandler(err)
|
||||
}
|
||||
@@ -294,9 +304,11 @@ func (s Store) UpsertFederationModuleMapping(ctx context.Context, rr ...*types.M
|
||||
|
||||
// DeleteFederationModuleMapping Deletes one or more rows from federation_module_mapping table
|
||||
func (s Store) DeleteFederationModuleMapping(ctx context.Context, rr ...*types.ModuleMapping) (err error) {
|
||||
for _, _ = range rr {
|
||||
for _, res := range rr {
|
||||
|
||||
err = s.execDeleteFederationModuleMappings(ctx, squirrel.Eq{})
|
||||
err = s.execDeleteFederationModuleMappings(ctx, squirrel.Eq{
|
||||
s.preprocessColumn("cmd.rel_federation_module", ""): s.preprocessValue(res.FederationModuleID, ""), s.preprocessColumn("cmd.rel_compose_module", ""): s.preprocessValue(res.ComposeModuleID, ""),
|
||||
})
|
||||
if err != nil {
|
||||
return s.config.ErrorHandler(err)
|
||||
}
|
||||
@@ -305,9 +317,12 @@ func (s Store) DeleteFederationModuleMapping(ctx context.Context, rr ...*types.M
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteFederationModuleMappingBy Deletes row from the federation_module_mapping table
|
||||
func (s Store) DeleteFederationModuleMappingBy(ctx context.Context) error {
|
||||
return s.execDeleteFederationModuleMappings(ctx, squirrel.Eq{})
|
||||
// DeleteFederationModuleMappingByFederationModuleIDComposeModuleID Deletes row from the federation_module_mapping table
|
||||
func (s Store) DeleteFederationModuleMappingByFederationModuleIDComposeModuleID(ctx context.Context, federationModuleID uint64, composeModuleID uint64) error {
|
||||
return s.execDeleteFederationModuleMappings(ctx, squirrel.Eq{
|
||||
s.preprocessColumn("cmd.rel_federation_module", ""): s.preprocessValue(federationModuleID, ""),
|
||||
s.preprocessColumn("cmd.rel_compose_module", ""): s.preprocessValue(composeModuleID, ""),
|
||||
})
|
||||
}
|
||||
|
||||
// TruncateFederationModuleMappings Deletes all rows from the federation_module_mapping table
|
||||
@@ -351,6 +366,8 @@ func (s Store) execUpsertFederationModuleMappings(ctx context.Context, set store
|
||||
s.config,
|
||||
s.federationModuleMappingTable(),
|
||||
set,
|
||||
"rel_federation_module",
|
||||
"rel_compose_module",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@@ -459,17 +476,30 @@ func (s Store) collectFederationModuleMappingCursorValues(res *types.ModuleMappi
|
||||
|
||||
// All known primary key columns
|
||||
|
||||
pkRel_federation_module bool
|
||||
|
||||
pkRel_compose_module bool
|
||||
|
||||
collect = func(cc ...string) {
|
||||
for _, c := range cc {
|
||||
switch c {
|
||||
case "rel_federation_module":
|
||||
cursor.Set(c, res.FederationModuleID, false)
|
||||
|
||||
pkRel_federation_module = true
|
||||
case "rel_compose_module":
|
||||
cursor.Set(c, res.ComposeModuleID, false)
|
||||
|
||||
pkRel_compose_module = true
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
collect(cc...)
|
||||
if !hasUnique || !(true) {
|
||||
collect()
|
||||
if !hasUnique || !(pkRel_federation_module && pkRel_compose_module && true) {
|
||||
collect("rel_federation_module", "rel_compose_module")
|
||||
}
|
||||
|
||||
return cursor
|
||||
|
||||
Reference in New Issue
Block a user