From 6c23369c066310c700c77c545e4ce22009e8090f Mon Sep 17 00:00:00 2001 From: ahdan15 Date: Fri, 25 Jul 2025 09:40:58 +0700 Subject: [PATCH] penambahan template --- internal/server/routes.go | 45 +++++++++++------------ pkg/database/satu_data/database.go | 13 +++++++ pkg/database/satu_data/master_location.go | 23 ++++++++++++ pkg/handlers/poliklinik/poliklinik.go | 21 +++++++++++ pkg/models/satu_data/poliklinik.go | 7 ++++ 5 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 pkg/database/satu_data/database.go create mode 100644 pkg/handlers/poliklinik/poliklinik.go create mode 100644 pkg/models/satu_data/poliklinik.go diff --git a/internal/server/routes.go b/internal/server/routes.go index f22c1d6..cfeea4f 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -1,27 +1,29 @@ package server import ( - "net/http" - "fmt" - "log" - "time" - - "github.com/gin-gonic/gin" - - "github.com/a-h/templ" - "io/fs" - "template_blueprint/cmd/web" - "github.com/coder/websocket" - "github.com/gin-contrib/cors" + "github.com/gin-gonic/gin" + "io/fs" + "log" + "net/http" + "template_blueprint/cmd/web" patientHandler "template_blueprint/pkg/handlers/patient" + datapoliklinikHandler "template_blueprint/pkg/handlers/poliklinik" + "time" ) func (s *Server) RegisterRoutes() http.Handler { r := gin.Default() + r.Use(cors.New(cors.Config{ + AllowOrigins: []string{"*"}, // or specific domains like "http://example.com" + AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, + AllowHeaders: []string{"Origin", "Content-Type"}, + AllowCredentials: true, + })) + r.GET("/", s.HelloWorldHandler) r.GET("/websocket", s.websocketHandler) @@ -29,26 +31,21 @@ func (s *Server) RegisterRoutes() http.Handler { staticFiles, _ := fs.Sub(web.Files, "assets") r.StaticFS("/assets", http.FS(staticFiles)) - r.GET("/web", func(c *gin.Context) { - templ.Handler(web.HelloForm()).ServeHTTP(c.Writer, c.Request) - }) - r.POST("/hello", func(c *gin.Context) { web.HelloWebHandler(c.Writer, c.Request) }) - api := r.Group("/api") - patient := api.Group("/patient") + v1 := r.Group("/api") + patient := v1.Group("/patient") { patient.POST("/insertpatient", patientHandler.InsertPatient) patient.GET("/getallpatient", patientHandler.GetAllPatient) } - r.Use(cors.New(cors.Config{ - AllowOrigins: []string{"*"}, // or specific domains like "http://example.com" - AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, - AllowHeaders: []string{"Origin", "Content-Type"}, - AllowCredentials: true, - })) + + Poliklinik := v1.Group("/poliklinik") + { + Poliklinik.GET("/getdata/statuspelayanan/:statuspelayanan", datapoliklinikHandler.GetDataPoliklinik) + } return r } diff --git a/pkg/database/satu_data/database.go b/pkg/database/satu_data/database.go new file mode 100644 index 0000000..09773b0 --- /dev/null +++ b/pkg/database/satu_data/database.go @@ -0,0 +1,13 @@ +package satu_data + +import ( + "gorm.io/gorm" +) + +type DatabaseService struct { + DB *gorm.DB +} + +func NewDatabaseService(db *gorm.DB) *DatabaseService { + return &DatabaseService{DB: db} +} diff --git a/pkg/database/satu_data/master_location.go b/pkg/database/satu_data/master_location.go index 99c9586..9cf9b02 100644 --- a/pkg/database/satu_data/master_location.go +++ b/pkg/database/satu_data/master_location.go @@ -1 +1,24 @@ package satu_data + +import ( + "errors" + "gorm.io/gorm" + "log" + "template_blueprint/pkg/models/satu_data" +) + +func (s *DatabaseService) PoliklinikGetData(Status_pelayanan string) []*satu_data.PoliklinikGetData { + var datapoliklinik []*satu_data.PoliklinikGetData + query := `select dlr."Nama",dlr."Kode",dlr."id" from daftar_lokasi_ruang dlr where dlr."Status_pelayanan" = ?` + errQuery := s.DB.Debug().Raw(query, Status_pelayanan).Scan(&datapoliklinik).Error + if errQuery != nil { + if errors.Is(errQuery, gorm.ErrRecordNotFound) { + errMsg := errors.New("Data Tidak Ditemukan") + log.Println(errMsg) + return nil + } + log.Println(errQuery) + return nil + } + return datapoliklinik +} diff --git a/pkg/handlers/poliklinik/poliklinik.go b/pkg/handlers/poliklinik/poliklinik.go new file mode 100644 index 0000000..ea65962 --- /dev/null +++ b/pkg/handlers/poliklinik/poliklinik.go @@ -0,0 +1,21 @@ +package poliklinik + +import ( + "" + "github.com/gin-gonic/gin" + "log" + "net/http" + "template_blueprint/internal/database" + connDatabase "template_blueprint/pkg/database/satu_data" +) + +func GetDataPoliklinik(c *gin.Context) { + db := database.New().GetDB("satudata") + satudata := connDatabase.NewDatabaseService(db) + statuspelayanan := c.Param("statuspelayanan") + + log.Println("REQUEST", statuspelayanan) + dataPoliklinik := satudata.PoliklinikGetData(statuspelayanan) + + c.JSON(http.StatusOK, dataPoliklinik) +} diff --git a/pkg/models/satu_data/poliklinik.go b/pkg/models/satu_data/poliklinik.go new file mode 100644 index 0000000..a244c80 --- /dev/null +++ b/pkg/models/satu_data/poliklinik.go @@ -0,0 +1,7 @@ +package satu_data + +type PoliklinikGetData struct { + ID string `gorm:"column:id" json:"id"` + Nama string `gorm:"column:name" json:"nama"` + Kode string `gorm:"column:kode" json:"kode"` +}