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.
69 lines
2.5 KiB
Go
69 lines
2.5 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"
|
|
)
|
|
|
|
// ChannelTwilioService implements business logic for Twilio SMS channel operations.
|
|
// Reference: Twilio SMS API — https://www.twilio.com/docs/sms
|
|
//
|
|
// Twilio SMS channels use the Twilio API to send/receive SMS messages
|
|
// via a purchased Twilio phone number. The Account SID and Auth Token
|
|
// authenticate API calls, and the phone number serves as the sender identity.
|
|
type ChannelTwilioService struct {
|
|
repo *repository.ChannelTwilioRepo
|
|
}
|
|
|
|
// NewChannelTwilioService creates a new ChannelTwilio service.
|
|
func NewChannelTwilioService(repo *repository.ChannelTwilioRepo) *ChannelTwilioService {
|
|
return &ChannelTwilioService{repo: repo}
|
|
}
|
|
|
|
// Create creates a new Twilio SMS channel.
|
|
func (s *ChannelTwilioService) Create(ctx context.Context, channel *channelmodel.ChannelTwilioSMS) error {
|
|
if err := s.repo.Create(ctx, channel); err != nil {
|
|
applogger.L().Errorf("Failed to create Twilio channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Created Twilio channel with ID %d", channel.ID)
|
|
return nil
|
|
}
|
|
|
|
// GetByID retrieves a Twilio SMS channel by ID.
|
|
func (s *ChannelTwilioService) GetByID(ctx context.Context, id uint) (*channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
// GetByInboxID retrieves a Twilio SMS channel by inbox ID.
|
|
func (s *ChannelTwilioService) GetByInboxID(ctx context.Context, inboxID uint) (*channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.FindByInboxID(ctx, inboxID)
|
|
}
|
|
|
|
// Update updates a Twilio SMS channel.
|
|
func (s *ChannelTwilioService) Update(ctx context.Context, channel *channelmodel.ChannelTwilioSMS) error {
|
|
if err := s.repo.Update(ctx, channel); err != nil {
|
|
applogger.L().Errorf("Failed to update Twilio channel %d: %v", channel.ID, err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Updated Twilio channel with ID %d", channel.ID)
|
|
return nil
|
|
}
|
|
|
|
// Delete deletes a Twilio SMS channel by ID.
|
|
func (s *ChannelTwilioService) Delete(ctx context.Context, id uint) error {
|
|
if err := s.repo.Delete(ctx, id); err != nil {
|
|
applogger.L().Errorf("Failed to delete Twilio channel %d: %v", id, err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Deleted Twilio channel with ID %d", id)
|
|
return nil
|
|
}
|
|
|
|
// ListByAccount lists all Twilio SMS channels for an account.
|
|
func (s *ChannelTwilioService) ListByAccount(ctx context.Context, accountID uint) ([]channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.ListByAccount(ctx, accountID)
|
|
} |