mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-10 19:30:25 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -3,62 +3,56 @@ package application
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
base.App[*entity.AuthCert]
|
||||
|
||||
Save(ac *entity.AuthCert)
|
||||
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
GetById(id uint64) *entity.AuthCert
|
||||
Save(ac *entity.AuthCert) error
|
||||
|
||||
GetByIds(ids ...uint64) []*entity.AuthCert
|
||||
|
||||
DeleteById(id uint64)
|
||||
}
|
||||
|
||||
func newAuthCertApp(authCertRepo repository.AuthCert) AuthCert {
|
||||
return &authCertAppImpl{
|
||||
authCertRepo: authCertRepo,
|
||||
base.AppImpl[*entity.AuthCert, repository.AuthCert]{Repo: authCertRepo},
|
||||
}
|
||||
}
|
||||
|
||||
type authCertAppImpl struct {
|
||||
authCertRepo repository.AuthCert
|
||||
base.AppImpl[*entity.AuthCert, repository.AuthCert]
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
return a.GetRepo().GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) Save(ac *entity.AuthCert) {
|
||||
func (a *authCertAppImpl) Save(ac *entity.AuthCert) error {
|
||||
oldAc := &entity.AuthCert{Name: ac.Name}
|
||||
err := a.authCertRepo.GetByCondition(oldAc, "Id", "Name")
|
||||
err := a.GetBy(oldAc, "Id", "Name")
|
||||
|
||||
ac.PwdEncrypt()
|
||||
if ac.Id == 0 {
|
||||
biz.IsTrue(err != nil, "该凭证名已存在")
|
||||
a.authCertRepo.Insert(ac)
|
||||
return
|
||||
if err == nil {
|
||||
return errorx.NewBiz("该凭证名已存在")
|
||||
}
|
||||
return a.Insert(ac)
|
||||
}
|
||||
|
||||
// 如果存在该库,则校验修改的库是否为该库
|
||||
if err == nil {
|
||||
biz.IsTrue(oldAc.Id == ac.Id, "该凭证名已存在")
|
||||
if err == nil && oldAc.Id != ac.Id {
|
||||
return errorx.NewBiz("该凭证名已存在")
|
||||
}
|
||||
a.authCertRepo.Update(ac)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetById(id uint64) *entity.AuthCert {
|
||||
return a.authCertRepo.GetById(id)
|
||||
return a.UpdateById(ac)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||
return a.authCertRepo.GetByIds(ids...)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) DeleteById(id uint64) {
|
||||
a.authCertRepo.DeleteById(id)
|
||||
acs := new([]*entity.AuthCert)
|
||||
a.GetByIdIn(acs, ids)
|
||||
return *acs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user