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.
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
channelmodel "github.com/gochat/gochat/internal/model/channel"
|
|
"github.com/gochat/gochat/internal/repository"
|
|
applogger "github.com/gochat/gochat/pkg/logger"
|
|
)
|
|
|
|
// ChannelEmailService implements business logic for Email channel operations.
|
|
// Reference: Chatwoot app/controllers/api/v1/accounts/channels/email_controller.rb
|
|
//
|
|
// Email channels use IMAP for inbound message polling and SMTP for outbound
|
|
// message delivery. Channel configuration includes IMAP/SMTP server settings,
|
|
// credentials, and SSL mode preferences.
|
|
type ChannelEmailService struct {
|
|
repo *repository.ChannelEmailRepo
|
|
}
|
|
|
|
// NewChannelEmailService creates a new ChannelEmail service.
|
|
func NewChannelEmailService(repo *repository.ChannelEmailRepo) *ChannelEmailService {
|
|
return &ChannelEmailService{repo: repo}
|
|
}
|
|
|
|
// GetByID retrieves an Email channel by ID.
|
|
func (s *ChannelEmailService) GetByID(ctx context.Context, id uint) (*channelmodel.ChannelEmail, error) {
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
// GetByInboxID retrieves an Email channel by inbox ID.
|
|
func (s *ChannelEmailService) GetByInboxID(ctx context.Context, inboxID uint) (*channelmodel.ChannelEmail, error) {
|
|
return s.repo.FindByInboxID(ctx, inboxID)
|
|
}
|
|
|
|
// GetByEmail retrieves an Email channel by email address.
|
|
func (s *ChannelEmailService) GetByEmail(ctx context.Context, email string) (*channelmodel.ChannelEmail, error) {
|
|
return s.repo.FindByEmail(ctx, email)
|
|
}
|
|
|
|
// Create inserts a new Email channel record.
|
|
func (s *ChannelEmailService) Create(ctx context.Context, ch *channelmodel.ChannelEmail) error {
|
|
if err := s.repo.Create(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to create Email channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Email channel created: id=%d email=%s", ch.ID, ch.Email)
|
|
return nil
|
|
}
|
|
|
|
// Update modifies an existing Email channel.
|
|
func (s *ChannelEmailService) Update(ctx context.Context, ch *channelmodel.ChannelEmail) error {
|
|
if err := s.repo.Update(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to update Email channel: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete soft-deletes an Email channel.
|
|
func (s *ChannelEmailService) Delete(ctx context.Context, id uint) error {
|
|
if err := s.repo.Delete(ctx, id); err != nil {
|
|
applogger.L().Errorf("Failed to delete Email channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Email channel deleted: id=%d", id)
|
|
return nil
|
|
}
|
|
|
|
// ListByAccount retrieves all Email channels for an account.
|
|
func (s *ChannelEmailService) ListByAccount(ctx context.Context, accountID uint) ([]channelmodel.ChannelEmail, error) {
|
|
return s.repo.ListByAccount(ctx, accountID)
|
|
}
|