Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat: Refine dataset import (#26)
Browse files Browse the repository at this point in the history
* - Declare DatasetSchemaFieldID scalar
- Extend AddLayerGroupInput to accept optional markerTitleFieldId
- Use selected Field value as layer name

* - fix mutation variable name
- use representativeFieldID to set layer title
  • Loading branch information
yk-eukarya committed Jul 28, 2021
1 parent 8ad1f80 commit 5dd3dba
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions gqlgen.yml
Expand Up @@ -31,6 +31,8 @@ models:
model: github.com/reearth/reearth-backend/internal/adapter/graphql.PropertySchemaID
PropertySchemaFieldID:
model: github.com/reearth/reearth-backend/internal/adapter/graphql.PropertySchemaFieldID
DatasetSchemaFieldID:
model: github.com/reearth/reearth-backend/internal/adapter/graphql.DatasetSchemaFieldID
TranslatedString:
model: github.com/reearth/reearth-backend/internal/adapter/graphql.Map
Lang:
Expand Down
1 change: 1 addition & 0 deletions internal/adapter/graphql/controller_layer.go
Expand Up @@ -56,6 +56,7 @@ func (c *LayerController) AddGroup(ctx context.Context, ginput *AddLayerGroupInp
Index: ginput.Index,
Name: refToString(ginput.Name),
LinkedDatasetSchemaID: id.DatasetSchemaIDFromRefID(ginput.LinkedDatasetSchemaID),
RepresentativeFieldId: ginput.RepresentativeFieldID,
}, operator)
if err != nil {
return nil, err
Expand Down
13 changes: 7 additions & 6 deletions internal/adapter/graphql/models_gen.go

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

13 changes: 13 additions & 0 deletions internal/adapter/graphql/scalar.go
Expand Up @@ -129,6 +129,19 @@ func UnmarshalPropertySchemaFieldID(v interface{}) (id.PropertySchemaFieldID, er
return id.PropertySchemaFieldID(""), errors.New("invalid ID")
}

func MarshalDatasetSchemaFieldID(t id.DatasetSchemaFieldID) graphql1.Marshaler {
return graphql1.WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, strconv.Quote(t.String()))
})
}

func UnmarshalDatasetSchemaFieldID(v interface{}) (id.DatasetSchemaFieldID, error) {
if tmpStr, ok := v.(string); ok {
return id.DatasetSchemaFieldIDFrom(tmpStr)
}
return id.NewDatasetSchemaFieldID(), errors.New("invalid ID")
}

func MarshalMap(val map[string]string) graphql1.Marshaler {
return graphql1.WriterFunc(func(w io.Writer) {
_ = json.NewEncoder(w).Encode(val)
Expand Down
25 changes: 25 additions & 0 deletions internal/graphql/generated.go

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

8 changes: 7 additions & 1 deletion internal/usecase/interactor/layer.go
Expand Up @@ -354,7 +354,13 @@ func (i *Layer) AddGroup(ctx context.Context, inp interfaces.AddLayerGroupInput,
}

// create item layers
representativeFieldID := datasetSchema.RepresentativeFieldID()
var representativeFieldID *id.DatasetSchemaFieldID
if inp.RepresentativeFieldId != nil {
representativeFieldID = inp.RepresentativeFieldId
} else {
representativeFieldID = datasetSchema.RepresentativeFieldID()
}

layerItems := make([]*layer.Item, 0, len(ds))
layerItemProperties := make([]*property.Property, 0, len(ds))
index := -1
Expand Down
1 change: 1 addition & 0 deletions internal/usecase/interfaces/layer.go
Expand Up @@ -28,6 +28,7 @@ type AddLayerGroupInput struct {
ExtensionID *id.PluginExtensionID
Index *int
LinkedDatasetSchemaID *id.DatasetSchemaID
RepresentativeFieldId *id.DatasetSchemaFieldID
Name string
}

Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Expand Up @@ -25,6 +25,7 @@ scalar PluginExtensionID
scalar PropertySchemaID
scalar PropertySchemaFieldID
scalar TranslatedString
scalar DatasetSchemaFieldID

type LatLng {
lat: Float!
Expand Down Expand Up @@ -995,6 +996,7 @@ input AddLayerGroupInput {
index: Int
linkedDatasetSchemaID: ID
name: String
representativeFieldId: DatasetSchemaFieldID
}

input RemoveLayerInput {
Expand Down

0 comments on commit 5dd3dba

Please sign in to comment.