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.
78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"github.com/gochat/gochat/internal/service"
|
|
"github.com/gochat/gochat/pkg/response"
|
|
)
|
|
|
|
// EmailChannelMigrationHandler handles account-scoped email channel migration endpoints.
|
|
// Reference: Chatwoot api/v1/accounts/:account_id/email_channel_migrations — create-only
|
|
// endpoint for initiating migration of an email channel from one inbox to another.
|
|
type EmailChannelMigrationHandler struct {
|
|
svc *service.EmailChannelMigrationService
|
|
}
|
|
|
|
// NewEmailChannelMigrationHandler creates a new EmailChannelMigrationHandler with service injection.
|
|
func NewEmailChannelMigrationHandler(svc *service.EmailChannelMigrationService) *EmailChannelMigrationHandler {
|
|
return &EmailChannelMigrationHandler{svc: svc}
|
|
}
|
|
|
|
// Create initiates a new email channel migration from one inbox to another.
|
|
// POST /api/v1/accounts/:account_id/email_channel_migrations
|
|
func (h *EmailChannelMigrationHandler) Create(c *gin.Context) {
|
|
accountID := getAccountID(c)
|
|
if accountID == 0 {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
|
return
|
|
}
|
|
|
|
var req struct {
|
|
InboxID uint `json:"inbox_id" binding:"required"`
|
|
TargetInboxID uint `json:"target_inbox_id" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
|
return
|
|
}
|
|
|
|
migration := &model.EmailChannelMigration{
|
|
AccountID: accountID,
|
|
InboxID: req.InboxID,
|
|
TargetInboxID: req.TargetInboxID,
|
|
MigrationStatus: "pending",
|
|
}
|
|
|
|
if svcErr := h.svc.Create(c.Request.Context(), migration); svcErr != nil {
|
|
handleServiceError(c, svcErr)
|
|
return
|
|
}
|
|
response.Created(c, migration)
|
|
}
|
|
|
|
// List retrieves all email channel migrations for the current account.
|
|
// GET /api/v1/accounts/:account_id/email_channel_migrations
|
|
func (h *EmailChannelMigrationHandler) List(c *gin.Context) {
|
|
accountID := getAccountID(c)
|
|
if accountID == 0 {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
|
return
|
|
}
|
|
|
|
migrations, err := h.svc.ListByAccount(c.Request.Context(), accountID)
|
|
if err != nil {
|
|
handleServiceError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, migrations)
|
|
}
|
|
|
|
// RegisterEmailChannelMigrationRoutes registers email channel migration routes on the given router group.
|
|
func RegisterEmailChannelMigrationRoutes(g *gin.RouterGroup, h *EmailChannelMigrationHandler) {
|
|
g.POST("/", h.Create)
|
|
g.GET("/", h.List)
|
|
} |