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.
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// NotificationSubscriptionType represents the subscription type enum.
|
|
// Reference: Chatwoot SUBSCRIPTION_TYPES = { browser_push: 1, fcm: 2 }
|
|
type NotificationSubscriptionType int
|
|
|
|
const (
|
|
NotificationSubBrowserPush NotificationSubscriptionType = 1
|
|
NotificationSubFCM NotificationSubscriptionType = 2
|
|
)
|
|
|
|
// NotificationSubscription represents a user's push notification subscription.
|
|
// Reference: Chatwoot app/models/notification_subscription.rb
|
|
// Table: notification_subscriptions
|
|
// Columns: id, identifier(text), subscription_attributes(jsonb), subscription_type(int), user_id(bigint), created_at, updated_at
|
|
type NotificationSubscription struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
Identifier string `gorm:"type:text;uniqueIndex:idx_notification_subscriptions_on_identifier;not null" json:"identifier"`
|
|
SubscriptionAttributes json.RawMessage `gorm:"type:jsonb;not null" json:"subscription_attributes"`
|
|
SubscriptionType NotificationSubscriptionType `gorm:"not null" json:"subscription_type"`
|
|
UserID uint `gorm:"not null;index:idx_notification_subscriptions_on_user_id" json:"user_id"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
|
}
|
|
|
|
func (NotificationSubscription) TableName() string { return "notification_subscriptions" }
|
|
|
|
// String returns the string representation of the subscription type.
|
|
func (t NotificationSubscriptionType) String() string {
|
|
switch t {
|
|
case NotificationSubBrowserPush:
|
|
return "browser_push"
|
|
case NotificationSubFCM:
|
|
return "fcm"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// NotificationSubscriptionTypeFromString parses a subscription type from string.
|
|
func NotificationSubscriptionTypeFromString(s string) NotificationSubscriptionType {
|
|
switch s {
|
|
case "browser_push":
|
|
return NotificationSubBrowserPush
|
|
case "fcm":
|
|
return NotificationSubFCM
|
|
default:
|
|
return 0
|
|
}
|
|
} |