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.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
)
|
|
|
|
// WidgetThemeConfigRepo implements GORM repository for WidgetThemeConfig.
|
|
type WidgetThemeConfigRepo struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewWidgetThemeConfigRepo creates a new WidgetThemeConfig repository.
|
|
func NewWidgetThemeConfigRepo(db *gorm.DB) *WidgetThemeConfigRepo {
|
|
return &WidgetThemeConfigRepo{db: db}
|
|
}
|
|
|
|
// FindByInboxID retrieves the theme config for a specific inbox.
|
|
// Each inbox should have at most one theme config record.
|
|
func (r *WidgetThemeConfigRepo) FindByInboxID(ctx context.Context, inboxID uint) (*model.WidgetThemeConfig, error) {
|
|
var config model.WidgetThemeConfig
|
|
err := r.db.WithContext(ctx).Where("inbox_id = ?", inboxID).First(&config).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|
|
|
|
// FindByID retrieves a theme config by primary key.
|
|
func (r *WidgetThemeConfigRepo) FindByID(ctx context.Context, id uint) (*model.WidgetThemeConfig, error) {
|
|
var config model.WidgetThemeConfig
|
|
err := r.db.WithContext(ctx).First(&config, id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|
|
|
|
// Create inserts a new theme config.
|
|
func (r *WidgetThemeConfigRepo) Create(ctx context.Context, config *model.WidgetThemeConfig) error {
|
|
return r.db.WithContext(ctx).Create(config).Error
|
|
}
|
|
|
|
// Update modifies an existing theme config.
|
|
func (r *WidgetThemeConfigRepo) Update(ctx context.Context, config *model.WidgetThemeConfig) error {
|
|
return r.db.WithContext(ctx).Save(config).Error
|
|
}
|
|
|
|
// Delete soft-deletes a theme config.
|
|
func (r *WidgetThemeConfigRepo) Delete(ctx context.Context, id uint) error {
|
|
return r.db.WithContext(ctx).Delete(&model.WidgetThemeConfig{}, id).Error
|
|
}
|
|
|
|
// DeleteByInboxID soft-deletes the theme config for a specific inbox.
|
|
func (r *WidgetThemeConfigRepo) DeleteByInboxID(ctx context.Context, inboxID uint) error {
|
|
return r.db.WithContext(ctx).Where("inbox_id = ?", inboxID).Delete(&model.WidgetThemeConfig{}).Error
|
|
} |