初步实现device_controller

This commit is contained in:
2025-09-12 17:18:14 +08:00
parent 4a78aa1c20
commit fe9b0db985
5 changed files with 273 additions and 24 deletions

View File

@@ -20,6 +20,9 @@ type DeviceRepository interface {
// FindByIDString 根据字符串形式的主键 ID 查找设备,方便控制器调用
FindByIDString(id string) (*models.Device, error)
// ListAll 获取所有设备的列表
ListAll() ([]*models.Device, error)
// ListByParentID 根据父级 ID 列出所有子设备。
// 如果 parentID 为 nil则列出所有顶层设备如区域主控
ListByParentID(parentID *uint) ([]*models.Device, error)
@@ -67,6 +70,15 @@ func (r *gormDeviceRepository) FindByIDString(id string) (*models.Device, error)
return r.FindByID(uint(idInt))
}
// ListAll 获取所有设备的列表
func (r *gormDeviceRepository) ListAll() ([]*models.Device, error) {
var devices []*models.Device
if err := r.db.Find(&devices).Error; err != nil {
return nil, err
}
return devices, nil
}
// ListByParentID 根据父级 ID 列出所有子设备
func (r *gormDeviceRepository) ListByParentID(parentID *uint) ([]*models.Device, error) {
var devices []*models.Device