init project

This commit is contained in:
2025-03-19 13:47:29 +07:00
parent 80d1f95f66
commit f6a2cf3a5b
22 changed files with 677 additions and 24 deletions

View File

@@ -0,0 +1,50 @@
package patient
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"net/http"
"os"
"template_blueprint/internal/database"
"template_blueprint/pkg/database/mongo"
"template_blueprint/pkg/models/patient"
)
func InsertPatient(c *gin.Context) {
local := os.Getenv("MONGODB_DEV_LOCAL")
db := database.New(local).GetDB()
if db == nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
return
}
mongoDB := mongo.NewDatabaseService(db)
var reqInsert *patient.Patient
err := c.Bind(&reqInsert)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
reqInsert.ID = uuid.New().String()
errInsert := mongoDB.InsertPatient(reqInsert)
if errInsert != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": errInsert.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Patient successfully inserted"})
}
func GetAllPatient(c *gin.Context) {
local := os.Getenv("MONGODB_DEV_LOCAL")
db := database.New(local).GetDB()
if db == nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
return
}
mongoDB := mongo.NewDatabaseService(db)
dataPatient, errSelect := mongoDB.GetAllDataPatient()
if errSelect != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()})
return
}
c.JSON(http.StatusOK, dataPatient)
}