From 7237044e0d53ed3a53c3ba27fbcbf683662c50f4 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Tue, 28 Sep 2021 18:12:15 +0900 Subject: [PATCH] fix nil error --- .../infrastructure/mongo/mongodoc/plugin.go | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/internal/infrastructure/mongo/mongodoc/plugin.go b/internal/infrastructure/mongo/mongodoc/plugin.go index 503bb4ba..0ca12189 100644 --- a/internal/infrastructure/mongo/mongodoc/plugin.go +++ b/internal/infrastructure/mongo/mongodoc/plugin.go @@ -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()), } } @@ -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), + } +}