Skip to content

Commit

Permalink
fix(server): add missing fields to PropertySchema documents. (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya authored Aug 3, 2023
1 parent 99abf5c commit 827c0d4
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions server/internal/infrastructure/mongo/mongodoc/property_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ type PropertySchemaDocument struct {
}

type PropertySchemaGroupDocument struct {
ID string
Fields []*PropertySchemaFieldDocument
List bool
IsAvailableIf *PropertyConditonDocument
Title map[string]string
ID string
Fields []*PropertySchemaFieldDocument
List bool
IsAvailableIf *PropertyConditonDocument
Title map[string]string
RepresentativeFieldID *string `bson:",omitempty"`
}

type PropertySchemaFieldDocument struct {
ID string
Type string
Name map[string]string
Description map[string]string
Prefix string
Suffix string
DefaultValue interface{}
UI *string
Min *float64
Max *float64
Choices []PropertySchemaFieldChoiceDocument
ID string
Type string
Name map[string]string
Description map[string]string
Prefix string
Suffix string
DefaultValue interface{}
UI *string
Min *float64
Max *float64
Choices []PropertySchemaFieldChoiceDocument
IsAvailableIf *PropertyConditonDocument `bson:",omitempty"`
}

type PropertySchemaFieldChoiceDocument struct {
Expand Down Expand Up @@ -73,16 +75,17 @@ func NewPropertySchemaField(f *property.SchemaField) *PropertySchemaFieldDocumen
}

field := &PropertySchemaFieldDocument{
ID: string(f.ID()),
Name: f.Title(),
Suffix: f.Suffix(),
Prefix: f.Prefix(),
Description: f.Description(),
Type: string(f.Type()),
DefaultValue: f.DefaultValue().Value(),
UI: f.UI().StringRef(),
Min: f.Min(),
Max: f.Max(),
ID: string(f.ID()),
Name: f.Title(),
Suffix: f.Suffix(),
Prefix: f.Prefix(),
Description: f.Description(),
Type: string(f.Type()),
DefaultValue: f.DefaultValue().Value(),
UI: f.UI().StringRef(),
Min: f.Min(),
Max: f.Max(),
IsAvailableIf: newPropertyCondition(f.IsAvailableIf()),
}
if choices := f.Choices(); choices != nil {
field.Choices = make([]PropertySchemaFieldChoiceDocument, 0, len(choices))
Expand Down Expand Up @@ -167,6 +170,7 @@ func ToModelPropertySchemaField(f *PropertySchemaFieldDocument) (*property.Schem
MinRef(f.Min).
MaxRef(f.Max).
Choices(choices).
IsAvailableIf(toModelPropertyCondition(f.IsAvailableIf)).
Build()
}

Expand Down Expand Up @@ -232,11 +236,12 @@ func newPropertySchemaGroup(p *property.SchemaGroup) *PropertySchemaGroupDocumen
}

return &PropertySchemaGroupDocument{
ID: string(p.ID()),
List: p.IsList(),
IsAvailableIf: newPropertyCondition(p.IsAvailableIf()),
Title: p.Title(),
Fields: fields,
ID: string(p.ID()),
List: p.IsList(),
IsAvailableIf: newPropertyCondition(p.IsAvailableIf()),
Title: p.Title(),
RepresentativeFieldID: p.RepresentativeFieldID().StringRef(),
Fields: fields,
}
}

Expand All @@ -260,6 +265,7 @@ func (d *PropertySchemaGroupDocument) Model() (*property.SchemaGroup, error) {
Title(d.Title).
IsAvailableIf(toModelPropertyCondition(d.IsAvailableIf)).
Fields(fields).
RepresentativeField(id.PropertyFieldIDFromRef(d.RepresentativeFieldID)).
Build()
}

Expand Down

0 comments on commit 827c0d4

Please sign in to comment.