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.
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gochat/gochat/internal/service"
|
|
)
|
|
|
|
// ContactInboxHandler handles contact_inbox-specific API endpoints
|
|
// that are not nested under a single contact (e.g., filter by account).
|
|
// Reference: Chatwoot app/controllers/api/v1/contact_inboxes_controller.rb
|
|
type ContactInboxHandler struct {
|
|
svc *service.ContactInboxService
|
|
}
|
|
|
|
// NewContactInboxHandler creates a new ContactInboxHandler.
|
|
func NewContactInboxHandler(svc *service.ContactInboxService) *ContactInboxHandler {
|
|
return &ContactInboxHandler{svc: svc}
|
|
}
|
|
|
|
// Filter retrieves contact_inboxes by account with optional filters.
|
|
// GET /api/v1/accounts/:id/contact_inboxes/filter?inbox_id=...&contact_id=...&source_id=...&page=1&page_size=25
|
|
// Reference: Chatwoot contact_inboxes_controller#filter
|
|
func (h *ContactInboxHandler) Filter(c *gin.Context) {
|
|
accountID, err := parseUintParam(c, "id")
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
|
return
|
|
}
|
|
|
|
page := getPage(c)
|
|
perPage := getPageSize(c)
|
|
offset := (page - 1) * perPage
|
|
|
|
// Optional filter params
|
|
var inboxID, contactID *uint
|
|
if v := c.Query("inbox_id"); v != "" {
|
|
id, e := strconv.ParseUint(v, 10, 64)
|
|
if e == nil {
|
|
uid := uint(id)
|
|
inboxID = &uid
|
|
}
|
|
}
|
|
if v := c.Query("contact_id"); v != "" {
|
|
id, e := strconv.ParseUint(v, 10, 64)
|
|
if e == nil {
|
|
uid := uint(id)
|
|
contactID = &uid
|
|
}
|
|
}
|
|
sourceID := c.Query("source_id")
|
|
|
|
contactInboxes, total, svcErr := h.svc.FilterContactInboxes(
|
|
c.Request.Context(), accountID, inboxID, contactID, sourceID, offset, perPage,
|
|
)
|
|
if svcErr != nil {
|
|
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to filter contact inboxes"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"contact_inboxes": contactInboxes,
|
|
"meta": gin.H{"count": total, "page": page, "page_size": perPage},
|
|
})
|
|
} |