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.
82 lines
2.8 KiB
Go
82 lines
2.8 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
)
|
|
|
|
// AgentBotInboxRepo implements GORM repository for AgentBotInbox.
|
|
// Reference: Chatwoot app/models/agent_bot_inbox.rb
|
|
type AgentBotInboxRepo struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewAgentBotInboxRepo creates a new AgentBotInbox repository.
|
|
func NewAgentBotInboxRepo(db *gorm.DB) *AgentBotInboxRepo {
|
|
return &AgentBotInboxRepo{db: db}
|
|
}
|
|
|
|
// FindByID retrieves an agent_bot_inbox by primary key.
|
|
func (r *AgentBotInboxRepo) FindByID(ctx context.Context, id uint) (*model.AgentBotInbox, error) {
|
|
var abi model.AgentBotInbox
|
|
err := r.db.WithContext(ctx).First(&abi, id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &abi, nil
|
|
}
|
|
|
|
// FindByAgentBotID retrieves all agent_bot_inboxes for a given agent_bot.
|
|
func (r *AgentBotInboxRepo) FindByAgentBotID(ctx context.Context, agentBotID uint) ([]model.AgentBotInbox, error) {
|
|
var abis []model.AgentBotInbox
|
|
err := r.db.WithContext(ctx).Where("agent_bot_id = ?", agentBotID).
|
|
Order("id ASC").Find(&abis).Error
|
|
return abis, err
|
|
}
|
|
|
|
// FindByInboxID retrieves all agent_bot_inboxes for a given inbox.
|
|
func (r *AgentBotInboxRepo) FindByInboxID(ctx context.Context, inboxID uint) ([]model.AgentBotInbox, error) {
|
|
var abis []model.AgentBotInbox
|
|
err := r.db.WithContext(ctx).Where("inbox_id = ?", inboxID).
|
|
Order("id ASC").Find(&abis).Error
|
|
return abis, err
|
|
}
|
|
|
|
// FindActiveByInboxID retrieves only active agent_bot_inboxes for a given inbox (status=0).
|
|
func (r *AgentBotInboxRepo) FindActiveByInboxID(ctx context.Context, inboxID uint) ([]model.AgentBotInbox, error) {
|
|
var abis []model.AgentBotInbox
|
|
err := r.db.WithContext(ctx).
|
|
Where("inbox_id = ? AND status = ?", inboxID, model.AgentBotInboxActive).
|
|
Order("id ASC").Find(&abis).Error
|
|
return abis, err
|
|
}
|
|
|
|
// FindByAgentBotAndInbox retrieves a single binding by agent_bot_id + inbox_id.
|
|
func (r *AgentBotInboxRepo) FindByAgentBotAndInbox(ctx context.Context, agentBotID, inboxID uint) (*model.AgentBotInbox, error) {
|
|
var abi model.AgentBotInbox
|
|
err := r.db.WithContext(ctx).
|
|
Where("agent_bot_id = ? AND inbox_id = ?", agentBotID, inboxID).
|
|
First(&abi).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &abi, nil
|
|
}
|
|
|
|
// Create persists a new AgentBotInbox record.
|
|
func (r *AgentBotInboxRepo) Create(ctx context.Context, abi *model.AgentBotInbox) error {
|
|
return r.db.WithContext(ctx).Create(abi).Error
|
|
}
|
|
|
|
// Update persists changes to an existing AgentBotInbox record.
|
|
func (r *AgentBotInboxRepo) Update(ctx context.Context, abi *model.AgentBotInbox) error {
|
|
return r.db.WithContext(ctx).Save(abi).Error
|
|
}
|
|
|
|
// Delete removes an AgentBotInbox record by primary key.
|
|
func (r *AgentBotInboxRepo) Delete(ctx context.Context, id uint) error {
|
|
return r.db.WithContext(ctx).Delete(&model.AgentBotInbox{}, id).Error
|
|
} |