From 91afde0624c73680444965abc6b707d8bd2f0ebd Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 13 Nov 2025 11:39:12 +0700 Subject: [PATCH] on going installation --- .../installation/handler.go | 2 +- .../simgos-sync-handler.go | 11 ++-- .../main-use-case/installation/case.go | 3 +- .../simgos-sync-use-case/installation/case.go | 4 ++ .../installation/helper.go | 5 +- .../simgos-sync-use-case/installation/lib.go | 9 +-- .../handler-crud-helper.go | 64 ------------------- 7 files changed, 22 insertions(+), 76 deletions(-) diff --git a/internal/interface/simgos-sync-handler/installation/handler.go b/internal/interface/simgos-sync-handler/installation/handler.go index 8e8b15bf..01a6beab 100644 --- a/internal/interface/simgos-sync-handler/installation/handler.go +++ b/internal/interface/simgos-sync-handler/installation/handler.go @@ -7,7 +7,7 @@ import ( // ua "github.com/karincake/tumpeng/auth/svc" e "simrs-vx/internal/domain/main-entities/installation" - u "simrs-vx/internal/use-case/main-use-case/installation" + u "simrs-vx/internal/use-case/simgos-sync-use-case/installation" ) type myBase struct{} diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index ed3246f7..963ec93c 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -2,8 +2,6 @@ package simgossynchandler import ( "net/http" - hc "simrs-vx/pkg/handler-crud-helper" - /******************** infra ********************/ gs "simrs-vx/internal/infra/gorm-setting" @@ -15,11 +13,10 @@ import ( /******************** external ********************/ a "github.com/karincake/apem" + hk "github.com/karincake/hongkue" /******************** internal ********************/ "simrs-vx/internal/interface/main-handler/home" - - /********************* source *********************/ installation "simrs-vx/internal/interface/simgos-sync-handler/installation" ) @@ -35,7 +32,11 @@ func SetRoutes() http.Handler { r.HandleFunc("/", home.Home) /******************** Source ******************/ - hc.RegCrudByCode(r, "/v1/installation", installation.O) + hk.GroupRoutes("/v1/installation", r, hk.MapHandlerFunc{ + "POST /": installation.O.Create, + "PATCH /{id}": installation.O.Update, + "DELETE /{id}": installation.O.Delete, + }) return cmw.SetCors(handlerlogger.SetLog(r)) } diff --git a/internal/use-case/main-use-case/installation/case.go b/internal/use-case/main-use-case/installation/case.go index f66bedaf..f3ce5d59 100644 --- a/internal/use-case/main-use-case/installation/case.go +++ b/internal/use-case/main-use-case/installation/case.go @@ -1,7 +1,6 @@ package installation import ( - e "simrs-vx/internal/domain/main-entities/installation" "strconv" dg "github.com/karincake/apem/db-gorm-pg" @@ -11,6 +10,8 @@ import ( pu "simrs-vx/pkg/use-case-helper" "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/installation" ) const source = "installation" diff --git a/internal/use-case/simgos-sync-use-case/installation/case.go b/internal/use-case/simgos-sync-use-case/installation/case.go index 7d8187cc..398289cd 100644 --- a/internal/use-case/simgos-sync-use-case/installation/case.go +++ b/internal/use-case/simgos-sync-use-case/installation/case.go @@ -27,6 +27,10 @@ func Create(input e.CreateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "create") err := dg.I.Transaction(func(tx *gorm.DB) error { + // TODO: Insert + + // TODO: InsertSimxLog + if resData, err := CreateData(input, &event, tx); err != nil { return err } else { diff --git a/internal/use-case/simgos-sync-use-case/installation/helper.go b/internal/use-case/simgos-sync-use-case/installation/helper.go index d3d96b5c..af56b5c6 100644 --- a/internal/use-case/simgos-sync-use-case/installation/helper.go +++ b/internal/use-case/simgos-sync-use-case/installation/helper.go @@ -6,9 +6,10 @@ package installation import ( e "simrs-vx/internal/domain/main-entities/installation" + esimgos "simrs-vx/internal/domain/simgos-entities/installation" ) -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Installation) { +func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T, data *esimgos.MInstalasi) { var inputSrc *e.CreateDto if inputT, ok := any(input).(*e.CreateDto); ok { inputSrc = inputT @@ -17,6 +18,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Installation) { inputSrc = &inputTemp.CreateDto } + data.NamaInstalasi = inputSrc.Name + data.StatusRawatInap = 1 data.Code = *inputSrc.Code data.Name = inputSrc.Name data.EncounterClass_Code = inputSrc.EncounterClass_Code diff --git a/internal/use-case/simgos-sync-use-case/installation/lib.go b/internal/use-case/simgos-sync-use-case/installation/lib.go index d75b2ecd..07afe61a 100644 --- a/internal/use-case/simgos-sync-use-case/installation/lib.go +++ b/internal/use-case/simgos-sync-use-case/installation/lib.go @@ -1,8 +1,6 @@ package installation import ( - e "simrs-vx/internal/domain/main-entities/installation" - plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" @@ -10,12 +8,15 @@ import ( dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/installation" + esimgos "simrs-vx/internal/domain/simgos-entities/installation" ) -func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Installation, error) { +func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MInstalasi, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") - data := e.Installation{} + data := esimgos.MInstalasi{} setData(&input, &data) var tx *gorm.DB diff --git a/pkg/handler-crud-helper/handler-crud-helper.go b/pkg/handler-crud-helper/handler-crud-helper.go index a5700dad..df475094 100644 --- a/pkg/handler-crud-helper/handler-crud-helper.go +++ b/pkg/handler-crud-helper/handler-crud-helper.go @@ -74,67 +74,3 @@ func RegCrudByCode(r *http.ServeMux, path string, mwAndRouter ...any) { "DELETE /{code}": c.Delete, }) } - -func RegCrudSimgosSync(r *http.ServeMux, path string, mwAndRouter ...any) { - sLength := len(mwAndRouter) - - mwCandidates := mwAndRouter[:sLength-1] - mwList := []hk.HandlerMw{} - for i := range mwCandidates { - // have to do it manually, since casting directly results unexpected result - myType := reflect.TypeOf(mwCandidates[i]) - if myType.String() != "func(http.Handler) http.Handler" { - panic("non middleware included as middleware") - } - mwList = append(mwList, mwCandidates[i].(func(http.Handler) http.Handler)) - - // if g, okHandler := mwCandidates[i].(func(http.Handler) http.Handler); !okHandler { - // panic("non middleware included") - // } else { - // mwList = append(mwList, g) - // } - } - - c, ok := mwAndRouter[sLength-1].(CrudBase) - if !ok { - panic("non CrudBase used in the last paramter") - } - - hk.GroupRoutes(path, r, mwList, hk.MapHandlerFunc{ - "POST /": c.Create, - "PATCH /{id}": c.Update, - "DELETE /{id}": c.Delete, - }) -} - -func RegCrudByCodeSimgosSync(r *http.ServeMux, path string, mwAndRouter ...any) { - sLength := len(mwAndRouter) - - mwCandidates := mwAndRouter[:sLength-1] - mwList := []hk.HandlerMw{} - for i := range mwCandidates { - // have to do it manually, since casting directly results unexpected result - myType := reflect.TypeOf(mwCandidates[i]) - if myType.String() != "func(http.Handler) http.Handler" { - panic("non middleware included as middleware") - } - mwList = append(mwList, mwCandidates[i].(func(http.Handler) http.Handler)) - - // if g, okHandler := mwCandidates[i].(func(http.Handler) http.Handler); !okHandler { - // panic("non middleware included") - // } else { - // mwList = append(mwList, g) - // } - } - - c, ok := mwAndRouter[sLength-1].(CrudBase) - if !ok { - panic("non CrudBase used in the last paramter") - } - - hk.GroupRoutes(path, r, mwList, hk.MapHandlerFunc{ - "POST /": c.Create, - "PATCH /{code}": c.Update, - "DELETE /{code}": c.Delete, - }) -}