mastering bridging
This commit is contained in:
71
internal/handler/procedure_handler.go
Normal file
71
internal/handler/procedure_handler.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"satusehat-rssa/internal/integration"
|
||||
"satusehat-rssa/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ProcedureHandler struct {
|
||||
Procedure integration.ProcedureInterface
|
||||
}
|
||||
|
||||
func NewProcedureHandler(procedure integration.ProcedureInterface) *ProcedureHandler {
|
||||
return &ProcedureHandler{
|
||||
Procedure: procedure,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ProcedureHandler) CreateProcedure(c *gin.Context) {
|
||||
var req model.ProcedureRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
result, err := p.Procedure.CreateProcedure(req)
|
||||
if err != nil {
|
||||
if result != nil {
|
||||
c.JSON(http.StatusInternalServerError, result)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (p *ProcedureHandler) GetProcedure(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
result, err := p.Procedure.GetProcedure(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (p *ProcedureHandler) UpdateProcedure(c *gin.Context) {
|
||||
var req model.ProcedureRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
result, err := p.Procedure.UpdateProcedure(req)
|
||||
if err != nil {
|
||||
if result != nil {
|
||||
c.JSON(http.StatusInternalServerError, result)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
Reference in New Issue
Block a user