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.
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gochat/gochat/internal/service"
|
|
"github.com/gochat/gochat/pkg/response"
|
|
)
|
|
|
|
// InboxLimitHandler handles inbox limit CRUD endpoints.
|
|
// Reference: Chatwoot app/controllers/api/v1/accounts/inboxes/inbox_limits_controller.rb
|
|
// Inbox limits only have create, update, and destroy actions (no index or show).
|
|
type InboxLimitHandler struct {
|
|
svc *service.InboxLimitService
|
|
}
|
|
|
|
// NewInboxLimitHandler creates a new InboxLimitHandler.
|
|
func NewInboxLimitHandler(svc *service.InboxLimitService) *InboxLimitHandler {
|
|
return &InboxLimitHandler{svc: svc}
|
|
}
|
|
|
|
// Create creates a new inbox limit.
|
|
// POST /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits
|
|
// Body: { "type": "conversation_count", "value": 100 }
|
|
func (h *InboxLimitHandler) Create(c *gin.Context) {
|
|
inboxID, err := parseUintParam(c, "inbox_id")
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid inbox_id")
|
|
return
|
|
}
|
|
|
|
var req service.CreateInboxLimitRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body")
|
|
return
|
|
}
|
|
|
|
limit, svcErr := h.svc.Create(c.Request.Context(), inboxID, req)
|
|
if svcErr != nil {
|
|
handleServiceError(c, svcErr)
|
|
return
|
|
}
|
|
|
|
response.OK(c, limit)
|
|
}
|
|
|
|
// Update modifies an existing inbox limit.
|
|
// PATCH /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits/:id
|
|
// Body: { "type": "conversation_count", "value": 200 }
|
|
func (h *InboxLimitHandler) Update(c *gin.Context) {
|
|
id, err := parseUintParam(c, "id")
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
|
|
return
|
|
}
|
|
|
|
var req service.UpdateInboxLimitRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body")
|
|
return
|
|
}
|
|
|
|
limit, svcErr := h.svc.Update(c.Request.Context(), id, req)
|
|
if svcErr != nil {
|
|
handleServiceError(c, svcErr)
|
|
return
|
|
}
|
|
|
|
response.OK(c, limit)
|
|
}
|
|
|
|
// Delete removes an inbox limit.
|
|
// DELETE /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits/:id
|
|
func (h *InboxLimitHandler) Delete(c *gin.Context) {
|
|
id, err := parseUintParam(c, "id")
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
|
|
return
|
|
}
|
|
|
|
if svcErr := h.svc.Delete(c.Request.Context(), id); svcErr != nil {
|
|
handleServiceError(c, svcErr)
|
|
return
|
|
}
|
|
|
|
response.OK(c, gin.H{})
|
|
} |