add create installation
This commit is contained in:
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package installation
|
||||
|
||||
import (
|
||||
egos "simrs-vx/internal/domain/simgos-entities/installation"
|
||||
"strconv"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
@@ -18,6 +19,7 @@ const source = "installation"
|
||||
|
||||
func Create(input e.CreateDto) (*d.Data, error) {
|
||||
data := e.Installation{}
|
||||
sgData := egos.MInstalasi{}
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
@@ -29,11 +31,6 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
|
||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPreMw, &input, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
@@ -43,7 +40,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPostMw, &input, &data); err != nil {
|
||||
if err := mwRunner.RunCreateMiddleware(createPostMw, &input, &sgData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package installation
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/installation"
|
||||
egos "simrs-vx/internal/domain/simgos-entities/installation"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
@@ -23,7 +24,7 @@ func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner {
|
||||
}
|
||||
|
||||
// ExecuteCreateMiddleware executes create middleware
|
||||
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.Installation) error {
|
||||
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *egos.MInstalasi) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package installation
|
||||
|
||||
import (
|
||||
plugin "simrs-vx/internal/use-case/simgos-sync-plugin/installation"
|
||||
)
|
||||
|
||||
// example of middleware
|
||||
// func init() {
|
||||
// createPreMw = append(createPreMw,
|
||||
// CreateMw{Name: "modif-input", Func: pm.ModifInput},
|
||||
// CreateMw{Name: "check-data", Func: pm.CheckData},
|
||||
// )
|
||||
// }
|
||||
func init() {
|
||||
createPostMw = append(createPostMw,
|
||||
createMw{Name: "create-installation", Func: plugin.Create},
|
||||
)
|
||||
}
|
||||
@@ -9,6 +9,8 @@ functionality. The purpose of this is to make the code more maintainable.
|
||||
package installation
|
||||
|
||||
import (
|
||||
egos "simrs-vx/internal/domain/simgos-entities/installation"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/installation"
|
||||
@@ -16,7 +18,7 @@ import (
|
||||
|
||||
type createMw struct {
|
||||
Name string
|
||||
Func func(input *e.CreateDto, data *e.Installation, tx *gorm.DB) error
|
||||
Func func(input *e.CreateDto, data *egos.MInstalasi, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readListMw struct {
|
||||
|
||||
Reference in New Issue
Block a user