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.
100 lines
3.2 KiB
Go
100 lines
3.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gochat/gochat/internal/service"
|
|
"github.com/gochat/gochat/pkg/response"
|
|
)
|
|
|
|
// AgentBulkHandler handles bulk assignment/unassignment of conversations to agents.
|
|
// Reference: Chatwoot app/controllers/api/v1/accounts/agents_controller.rb #bulk_assign, #bulk_unassign
|
|
type AgentBulkHandler struct {
|
|
conversationSvc *service.ConversationService
|
|
}
|
|
|
|
// NewAgentBulkHandler creates a new AgentBulkHandler.
|
|
func NewAgentBulkHandler(conversationSvc *service.ConversationService) *AgentBulkHandler {
|
|
return &AgentBulkHandler{conversationSvc: conversationSvc}
|
|
}
|
|
|
|
// BulkAssignRequest is the DTO for bulk assigning conversations to an agent.
|
|
type BulkAssignRequest struct {
|
|
ConversationIDs []uint `json:"conversation_ids" binding:"required,min=1"`
|
|
AgentID uint `json:"agent_id" binding:"required"`
|
|
}
|
|
|
|
// BulkAssign assigns multiple conversations to a single agent.
|
|
// POST /api/v1/accounts/:account_id/agents/bulk_assign
|
|
func (h *AgentBulkHandler) BulkAssign(c *gin.Context) {
|
|
accountID, err := parseUintParam(c, "account_id")
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
|
return
|
|
}
|
|
|
|
var req BulkAssignRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
|
return
|
|
}
|
|
|
|
results := make([]map[string]interface{}, 0, len(req.ConversationIDs))
|
|
for _, convID := range req.ConversationIDs {
|
|
_, svcErr := h.conversationSvc.AssignAgent(c.Request.Context(), accountID, convID, req.AgentID)
|
|
if svcErr != nil {
|
|
results = append(results, map[string]interface{}{
|
|
"conversation_id": convID,
|
|
"error": svcErr.Error(),
|
|
})
|
|
} else {
|
|
results = append(results, map[string]interface{}{
|
|
"conversation_id": convID,
|
|
"status": "assigned",
|
|
})
|
|
}
|
|
}
|
|
|
|
response.OK(c, results)
|
|
}
|
|
|
|
// BulkUnassignRequest is the DTO for bulk unassigning conversations from agents.
|
|
type BulkUnassignRequest struct {
|
|
ConversationIDs []uint `json:"conversation_ids" binding:"required,min=1"`
|
|
}
|
|
|
|
// BulkUnassign removes agent assignment from multiple conversations.
|
|
// POST /api/v1/accounts/:account_id/agents/bulk_unassign
|
|
func (h *AgentBulkHandler) BulkUnassign(c *gin.Context) {
|
|
accountID, err := parseUintParam(c, "account_id")
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
|
return
|
|
}
|
|
|
|
var req BulkUnassignRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
|
return
|
|
}
|
|
|
|
results := make([]map[string]interface{}, 0, len(req.ConversationIDs))
|
|
for _, convID := range req.ConversationIDs {
|
|
_, svcErr := h.conversationSvc.UnassignAgent(c.Request.Context(), accountID, convID)
|
|
if svcErr != nil {
|
|
results = append(results, map[string]interface{}{
|
|
"conversation_id": convID,
|
|
"error": svcErr.Error(),
|
|
})
|
|
} else {
|
|
results = append(results, map[string]interface{}{
|
|
"conversation_id": convID,
|
|
"status": "unassigned",
|
|
})
|
|
}
|
|
}
|
|
|
|
response.OK(c, results)
|
|
} |