优化mongo,封装count逻辑,处理objectId
This commit is contained in:
@@ -10,24 +10,23 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
AdSource = adSourceService{}
|
||||
)
|
||||
type adSource struct{}
|
||||
|
||||
type adSourceService struct{}
|
||||
// AdSource 广告源服务
|
||||
var AdSource = new(adSource)
|
||||
|
||||
// GetAvailableSources 获取可用的广告源列表
|
||||
func (s *adSourceService) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
||||
func (s *adSource) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
||||
return dao.AdSource.GetAvailableSources(ctx)
|
||||
}
|
||||
|
||||
// GetSourcesByProvider 根据提供商获取广告源
|
||||
func (s *adSourceService) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
||||
func (s *adSource) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
||||
return dao.AdSource.GetSourcesByProvider(ctx, provider)
|
||||
}
|
||||
|
||||
// CreateAdSource 创建广告源
|
||||
func (s *adSourceService) CreateAdSource(ctx context.Context, req *dto.CreateAdSourceReq) (id string, err error) {
|
||||
func (s *adSource) CreateAdSource(ctx context.Context, req *dto.CreateAdSourceReq) (id string, err error) {
|
||||
// 检查广告源名称是否已存在
|
||||
existingSource, err := dao.AdSource.GetByName(ctx, req.Name)
|
||||
if err != nil {
|
||||
@@ -54,7 +53,7 @@ func (s *adSourceService) CreateAdSource(ctx context.Context, req *dto.CreateAdS
|
||||
}
|
||||
|
||||
// UpdateAdSource 更新广告源
|
||||
func (s *adSourceService) UpdateAdSource(ctx context.Context, id string, req *dto.UpdateAdSourceReq) (affected int64, err error) {
|
||||
func (s *adSource) UpdateAdSource(ctx context.Context, id string, req *dto.UpdateAdSourceReq) (affected int64, err error) {
|
||||
|
||||
// 检查广告源是否存在
|
||||
existingSource, err := dao.AdSource.GetByID(ctx, id)
|
||||
@@ -89,7 +88,7 @@ func (s *adSourceService) UpdateAdSource(ctx context.Context, id string, req *dt
|
||||
}
|
||||
|
||||
// DeleteAdSource 删除广告源
|
||||
func (s *adSourceService) DeleteAdSource(ctx context.Context, id string) (affected int64, err error) {
|
||||
func (s *adSource) DeleteAdSource(ctx context.Context, id string) (affected int64, err error) {
|
||||
// 检查广告源是否存在
|
||||
existingSource, err := dao.AdSource.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
@@ -103,6 +102,6 @@ func (s *adSourceService) DeleteAdSource(ctx context.Context, id string) (affect
|
||||
}
|
||||
|
||||
// GetAdSourceByID 根据ID获取广告源
|
||||
func (s *adSourceService) GetAdSourceByID(ctx context.Context, id string) (adSource *entity.AdSource, err error) {
|
||||
func (s *adSource) GetAdSourceByID(ctx context.Context, id string) (adSource *entity.AdSource, err error) {
|
||||
return dao.AdSource.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user