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

feat: Refine dataset import #26

Merged
merged 3 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gqlgen.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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