53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package contracts
|
|
|
|
import (
|
|
"git.fsdpf.net/go/req"
|
|
"github.com/samber/do"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
type ResEvent string
|
|
|
|
type ResListener interface {
|
|
Insert(new map[string]any, u req.User, id int64) error
|
|
Update(new map[string]any, u req.User, old map[string]any) error
|
|
Delete(old map[string]any, u req.User) error
|
|
GetResource() req.Resource
|
|
GetCode() string
|
|
}
|
|
|
|
type BaseListener struct {
|
|
Container *do.Injector
|
|
res req.Resource // 监听资源
|
|
code string // code
|
|
events []string // 监听动作
|
|
}
|
|
|
|
func (this BaseListener) GetCode() string {
|
|
return this.code
|
|
}
|
|
|
|
func (this BaseListener) GetResource() req.Resource {
|
|
return this.res
|
|
}
|
|
|
|
func (this BaseListener) HasEvent(event string) bool {
|
|
return lo.Contains(this.events, event)
|
|
}
|
|
|
|
func (BaseListener) Insert(new map[string]any, u req.User, id int64) error {
|
|
return nil
|
|
}
|
|
|
|
func (BaseListener) Update(new map[string]any, u req.User, old map[string]any) error {
|
|
return nil
|
|
}
|
|
|
|
func (BaseListener) Delete(old map[string]any, u req.User) error {
|
|
return nil
|
|
}
|
|
|
|
func NewBaseListener(code string, res req.Resource, container *do.Injector) *BaseListener {
|
|
return &BaseListener{code: code, res: res, Container: container}
|
|
}
|