on going installation

This commit is contained in:
vanilia
2025-11-13 11:39:12 +07:00
parent 3e8a3610cf
commit 91afde0624
7 changed files with 22 additions and 76 deletions
@@ -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{}
@@ -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))
}
@@ -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"
@@ -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 {
@@ -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
@@ -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
@@ -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,
})
}