mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 03:15:04 +08:00
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package repo
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/ctwj/urldb/db/entity"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// PanRepository Pan的Repository接口
|
||
type PanRepository interface {
|
||
BaseRepository[entity.Pan]
|
||
FindWithCks() ([]entity.Pan, error)
|
||
FindIdByServiceType(serviceType string) (int, error)
|
||
}
|
||
|
||
// PanRepositoryImpl Pan的Repository实现
|
||
type PanRepositoryImpl struct {
|
||
BaseRepositoryImpl[entity.Pan]
|
||
}
|
||
|
||
// NewPanRepository 创建Pan Repository
|
||
func NewPanRepository(db *gorm.DB) PanRepository {
|
||
return &PanRepositoryImpl{
|
||
BaseRepositoryImpl: BaseRepositoryImpl[entity.Pan]{db: db},
|
||
}
|
||
}
|
||
|
||
// FindWithCks 查找包含Cks的Pan
|
||
func (r *PanRepositoryImpl) FindWithCks() ([]entity.Pan, error) {
|
||
var pans []entity.Pan
|
||
err := r.db.Preload("Cks").Find(&pans).Error
|
||
return pans, err
|
||
}
|
||
|
||
func (r *PanRepositoryImpl) FindIdByServiceType(serviceType string) (int, error) {
|
||
var pan entity.Pan
|
||
err := r.db.Where("name = ?", serviceType).Find(&pan).Error
|
||
if err != nil {
|
||
return 0, fmt.Errorf("获取panId失败: %v", serviceType)
|
||
}
|
||
return int(pan.ID), nil
|
||
}
|