44 lines
899 B
Go
44 lines
899 B
Go
package antrianoperasi
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AntrianOperasiHandler struct {
|
|
repo IAntrianOperasiRepository
|
|
}
|
|
|
|
func NewAntrianOperasiHandler(repo IAntrianOperasiRepository) AntrianOperasiHandler {
|
|
return AntrianOperasiHandler{repo}
|
|
}
|
|
|
|
func (h AntrianOperasiHandler) CreateAntrianOperasi(c *gin.Context) {
|
|
var req CreatePasienOperasiRequest
|
|
// Binding format JSON
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
log.Printf("error bind json : %s", err)
|
|
c.JSON(500, err)
|
|
return
|
|
}
|
|
|
|
// Request data master validation
|
|
errValidation := req.DataValidation()
|
|
if errValidation != nil {
|
|
log.Printf("validation error : %s", errValidation)
|
|
c.JSON(500, errValidation)
|
|
return
|
|
}
|
|
|
|
// Start insert database
|
|
res, err := h.repo.CreateAntrianOperasi(c, req)
|
|
if err != nil {
|
|
log.Printf("insert error : %s", err)
|
|
c.JSON(500, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(201, res)
|
|
}
|