refactor: 新增base.Repo与base.App,重构repo与app层代码

This commit is contained in:
meilin.huang
2023-10-26 17:15:49 +08:00
parent 10f6b03fb5
commit a1303b52eb
115 changed files with 1867 additions and 1696 deletions

View File

@@ -3,49 +3,26 @@ package persistence
import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/base"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
type authCertRepoImpl struct{}
func newAuthCertRepo() repository.AuthCert {
return new(authCertRepoImpl)
type authCertRepoImpl struct {
base.RepoImpl[*entity.AuthCert]
}
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
func newAuthCertRepo() repository.AuthCert {
return &authCertRepoImpl{base.RepoImpl[*entity.AuthCert]{M: new(entity.AuthCert)}}
}
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := gormx.NewQuery(new(entity.AuthCert)).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
biz.ErrIsNil(gormx.Insert(ac), "新增授权凭证失败")
}
func (m *authCertRepoImpl) Update(ac *entity.AuthCert) {
biz.ErrIsNil(gormx.UpdateById(ac), "更新授权凭证失败")
}
func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
ac := new(entity.AuthCert)
err := gormx.GetById(ac, id)
if err != nil {
return nil
}
return ac
}
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
acs := new([]*entity.AuthCert)
gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
return *acs
}
func (m *authCertRepoImpl) GetByCondition(condition *entity.AuthCert, cols ...string) error {
return gormx.GetBy(condition, cols...)
}
func (m *authCertRepoImpl) DeleteById(id uint64) {
gormx.DeleteById(new(entity.AuthCert), id)
}
// func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
// acs := new([]*entity.AuthCert)
// gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
// return *acs
// }