feat(contacts): initiate voice calls

This commit is contained in:
2026-06-06 05:44:27 +08:00
parent 2551353e31
commit 689c79bb9c
9 changed files with 467 additions and 29 deletions
@@ -1,11 +1,13 @@
package v1
import (
"errors"
"io"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"github.com/gochat/gochat/internal/model"
"github.com/gochat/gochat/internal/repository"
@@ -288,6 +290,48 @@ func (h *ContactHandler) Delete(c *gin.Context) {
c.Status(http.StatusOK)
}
func (h *ContactHandler) InitiateCall(c *gin.Context) {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
contactID, err := parseUintParam(c, "contact_id")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid contact id"})
return
}
userID := getUserID(c)
if userID == 0 {
c.JSON(http.StatusUnauthorized, gin.H{"error": "user not authenticated"})
return
}
var body struct {
InboxID uint `json:"inbox_id" binding:"required"`
ConversationID *uint `json:"conversation_id"`
}
if bindErr := c.ShouldBindJSON(&body); bindErr != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": bindErr.Error()})
return
}
result, svcErr := h.svc.InitiateCall(c.Request.Context(), accountID, contactID, service.InitiateContactCallRequest{
InboxID: body.InboxID,
ConversationID: body.ConversationID,
UserID: userID,
})
if svcErr != nil {
if errors.Is(svcErr, gorm.ErrRecordNotFound) {
c.JSON(http.StatusNotFound, gin.H{"error": "resource not found"})
return
}
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": svcErr.Error()})
return
}
c.JSON(http.StatusOK, result)
}
func (h *ContactHandler) DeleteAvatar(c *gin.Context) {
accountID := parseAccountIDParam(c)
if accountID == 0 {