初步实现device_controller
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user