aboutsummaryrefslogtreecommitdiff
path: root/cmd/mi/models
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-05-27 17:46:02 -0400
committerXe Iaso <me@xeiaso.net>2024-05-27 17:46:02 -0400
commitaa017342bfda3e79dee640bcc336bcec5bf0c094 (patch)
treede6b13dc44b6f3a397adbc1b2e757f97fcb76b5d /cmd/mi/models
parent9dc5d4799dce590e0bfb334f6cf47fc1fad47618 (diff)
downloadx-aa017342bfda3e79dee640bcc336bcec5bf0c094.tar.xz
x-aa017342bfda3e79dee640bcc336bcec5bf0c094.zip
cmd/mi/services/switchtracker: fix getting individual switches, add tests
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mi/models')
-rw-r--r--cmd/mi/models/dao.go2
-rw-r--r--cmd/mi/models/switch.go6
2 files changed, 6 insertions, 2 deletions
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 {