Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
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)
|
|
}
|
|
}
|