Files
urldb/db/repo/pan_repository.go
2025-09-05 01:28:24 +08:00

45 lines
1.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}