mastering bridging
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"satusehat-rssa/internal/integration"
|
||||
"satusehat-rssa/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ImmunizationHandler struct {
|
||||
Immunization integration.ImmunizationInterface
|
||||
}
|
||||
|
||||
func NewImmunizationHandler(Immunization integration.ImmunizationInterface) *ImmunizationHandler {
|
||||
return &ImmunizationHandler{Immunization: Immunization}
|
||||
}
|
||||
|
||||
func (h ImmunizationHandler) CreateImmunization(c *gin.Context) {
|
||||
var req model.ImmunizationRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
res, err := h.Immunization.CreateImmunization(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 ImmunizationHandler) UpdateImmunization(c *gin.Context) {
|
||||
var req model.ImmunizationRequest
|
||||
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.Immunization.CreateImmunization(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)
|
||||
}
|
||||
Reference in New Issue
Block a user