package v1 import ( "net/http" "github.com/gin-gonic/gin" "github.com/gochat/gochat/internal/service" "github.com/gochat/gochat/pkg/response" ) // NotionIntegrationHandler handles Notion integration endpoints. // Reference: Chatwoot Integrations::NotionController type NotionIntegrationHandler struct { svc *service.NotionIntegrationService } // NewNotionIntegrationHandler creates a new NotionIntegrationHandler. func NewNotionIntegrationHandler(svc *service.NotionIntegrationService) *NotionIntegrationHandler { return &NotionIntegrationHandler{svc: svc} } // Authorization creates a Notion OAuth authorization URL. // POST /api/v1/accounts/:account_id/notion/authorization func (h *NotionIntegrationHandler) Authorization(c *gin.Context) { accountID, err := parseUintParam(c, "account_id") if err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id") return } result, svcErr := h.svc.BuildAuthorizationURL(accountID) if svcErr != nil { c.JSON(http.StatusUnprocessableEntity, gin.H{"success": false}) return } c.JSON(http.StatusOK, result) } // Delete removes a Notion integration for an account. // DELETE /api/v1/accounts/:account_id/integrations/notion func (h *NotionIntegrationHandler) Delete(c *gin.Context) { accountID, err := parseUintParam(c, "account_id") if err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id") return } if svcErr := h.svc.Delete(c.Request.Context(), accountID); svcErr != nil { handleServiceError(c, svcErr) return } c.Status(http.StatusOK) } // RegisterNotionIntegrationRoutes registers Notion integration routes. func RegisterNotionIntegrationRoutes(g *gin.RouterGroup, h *NotionIntegrationHandler) { g.DELETE("/notion", h.Delete) notion := g.Group("/notion") { notion.DELETE("/", h.Delete) } }