mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: code review
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"mayfly-go/internal/db/api/vo"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
type Db struct {
|
||||
DbApp application.Db
|
||||
DbSqlExecApp application.DbSqlExec
|
||||
MsgApp sysapp.Msg
|
||||
MsgApp msgapp.Msg
|
||||
TagApp tagapp.TagTree
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package router
|
||||
import (
|
||||
"mayfly-go/internal/db/api"
|
||||
"mayfly-go/internal/db/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
"mayfly-go/pkg/req"
|
||||
|
||||
@@ -16,7 +16,7 @@ func InitDbRouter(router *gin.RouterGroup) {
|
||||
d := &api.Db{
|
||||
DbApp: application.GetDbApp(),
|
||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||
MsgApp: sysapp.GetMsgApp(),
|
||||
MsgApp: msgapp.GetMsgApp(),
|
||||
TagApp: tagapp.GetTagTreeApp(),
|
||||
}
|
||||
// 获取所有数据库列表
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
type MachineFile struct {
|
||||
MachineFileApp application.MachineFile
|
||||
MsgApp sysApplication.Msg
|
||||
MsgApp msgapp.Msg
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package router
|
||||
import (
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
"mayfly-go/pkg/req"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,7 +14,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
|
||||
{
|
||||
mf := &api.MachineFile{
|
||||
MachineFileApp: application.GetMachineFileApp(),
|
||||
MsgApp: sysApplication.GetMsgApp(),
|
||||
MsgApp: msgapp.GetMsgApp(),
|
||||
}
|
||||
|
||||
// 获取指定机器文件列表
|
||||
|
||||
20
server/internal/msg/api/msg.go
Normal file
20
server/internal/msg/api/msg.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/msg/application"
|
||||
"mayfly-go/internal/msg/domain/entity"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
)
|
||||
|
||||
type Msg struct {
|
||||
MsgApp application.Msg
|
||||
}
|
||||
|
||||
// 获取账号接收的消息列表
|
||||
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))
|
||||
}
|
||||
13
server/internal/msg/application/application.go
Normal file
13
server/internal/msg/application/application.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/msg/infrastructure/persistence"
|
||||
)
|
||||
|
||||
var (
|
||||
msgApp = newMsgApp(persistence.GetMsgRepo())
|
||||
)
|
||||
|
||||
func GetMsgApp() Msg {
|
||||
return msgApp
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/internal/msg/domain/entity"
|
||||
"mayfly-go/internal/msg/domain/repository"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/ws"
|
||||
"time"
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/msg/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/internal/msg/domain/entity"
|
||||
"mayfly-go/internal/msg/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
@@ -0,0 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import "mayfly-go/internal/msg/domain/repository"
|
||||
|
||||
var (
|
||||
msgRepo = newMsgRepo()
|
||||
)
|
||||
|
||||
func GetMsgRepo() repository.Msg {
|
||||
return msgRepo
|
||||
}
|
||||
21
server/internal/msg/router/msg.go
Normal file
21
server/internal/msg/router/msg.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/msg/api"
|
||||
"mayfly-go/internal/msg/application"
|
||||
"mayfly-go/pkg/req"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitMsgRouter(router *gin.RouterGroup) {
|
||||
msg := router.Group("msgs")
|
||||
a := &api.Msg{
|
||||
MsgApp: application.GetMsgApp(),
|
||||
}
|
||||
{
|
||||
msg.GET("/self", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).Handle(a.GetMsgs)
|
||||
})
|
||||
}
|
||||
}
|
||||
7
server/internal/msg/router/router.go
Normal file
7
server/internal/msg/router/router.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package router
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func Init(router *gin.RouterGroup) {
|
||||
InitMsgRouter(router)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
msgentity "mayfly-go/internal/msg/domain/entity"
|
||||
"mayfly-go/internal/sys/api/form"
|
||||
"mayfly-go/internal/sys/api/vo"
|
||||
"mayfly-go/internal/sys/application"
|
||||
@@ -31,7 +33,7 @@ type Account struct {
|
||||
AccountApp application.Account
|
||||
ResourceApp application.Resource
|
||||
RoleApp application.Role
|
||||
MsgApp application.Msg
|
||||
MsgApp msgapp.Msg
|
||||
ConfigApp application.Config
|
||||
}
|
||||
|
||||
@@ -257,7 +259,7 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
|
||||
a.AccountApp.Update(updateAccount)
|
||||
|
||||
// 创建登录消息
|
||||
loginMsg := &entity.Msg{
|
||||
loginMsg := &msgentity.Msg{
|
||||
RecipientId: int64(account.Id),
|
||||
Msg: fmt.Sprintf("于[%s]-[%s]登录", ip, now.Format("2006-01-02 15:04:05")),
|
||||
Type: 1,
|
||||
@@ -296,14 +298,6 @@ func (a *Account) UpdateAccount(rc *req.Ctx) {
|
||||
a.AccountApp.Update(updateAccount)
|
||||
}
|
||||
|
||||
// 获取账号接收的消息列表
|
||||
func (a *Account) GetMsgs(rc *req.Ctx) {
|
||||
condition := &entity.Msg{
|
||||
RecipientId: int64(rc.LoginAccount.Id),
|
||||
}
|
||||
rc.ResData = a.MsgApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Msg))
|
||||
}
|
||||
|
||||
/** 后台账号操作 **/
|
||||
|
||||
// @router /accounts [get]
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
var (
|
||||
accountApp = newAccountApp(persistence.GetAccountRepo())
|
||||
configApp = newConfigApp(persistence.GetConfigRepo())
|
||||
msgApp = newMsgApp(persistence.GetMsgRepo())
|
||||
resourceApp = newResourceApp(persistence.GetResourceRepo())
|
||||
roleApp = newRoleApp(persistence.GetRoleRepo())
|
||||
syslogApp = newSyslogApp(persistence.GetSyslogRepo())
|
||||
@@ -21,10 +20,6 @@ func GetConfigApp() Config {
|
||||
return configApp
|
||||
}
|
||||
|
||||
func GetMsgApp() Msg {
|
||||
return msgApp
|
||||
}
|
||||
|
||||
func GetResourceApp() Resource {
|
||||
return resourceApp
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.P
|
||||
func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
|
||||
lg := req.LoginAccount
|
||||
if lg == nil {
|
||||
return
|
||||
lg = &model.LoginAccount{Id: 0, Username: "-"}
|
||||
}
|
||||
syslog := new(entity.Syslog)
|
||||
syslog.CreateTime = time.Now()
|
||||
|
||||
@@ -5,7 +5,6 @@ import "mayfly-go/internal/sys/domain/repository"
|
||||
var (
|
||||
accountRepo = newAccountRepo()
|
||||
configRepo = newConfigRepo()
|
||||
msgRepo = newMsgRepo()
|
||||
resourceRepo = newResourceRepo()
|
||||
roleRepo = newRoleRepo()
|
||||
syslogRepo = newSyslogRepo()
|
||||
@@ -19,10 +18,6 @@ func GetConfigRepo() repository.Config {
|
||||
return configRepo
|
||||
}
|
||||
|
||||
func GetMsgRepo() repository.Msg {
|
||||
return msgRepo
|
||||
}
|
||||
|
||||
func GetResourceRepo() repository.Resource {
|
||||
return resourceRepo
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
msgapp "mayfly-go/internal/msg/application"
|
||||
"mayfly-go/internal/sys/api"
|
||||
"mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/req"
|
||||
@@ -14,7 +15,7 @@ func InitAccountRouter(router *gin.RouterGroup) {
|
||||
AccountApp: application.GetAccountApp(),
|
||||
ResourceApp: application.GetResourceApp(),
|
||||
RoleApp: application.GetRoleApp(),
|
||||
MsgApp: application.GetMsgApp(),
|
||||
MsgApp: msgapp.GetMsgApp(),
|
||||
ConfigApp: application.GetConfigApp(),
|
||||
}
|
||||
{
|
||||
@@ -56,10 +57,6 @@ func InitAccountRouter(router *gin.RouterGroup) {
|
||||
req.NewCtxWithGin(c).Handle(a.UpdateAccount)
|
||||
})
|
||||
|
||||
account.GET("/msgs", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).Handle(a.GetMsgs)
|
||||
})
|
||||
|
||||
/** 后台管理接口 **/
|
||||
|
||||
// 获取所有用户列表
|
||||
|
||||
Reference in New Issue
Block a user