61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package call_handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
call_service "github.com/evolution-foundation/evolution-go/pkg/call/service"
|
|
instance_model "github.com/evolution-foundation/evolution-go/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,
|
|
}
|
|
}
|