Files
gochat/backend/internal/handler/api/v1/conversation_insight_handler.go
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
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.
2026-07-07 14:44:12 +08:00

98 lines
3.4 KiB
Go

package v1
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/gochat/gochat/internal/service"
applogger "github.com/gochat/gochat/pkg/logger"
"github.com/gochat/gochat/pkg/response"
)
// ConversationInsightHandler handles Captain conversation analysis endpoints.
// Reference: M12 PRD §Captain AI — Participant Analysis, Action Items, Label Suggestion
type ConversationInsightHandler struct {
svc *service.ConversationInsightService
}
// NewConversationInsightHandler creates a new ConversationInsightHandler.
func NewConversationInsightHandler(svc *service.ConversationInsightService) *ConversationInsightHandler {
return &ConversationInsightHandler{svc: svc}
}
// AnalyzeParticipants analyzes participants in a conversation.
// POST /api/v1/accounts/:account_id/captain/insights/participants
func (h *ConversationInsightHandler) AnalyzeParticipants(c *gin.Context) {
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
return
}
var req service.ParticipantAnalysisRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
return
}
result, err := h.svc.AnalyzeParticipants(c.Request.Context(), uint(accountID), &req)
if err != nil {
applogger.L().Errorf("ConversationInsightHandler.AnalyzeParticipants failed: %v", err)
response.AbortWithStatusError(c, http.StatusInternalServerError, "analysis_failed", "Failed to analyze participants")
return
}
response.OK(c, result)
}
// ExtractActionItems extracts action items from a conversation.
// POST /api/v1/accounts/:account_id/captain/insights/action_items
func (h *ConversationInsightHandler) ExtractActionItems(c *gin.Context) {
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
return
}
var req service.ActionItemsRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
return
}
result, err := h.svc.ExtractActionItems(c.Request.Context(), uint(accountID), &req)
if err != nil {
applogger.L().Errorf("ConversationInsightHandler.ExtractActionItems failed: %v", err)
response.AbortWithStatusError(c, http.StatusInternalServerError, "action_items_failed", "Failed to extract action items")
return
}
response.OK(c, result)
}
// SuggestLabels suggests labels and priority for a conversation.
// POST /api/v1/accounts/:account_id/captain/insights/label_suggestion
func (h *ConversationInsightHandler) SuggestLabels(c *gin.Context) {
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
return
}
var req service.LabelSuggestionRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
return
}
result, err := h.svc.SuggestLabels(c.Request.Context(), uint(accountID), &req)
if err != nil {
applogger.L().Errorf("ConversationInsightHandler.SuggestLabels failed: %v", err)
response.AbortWithStatusError(c, http.StatusInternalServerError, "label_suggestion_failed", "Failed to suggest labels")
return
}
response.OK(c, result)
}