调整 ChirpStackListener
This commit is contained in:
40
internal/infra/repository/area_controller_repository.go
Normal file
40
internal/infra/repository/area_controller_repository.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AreaControllerRepository 定义了对 AreaController 模型的数据库操作接口
|
||||
type AreaControllerRepository interface {
|
||||
FindByID(id uint) (*models.AreaController, error)
|
||||
FindByNetworkID(networkID string) (*models.AreaController, error) // New method
|
||||
}
|
||||
|
||||
// gormAreaControllerRepository 是 AreaControllerRepository 的 GORM 实现。
|
||||
type gormAreaControllerRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewGormAreaControllerRepository 创建一个新的 AreaControllerRepository GORM 实现实例。
|
||||
func NewGormAreaControllerRepository(db *gorm.DB) AreaControllerRepository {
|
||||
return &gormAreaControllerRepository{db: db}
|
||||
}
|
||||
|
||||
// FindByID 通过 ID 查找一个 AreaController。
|
||||
func (r *gormAreaControllerRepository) FindByID(id uint) (*models.AreaController, error) {
|
||||
var areaController models.AreaController
|
||||
if err := r.db.First(&areaController, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &areaController, nil
|
||||
}
|
||||
|
||||
// FindByNetworkID 通过 NetworkID 查找一个 AreaController。
|
||||
func (r *gormAreaControllerRepository) FindByNetworkID(networkID string) (*models.AreaController, error) {
|
||||
var areaController models.AreaController
|
||||
if err := r.db.Where("network_id = ?", networkID).First(&areaController).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &areaController, nil
|
||||
}
|
||||
Reference in New Issue
Block a user