Files
2025-07-01 12:42:28 +07:00

103 lines
2.4 KiB
Go

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,
})
}
func Getdatadokter(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
}
display := c.Param("display")
value := c.Param("value")
if display == "" || value == "" {
c.JSON(http.StatusBadRequest, gin.H{"message": "Parameter 'display' dan 'value' dibutuhkan"})
return
}
mongoDB := mongo.NewDatabaseServiceMongo(db)
dataSMF, err := mongoDB.GetDokterBySMF(display, value)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"data": dataSMF,
"message": "Practitioner Dengan SMF berhasil di cari",
})
}
func GetPractitionerbyID(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
}
id := c.Param("id")
if id == "" {
c.JSON(http.StatusBadRequest, gin.H{"message": "Parameter 'id' dibutuhkan"})
return
}
mongoDB := mongo.NewDatabaseServiceMongo(db)
dataID, err := mongoDB.GetDokterByid(id)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"data": dataID,
"message": "Practitioner Dengan ID berhasil di cari",
})
}