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

Commit

Permalink
fix nil error
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Sep 28, 2021
1 parent 6906a18 commit 7237044
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions internal/infrastructure/mongo/mongodoc/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,9 @@ func NewWidgetLayout(l *plugin.WidgetLayout) *WidgetLayoutDocument {
Vertically: l.VerticallyExtendable(),
Horizontally: l.HorizontallyExtendable(),
},
Extended: l.Extended(),
Floating: l.Floating(),
DefaultLocation: &WidgetLocationDocument{
Zone: string(l.DefaultLocation().Zone),
Section: string(l.DefaultLocation().Section),
Area: string(l.DefaultLocation().Area),
},
Extended: l.Extended(),
Floating: l.Floating(),
DefaultLocation: NewWidgetLocation(l.DefaultLocation()),
}
}

Expand All @@ -167,20 +163,35 @@ func (d *WidgetLayoutDocument) Model() *plugin.WidgetLayout {
return nil
}

var loc *plugin.WidgetLocation
if d.DefaultLocation != nil {
loc = &plugin.WidgetLocation{
Zone: plugin.WidgetZoneType(d.DefaultLocation.Zone),
Section: plugin.WidgetSectionType(d.DefaultLocation.Section),
Area: plugin.WidgetAreaType(d.DefaultLocation.Area),
}
}

return plugin.NewWidgetLayout(
d.Extendable.Horizontally,
d.Extendable.Vertically,
d.Extended,
d.Floating,
loc,
d.DefaultLocation.Model(),
).Ref()
}

func NewWidgetLocation(l *plugin.WidgetLocation) *WidgetLocationDocument {
if l == nil {
return nil
}

return &WidgetLocationDocument{
Zone: string(l.Zone),
Section: string(l.Section),
Area: string(l.Area),
}
}

func (d *WidgetLocationDocument) Model() *plugin.WidgetLocation {
if d == nil {
return nil
}

return &plugin.WidgetLocation{
Zone: plugin.WidgetZoneType(d.Zone),
Section: plugin.WidgetSectionType(d.Section),
Area: plugin.WidgetAreaType(d.Area),
}
}

0 comments on commit 7237044

Please sign in to comment.