Skip to content

Commit

Permalink
chore(server): add schema to nlslayer simple input (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyshx authored Mar 21, 2024
1 parent 404eda1 commit 06f7019
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 7 deletions.
25 changes: 22 additions & 3 deletions server/e2e/gql_nlslayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}`,
Expand Down Expand Up @@ -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},
},
},
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion server/gql/featureCollection.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions server/gql/newlayer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ input AddNLSLayerSimpleInput {
config: JSON
index: Int
visible: Boolean
schema: JSON
}

input RemoveNLSLayerInput {
Expand Down
12 changes: 10 additions & 2 deletions server/internal/adapter/gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/internal/adapter/gql/gqlmodel/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/internal/adapter/gql/resolver_mutation_nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 19 additions & 1 deletion server/internal/usecase/interactor/nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions server/internal/usecase/interfaces/nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type AddNLSLayerSimpleInput struct {
LayerType nlslayer.LayerType
Config *nlslayer.Config
Visible *bool
Schema *map[string]any
}

type UpdateNLSLayerInput struct {
Expand Down
1 change: 1 addition & 0 deletions web/src/classic/gql/graphql-client-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export type AddNlsLayerSimpleInput = {
index?: InputMaybe<Scalars['Int']['input']>;
layerType: Scalars['String']['input'];
sceneId: Scalars['ID']['input'];
schema?: InputMaybe<Scalars['JSON']['input']>;
title: Scalars['String']['input'];
visible?: InputMaybe<Scalars['Boolean']['input']>;
};
Expand Down
12 changes: 12 additions & 0 deletions web/src/classic/gql/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions web/src/services/gql/__gen__/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export type AddNlsLayerSimpleInput = {
index?: InputMaybe<Scalars['Int']['input']>;
layerType: Scalars['String']['input'];
sceneId: Scalars['ID']['input'];
schema?: InputMaybe<Scalars['JSON']['input']>;
title: Scalars['String']['input'];
visible?: InputMaybe<Scalars['Boolean']['input']>;
};
Expand Down

0 comments on commit 06f7019

Please sign in to comment.