package practitioner import ( "api-poliklinik/internal/database" "api-poliklinik/pkg/database/mongo" "github.com/gin-gonic/gin" "net/http" "os" "strconv" ) func GetDataPractitioner(c *gin.Context) { local := os.Getenv("MONGODB_DEV_LOCAL") db := database.New(local).GetMongoDB() if db == nil { c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) return } // Default values limit := int64(0) skip := int64(0) // Ambil dari query jika tersedia if l := c.Query("limit"); l != "" { if parsed, err := strconv.ParseInt(l, 10, 64); err == nil { limit = parsed } } if s := c.Query("skip"); s != "" { if parsed, err := strconv.ParseInt(s, 10, 64); err == nil { skip = parsed } } mongoDB := mongo.NewDatabaseServiceMongo(db) dataPractitioner, errSelect := mongoDB.GetAllPractitioner(limit, skip) if errSelect != nil { c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) return } c.JSON(http.StatusOK, gin.H{ "message": "success", "data": dataPractitioner, }) }