mastering bridging
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"satusehat-rssa/internal/integration"
|
||||
"satusehat-rssa/internal/model"
|
||||
"satusehat-rssa/pkg/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type CompositionHandler struct {
|
||||
Composition integration.CompositionInterface
|
||||
}
|
||||
|
||||
func NewCompositionHandler(composition integration.CompositionInterface) *CompositionHandler {
|
||||
return &CompositionHandler{
|
||||
Composition: composition,
|
||||
}
|
||||
}
|
||||
|
||||
func (ch *CompositionHandler) CreateComposition(c *gin.Context) {
|
||||
var req model.CompositionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
req.Identifier = common.GetIdentifier("composition")
|
||||
resp, err := ch.Composition.CreateComposition(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (ch *CompositionHandler) UpdateComposition(c *gin.Context) {
|
||||
var req model.CompositionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req.Identifier = common.GetIdentifier("composition")
|
||||
req.Id = c.Param("id")
|
||||
resp, err := ch.Composition.UpdateComposition(req)
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user