Files
gochat/backend/internal/model/conversation.go.txt
T
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

46 lines
2.8 KiB
Plaintext

package model
import (
"encoding/json"
"time"
"gorm.io/gorm"
)
// Conversation represents a conversation between a contact and agents.
// Reference: Chatwoot Conversation model + P2B M3 spec
type Conversation struct {
ID uint `gorm:"primaryKey" json:"id"`
AccountID uint `gorm:"not null;index" json:"account_id"`
InboxID uint `gorm:"not null;index" json:"inbox_id"`
ContactID uint `gorm:"not null;index" json:"contact_id"`
AssigneeID *uint `gorm:"index" json:"assignee_id,omitempty"`
TeamID *uint `gorm:"index" json:"team_id,omitempty"`
Status string `gorm:"size:50;not null;index;default:'open'" json:"status"` // open/resolved/pending/snoozed
Priority string `gorm:"size:50" json:"priority"` // urgent/high/medium/low
LastNonActivityMessageID uint `json:"last_non_activity_message_id"`
Labels []string `gorm:"type:text[];index" json:"labels"`
CustomAttributes json.RawMessage `gorm:"type:jsonb" json:"custom_attributes"`
AdditionalAttributes json.RawMessage `gorm:"type:jsonb" json:"additional_attributes"`
Channel string `gorm:"size:100" json:"channel"`
ContactInboxID uint `gorm:"index" json:"contact_inbox_id"`
UnreadCount int `gorm:"default:0" json:"unread_count"`
FirstReplyCreatedAt *time.Time `json:"first_reply_created_at,omitempty"`
LastActivityAt *time.Time `json:"last_activity_at,omitempty"`
SnoozedUntil *time.Time `json:"snoozed_until,omitempty"`
Uuid string `gorm:"size:255;uniqueIndex" json:"uuid"`
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
Contact Contact `gorm:"foreignKey:ContactID" json:"contact,omitempty"`
Assignee *User `gorm:"foreignKey:AssigneeID" json:"assignee,omitempty"`
Team *Team `gorm:"foreignKey:TeamID" json:"team,omitempty"`
Messages []Message `gorm:"foreignKey:ConversationID" json:"messages,omitempty"`
Tags []Tag `gorm:"many2many:conversation_tags" json:"tags,omitempty"`
AppliedSLAs []AppliedSLA `gorm:"foreignKey:ConversationID" json:"applied_slas,omitempty"`
}
func (Conversation) TableName() string { return "conversations" }