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,6 +3,7 @@ package api
import (
"mayfly-go/internal/msg/application"
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
)
@@ -16,5 +17,7 @@ func (m *Msg) GetMsgs(rc *req.Ctx) {
condition := &entity.Msg{
RecipientId: int64(rc.LoginAccount.Id),
}
rc.ResData = m.MsgApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Msg))
res, err := m.MsgApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Msg))
biz.ErrIsNil(err)
rc.ResData = res
}

View File

@@ -10,7 +10,7 @@ import (
)
type Msg interface {
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
Create(msg *entity.Msg)
@@ -28,7 +28,7 @@ type msgAppImpl struct {
msgRepo repository.Msg
}
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
}

View File

@@ -2,11 +2,12 @@ package repository
import (
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/pkg/base"
"mayfly-go/pkg/model"
)
type Msg interface {
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
base.Repo[*entity.Msg]
Insert(msg *entity.Msg)
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
}

View File

@@ -3,22 +3,20 @@ package persistence
import (
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/internal/msg/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/base"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
type msgRepoImpl struct{}
func newMsgRepo() repository.Msg {
return new(msgRepoImpl)
type msgRepoImpl struct {
base.RepoImpl[*entity.Msg]
}
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
func newMsgRepo() repository.Msg {
return &msgRepoImpl{base.RepoImpl[*entity.Msg]{M: new(entity.Msg)}}
}
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *msgRepoImpl) Insert(account *entity.Msg) {
biz.ErrIsNil(gormx.Insert(account), "新增消息记录失败")
}