mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-10 03:10:25 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -3,19 +3,21 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/internal/mongo/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type mongoRepoImpl struct{}
|
||||
type mongoRepoImpl struct {
|
||||
base.RepoImpl[*entity.Mongo]
|
||||
}
|
||||
|
||||
func newMongoRepo() repository.Mongo {
|
||||
return new(mongoRepoImpl)
|
||||
return &mongoRepoImpl{base.RepoImpl[*entity.Mongo]{M: new(entity.Mongo)}}
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQuery(new(entity.Mongo)).
|
||||
Like("name", condition.Name).
|
||||
In("tag_id", condition.TagIds).
|
||||
@@ -31,30 +33,3 @@ func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
||||
}
|
||||
return gormx.CountByCond(new(entity.Mongo), where)
|
||||
}
|
||||
|
||||
// 根据条件获取
|
||||
func (d *mongoRepoImpl) Get(condition *entity.Mongo, cols ...string) error {
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||
db := new(entity.Mongo)
|
||||
if err := gormx.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Insert(db *entity.Mongo) {
|
||||
biz.ErrIsNil(gormx.Insert(db), "新增mongo信息失败")
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Update(db *entity.Mongo) {
|
||||
biz.ErrIsNil(gormx.UpdateById(db), "更新mongo信息失败")
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Delete(id uint64) {
|
||||
gormx.DeleteById(new(entity.Mongo), id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user