From aa017342bfda3e79dee640bcc336bcec5bf0c094 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 27 May 2024 17:46:02 -0400 Subject: cmd/mi/services/switchtracker: fix getting individual switches, add tests Signed-off-by: Xe Iaso --- cmd/mi/models/dao.go | 2 +- cmd/mi/models/switch.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'cmd/mi/models') diff --git a/cmd/mi/models/dao.go b/cmd/mi/models/dao.go index 3241d5e..b00ed96 100644 --- a/cmd/mi/models/dao.go +++ b/cmd/mi/models/dao.go @@ -129,7 +129,7 @@ func (d *DAO) GetSwitch(ctx context.Context, id string) (*Switch, error) { var sw Switch if err := d.db.WithContext(ctx). Joins("Member"). - Where("id = ?", id). + Where("switches.id = ?", id). First(&sw).Error; err != nil { return nil, err } diff --git a/cmd/mi/models/switch.go b/cmd/mi/models/switch.go index ec85a1c..5a16dd6 100644 --- a/cmd/mi/models/switch.go +++ b/cmd/mi/models/switch.go @@ -17,7 +17,11 @@ type Switch struct { } // AsProto converts a Switch to its protobuf representation. -func (s Switch) AsProto() *pb.Switch { +func (s *Switch) AsProto() *pb.Switch { + if s == nil { + return nil + } + var endedAt string if s.EndedAt != nil { -- cgit v1.2.3