From 06f7019cb483dbd9968c51902c24ca8d62de1b54 Mon Sep 17 00:00:00 2001 From: Piyush Chauhan <42397980+pyshx@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:08:21 +0530 Subject: [PATCH] chore(server): add schema to nlslayer simple input (#935) --- server/e2e/gql_nlslayer_test.go | 25 ++++++++++++++++--- server/gql/featureCollection.graphql | 2 +- server/gql/newlayer.graphql | 1 + server/internal/adapter/gql/generated.go | 12 +++++++-- .../adapter/gql/gqlmodel/models_gen.go | 1 + .../adapter/gql/resolver_mutation_nlslayer.go | 1 + .../internal/usecase/interactor/nlslayer.go | 20 ++++++++++++++- .../internal/usecase/interfaces/nlslayer.go | 1 + web/src/classic/gql/graphql-client-api.tsx | 1 + web/src/classic/gql/graphql.schema.json | 12 +++++++++ web/src/services/gql/__gen__/graphql.ts | 1 + 11 files changed, 70 insertions(+), 7 deletions(-) diff --git a/server/e2e/gql_nlslayer_test.go b/server/e2e/gql_nlslayer_test.go index b318b780f9..3c234744e4 100644 --- a/server/e2e/gql_nlslayer_test.go +++ b/server/e2e/gql_nlslayer_test.go @@ -12,13 +12,16 @@ import ( func addNLSLayerSimple(e *httpexpect.Expect, sId string) (GraphQLRequest, *httpexpect.Value, string) { requestBody := GraphQLRequest{ OperationName: "AddNLSLayerSimple", - Query: `mutation AddNLSLayerSimple($layerType: String!, $sceneId: ID!, $config: JSON, $index: Int, $title: String!) { - addNLSLayerSimple(input: { layerType: $layerType, sceneId: $sceneId, config: $config, index: $index, title: $title}) { + Query: `mutation AddNLSLayerSimple($layerType: String!, $sceneId: ID!, $config: JSON, $index: Int, $title: String!, $schema: JSON) { + addNLSLayerSimple(input: { layerType: $layerType, sceneId: $sceneId, config: $config, index: $index, title: $title, schema: $schema}) { layers { id sceneId layerType config + sketch { + customPropertySchema + } } } }`, @@ -58,6 +61,12 @@ func addNLSLayerSimple(e *httpexpect.Expect, sId string) (GraphQLRequest, *httpe "events": "sampleEvents", }, "index": 0, + "schema": map[string]any{ + "id": "schemaId1", + "type": "marker", + "extrudedHeight": 1, + "positions": []float64{1, 2, 3}, + }, }, } @@ -321,6 +330,14 @@ func TestNLSLayerCRUD(t *testing.T) { Value("newLayers").Array(). Length().Equal(1) + res2.Object(). + Value("data").Object(). + Value("node").Object(). + Value("newLayers").Array().First().Object(). + Value("sketch").Object(). + Value("customPropertySchema").Object(). + Value("extrudedHeight").Equal(1) + // Update NLSLayer _, _ = updateNLSLayer(e, layerId) @@ -768,7 +785,9 @@ func TestCustomProperties(t *testing.T) { Value("data").Object(). Value("node").Object(). Value("newLayers").Array().First().Object(). - Value("sketch").Equal(nil) + Value("sketch").Object(). + Value("customPropertySchema").Object(). + Value("extrudedHeight").Equal(1) schema1 := map[string]any{ "id": "schemaId1", diff --git a/server/gql/featureCollection.graphql b/server/gql/featureCollection.graphql index 48a94c7022..a0374c6c76 100644 --- a/server/gql/featureCollection.graphql +++ b/server/gql/featureCollection.graphql @@ -26,7 +26,7 @@ type GeometryCollection { union Geometry = Point | LineString | Polygon | MultiPolygon | GeometryCollection type Feature { - type: String! + type: String! geometry: Geometry! id: ID! properties: JSON diff --git a/server/gql/newlayer.graphql b/server/gql/newlayer.graphql index 34e1fd5e03..88ac08b328 100644 --- a/server/gql/newlayer.graphql +++ b/server/gql/newlayer.graphql @@ -76,6 +76,7 @@ input AddNLSLayerSimpleInput { config: JSON index: Int visible: Boolean + schema: JSON } input RemoveNLSLayerInput { diff --git a/server/internal/adapter/gql/generated.go b/server/internal/adapter/gql/generated.go index 3febe7f225..3b987d6f64 100644 --- a/server/internal/adapter/gql/generated.go +++ b/server/internal/adapter/gql/generated.go @@ -8727,7 +8727,7 @@ type GeometryCollection { union Geometry = Point | LineString | Polygon | MultiPolygon | GeometryCollection type Feature { - type: String! + type: String! geometry: Geometry! id: ID! properties: JSON @@ -9145,6 +9145,7 @@ input AddNLSLayerSimpleInput { config: JSON index: Int visible: Boolean + schema: JSON } input RemoveNLSLayerInput { @@ -58364,7 +58365,7 @@ func (ec *executionContext) unmarshalInputAddNLSLayerSimpleInput(ctx context.Con asMap[k] = v } - fieldsInOrder := [...]string{"layerType", "title", "sceneId", "config", "index", "visible"} + fieldsInOrder := [...]string{"layerType", "title", "sceneId", "config", "index", "visible", "schema"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -58413,6 +58414,13 @@ func (ec *executionContext) unmarshalInputAddNLSLayerSimpleInput(ctx context.Con return it, err } it.Visible = data + case "schema": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("schema")) + data, err := ec.unmarshalOJSON2githubᚗcomᚋreearthᚋreearthᚋserverᚋinternalᚋadapterᚋgqlᚋgqlmodelᚐJSON(ctx, v) + if err != nil { + return it, err + } + it.Schema = data } } diff --git a/server/internal/adapter/gql/gqlmodel/models_gen.go b/server/internal/adapter/gql/gqlmodel/models_gen.go index 244839bf7e..0b4e7f69e7 100644 --- a/server/internal/adapter/gql/gqlmodel/models_gen.go +++ b/server/internal/adapter/gql/gqlmodel/models_gen.go @@ -178,6 +178,7 @@ type AddNLSLayerSimpleInput struct { Config JSON `json:"config,omitempty"` Index *int `json:"index,omitempty"` Visible *bool `json:"visible,omitempty"` + Schema JSON `json:"schema,omitempty"` } type AddNLSLayerSimplePayload struct { diff --git a/server/internal/adapter/gql/resolver_mutation_nlslayer.go b/server/internal/adapter/gql/resolver_mutation_nlslayer.go index 2c2cb44c06..07b57fdb51 100644 --- a/server/internal/adapter/gql/resolver_mutation_nlslayer.go +++ b/server/internal/adapter/gql/resolver_mutation_nlslayer.go @@ -22,6 +22,7 @@ func (r *mutationResolver) AddNLSLayerSimple(ctx context.Context, input gqlmodel LayerType: gqlmodel.ToNLSLayerType(input.LayerType), Config: gqlmodel.ToNLSConfig(input.Config), Visible: input.Visible, + Schema: gqlmodel.ToGoJsonRef(input.Schema), } layer, err := usecases(ctx).NLSLayer.AddLayerSimple(ctx, inp, getOperator(ctx)) diff --git a/server/internal/usecase/interactor/nlslayer.go b/server/internal/usecase/interactor/nlslayer.go index 7ef6deaeba..56052d472c 100644 --- a/server/internal/usecase/interactor/nlslayer.go +++ b/server/internal/usecase/interactor/nlslayer.go @@ -83,6 +83,20 @@ func (i *NLSLayer) AddLayerSimple(ctx context.Context, inp interfaces.AddNLSLaye return nil, err } + if inp.Schema != nil { + featureCollection := nlslayer.NewFeatureCollection( + "FeatureCollection", + []nlslayer.Feature{}, + ) + sketchInfo := nlslayer.NewSketchInfo( + inp.Schema, + featureCollection, + ) + + layerSimple.SetIsSketch(true) + layerSimple.SetSketch(sketchInfo) + } + err = i.nlslayerRepo.Save(ctx, layerSimple) if err != nil { return nil, err @@ -546,9 +560,13 @@ func (i *NLSLayer) AddCustomProperties(ctx context.Context, inp interfaces.AddCu } if layer.Sketch() == nil { + featureCollection := nlslayer.NewFeatureCollection( + "FeatureCollection", + []nlslayer.Feature{}, + ) sketchInfo := nlslayer.NewSketchInfo( &inp.Schema, - nil, + featureCollection, ) layer.SetIsSketch(true) diff --git a/server/internal/usecase/interfaces/nlslayer.go b/server/internal/usecase/interfaces/nlslayer.go index 3e7f981534..bde4af7537 100644 --- a/server/internal/usecase/interfaces/nlslayer.go +++ b/server/internal/usecase/interfaces/nlslayer.go @@ -16,6 +16,7 @@ type AddNLSLayerSimpleInput struct { LayerType nlslayer.LayerType Config *nlslayer.Config Visible *bool + Schema *map[string]any } type UpdateNLSLayerInput struct { diff --git a/web/src/classic/gql/graphql-client-api.tsx b/web/src/classic/gql/graphql-client-api.tsx index 21b7ab0fee..e91a9f41f5 100644 --- a/web/src/classic/gql/graphql-client-api.tsx +++ b/web/src/classic/gql/graphql-client-api.tsx @@ -137,6 +137,7 @@ export type AddNlsLayerSimpleInput = { index?: InputMaybe; layerType: Scalars['String']['input']; sceneId: Scalars['ID']['input']; + schema?: InputMaybe; title: Scalars['String']['input']; visible?: InputMaybe; }; diff --git a/web/src/classic/gql/graphql.schema.json b/web/src/classic/gql/graphql.schema.json index 9b1a1b4d63..15124e3a3b 100644 --- a/web/src/classic/gql/graphql.schema.json +++ b/web/src/classic/gql/graphql.schema.json @@ -974,6 +974,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "schema", + "description": null, + "type": { + "kind": "SCALAR", + "name": "JSON", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "title", "description": null, diff --git a/web/src/services/gql/__gen__/graphql.ts b/web/src/services/gql/__gen__/graphql.ts index b9b4001af8..cbc34e8811 100644 --- a/web/src/services/gql/__gen__/graphql.ts +++ b/web/src/services/gql/__gen__/graphql.ts @@ -136,6 +136,7 @@ export type AddNlsLayerSimpleInput = { index?: InputMaybe; layerType: Scalars['String']['input']; sceneId: Scalars['ID']['input']; + schema?: InputMaybe; title: Scalars['String']['input']; visible?: InputMaybe; };