mastering bridging
This commit is contained in:
58
internal/handler/medicationrequest_handler.go
Normal file
58
internal/handler/medicationrequest_handler.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"satusehat-rssa/internal/integration"
|
||||
"satusehat-rssa/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type MedicationRequestHandler struct {
|
||||
MedicationRequest integration.MedicationRequestInterface
|
||||
}
|
||||
|
||||
func NewMedicationRequestHandler(MedicationRequest integration.MedicationRequestInterface) *MedicationRequestHandler {
|
||||
return &MedicationRequestHandler{MedicationRequest: MedicationRequest}
|
||||
}
|
||||
|
||||
func (h MedicationRequestHandler) CreateMedicationRequest(c *gin.Context) {
|
||||
var req model.MedicationRequestRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
res, err := h.MedicationRequest.CreateMedicationRequest(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 MedicationRequestHandler) UpdateMedicationRequest(c *gin.Context) {
|
||||
var req model.MedicationRequestRequest
|
||||
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.MedicationRequest.CreateMedicationRequest(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