validops-east-1's picture
restructure repo into production layout; add whatsapp-service, tests, ddl, docs, scripts; scrub hardcoded secrets
83d6851
Raw
History Blame Contribute Delete
1.41 kB
package call_handler
import (
"net/http"
call_service "agentdeck-whatsapp-service/pkg/call/service"
instance_model "agentdeck-whatsapp-service/pkg/instance/model"
"github.com/gin-gonic/gin"
)
type CallHandler interface {
RejectCall(ctx *gin.Context)
}
type callHandler struct {
callService call_service.CallService
}
// Reject call
// @Summary Reject call
// @Description Reject call
// @Tags Call
// @Accept json
// @Produce json
// @Param message body call_service.RejectCallStruct true "Call data"
// @Success 200 {object} gin.H "success"
// @Failure 500 {object} gin.H "Internal server error"
// @Router /call/reject [post]
func (g *callHandler) RejectCall(ctx *gin.Context) {
getInstance := ctx.MustGet("instance")
instance, ok := getInstance.(*instance_model.Instance)
if !ok {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "instance not found"})
return
}
var data *call_service.RejectCallStruct
err := ctx.ShouldBindBodyWithJSON(&data)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = g.callService.RejectCall(data, instance)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
ctx.JSON(http.StatusOK, gin.H{"message": "success"})
}
func NewCallHandler(
callService call_service.CallService,
) CallHandler {
return &callHandler{
callService: callService,
}
}