package handler import ( "net/http" "satusehat-rssa/internal/integration" "satusehat-rssa/internal/model" "github.com/gin-gonic/gin" ) type CarePlanHandler struct { CarePlan integration.CarePlanInterface } func NewCarePlanHandler(CarePlan integration.CarePlanInterface) *CarePlanHandler { return &CarePlanHandler{CarePlan: CarePlan} } func (h CarePlanHandler) CreateCarePlan(c *gin.Context) { var req model.CarePlanRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } res, err := h.CarePlan.CreateCarePlan(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 CarePlanHandler) UpdateCarePlan(c *gin.Context) { var req model.CarePlanRequest 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.CarePlan.CreateCarePlan(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) }