antrean tes

This commit is contained in:
2025-12-01 11:32:33 +07:00
parent 266d937c51
commit bd02bb83a7
7 changed files with 302 additions and 11 deletions
+89
View File
@@ -0,0 +1,89 @@
package antrean
import (
"github.com/gin-gonic/gin"
"net/http"
"strconv"
"template_blueprint/internal/database"
connDatabase "template_blueprint/pkg/database/satu_data"
"template_blueprint/pkg/models/antrean"
)
func GetKios(c *gin.Context) {
db := database.New().GetDB("antrean")
satudata := connDatabase.NewDatabaseService(db)
var req *antrean.Request
err := c.Bind(&req)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
DataKios, errInsertData := satudata.GetKios(req.ID)
if errInsertData != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": errInsertData.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{
"message": "Data Ditemukan",
"data": DataKios,
})
}
func InsertKios(c *gin.Context) {
db := database.New().GetDB("antrean")
satudata := connDatabase.NewDatabaseService(db)
var req *antrean.KioskData
err := c.Bind(&req)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
errInsertData := satudata.InsertKiosk(req)
if errInsertData != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": errInsertData.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{"message": "Data Berhasil disimpan"})
}
func UpdateKios(c *gin.Context) {
db := database.New().GetDB("antrean")
satudata := connDatabase.NewDatabaseService(db)
ID := c.Param("id")
var req *antrean.KioskData
err := c.Bind(&req)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = satudata.UpdateKiosk(ID, req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Data kios berhasil diupdate"})
}
func DeleteKios(c *gin.Context) {
db := database.New().GetDB("antrean")
satudata := connDatabase.NewDatabaseService(db)
idParam := c.Param("id")
id, err := strconv.ParseInt(idParam, 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid ID"})
return
}
if err := satudata.DeleteKiosk(id); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Kios Berhasil di delete"})
}