Files
satusehat-bridging/internal/handler/medicationstatement_handler.go
2025-11-24 09:13:08 +07:00

61 lines
1.5 KiB
Go

package handler
import (
"fmt"
"net/http"
"satusehat-rssa/internal/integration"
"satusehat-rssa/internal/model"
"github.com/gin-gonic/gin"
)
type MedicationStatementHandler struct {
MedicationStatement integration.MedicationStatementInterface
}
func NewMedicationStatementHandler(MedicationStatement integration.MedicationStatementInterface) *MedicationStatementHandler {
return &MedicationStatementHandler{MedicationStatement: MedicationStatement}
}
func (h MedicationStatementHandler) CreateMedicationStatement(c *gin.Context) {
var req model.MedicationStatementRequest
if err := c.ShouldBindJSON(&req); err != nil {
fmt.Println(err)
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
res, err := h.MedicationStatement.CreateMedicationStatement(req)
if err != nil {
if res != nil {
c.JSON(http.StatusInternalServerError, res)
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, res)
}
func (h MedicationStatementHandler) UpdateMedicationStatement(c *gin.Context) {
var req model.MedicationStatementRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
req.Id = c.Param("id")
res, err := h.MedicationStatement.CreateMedicationStatement(req)
if err != nil {
if res != nil {
c.JSON(http.StatusInternalServerError, res)
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, res)
}