penambahan template
This commit is contained in:
@@ -1,27 +1,29 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fmt"
|
"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/coder/websocket"
|
||||||
|
|
||||||
"github.com/gin-contrib/cors"
|
"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"
|
patientHandler "template_blueprint/pkg/handlers/patient"
|
||||||
|
datapoliklinikHandler "template_blueprint/pkg/handlers/poliklinik"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) RegisterRoutes() http.Handler {
|
func (s *Server) RegisterRoutes() http.Handler {
|
||||||
r := gin.Default()
|
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("/", s.HelloWorldHandler)
|
||||||
|
|
||||||
r.GET("/websocket", s.websocketHandler)
|
r.GET("/websocket", s.websocketHandler)
|
||||||
@@ -29,26 +31,21 @@ func (s *Server) RegisterRoutes() http.Handler {
|
|||||||
staticFiles, _ := fs.Sub(web.Files, "assets")
|
staticFiles, _ := fs.Sub(web.Files, "assets")
|
||||||
r.StaticFS("/assets", http.FS(staticFiles))
|
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) {
|
r.POST("/hello", func(c *gin.Context) {
|
||||||
web.HelloWebHandler(c.Writer, c.Request)
|
web.HelloWebHandler(c.Writer, c.Request)
|
||||||
})
|
})
|
||||||
|
|
||||||
api := r.Group("/api")
|
v1 := r.Group("/api")
|
||||||
patient := api.Group("/patient")
|
patient := v1.Group("/patient")
|
||||||
{
|
{
|
||||||
patient.POST("/insertpatient", patientHandler.InsertPatient)
|
patient.POST("/insertpatient", patientHandler.InsertPatient)
|
||||||
patient.GET("/getallpatient", patientHandler.GetAllPatient)
|
patient.GET("/getallpatient", patientHandler.GetAllPatient)
|
||||||
}
|
}
|
||||||
r.Use(cors.New(cors.Config{
|
|
||||||
AllowOrigins: []string{"*"}, // or specific domains like "http://example.com"
|
Poliklinik := v1.Group("/poliklinik")
|
||||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
{
|
||||||
AllowHeaders: []string{"Origin", "Content-Type"},
|
Poliklinik.GET("/getdata/statuspelayanan/:statuspelayanan", datapoliklinikHandler.GetDataPoliklinik)
|
||||||
AllowCredentials: true,
|
}
|
||||||
}))
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|||||||
13
pkg/database/satu_data/database.go
Normal file
13
pkg/database/satu_data/database.go
Normal file
@@ -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}
|
||||||
|
}
|
||||||
@@ -1 +1,24 @@
|
|||||||
package satu_data
|
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
|
||||||
|
}
|
||||||
|
|||||||
21
pkg/handlers/poliklinik/poliklinik.go
Normal file
21
pkg/handlers/poliklinik/poliklinik.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
7
pkg/models/satu_data/poliklinik.go
Normal file
7
pkg/models/satu_data/poliklinik.go
Normal file
@@ -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"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user