Files
api-poliklinik/internal/server/routes.go
2025-04-25 08:48:15 +07:00

56 lines
1.4 KiB
Go

package server
import (
patientHandler "api-poliklinik/pkg/handlers/Patient"
datapoliklinikHandler "api-poliklinik/pkg/handlers/Poliklinik"
datapractitionerHandler "api-poliklinik/pkg/handlers/Practitioner"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"net/http"
)
func (s *Server) RegisterRoutes() http.Handler {
r := gin.Default()
r.GET("/", s.HelloWorldHandler)
r.GET("/health", s.healthHandler)
v1 := r.Group("/api")
Poliklinik := v1.Group("/poliklinik")
{
Poliklinik.GET("/getdata/statuspelayanan/:statuspelayanan", datapoliklinikHandler.GetDataPoliklinik)
}
Practitioner := v1.Group("/practitioner")
{
Practitioner.GET("/getdata", datapractitionerHandler.GetDataPractitioner)
}
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,
}))
return r
}
func (s *Server) HelloWorldHandler(c *gin.Context) {
resp := make(map[string]string)
resp["message"] = "Hello World"
c.JSON(http.StatusOK, resp)
}
func (s *Server) healthHandler(c *gin.Context) {
c.JSON(http.StatusOK, s.db.Health())
}