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.
79 lines
3.0 KiB
Go
79 lines
3.0 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"
|
|
)
|
|
|
|
// ChannelTwilioSMSService implements business logic for Twilio SMS channel operations.
|
|
// Reference: Twilio SMS API — https://www.twilio.com/docs/sms
|
|
//
|
|
// Twilio SMS channels use the Twilio Programmable Messaging API to send/receive
|
|
// SMS messages via a Twilio phone number. The Account SID + Auth Token grant
|
|
// messaging permissions for Twilio interactions.
|
|
type ChannelTwilioSMSService struct {
|
|
repo *repository.ChannelTwilioSMSRepo
|
|
}
|
|
|
|
// NewChannelTwilioSMSService creates a new ChannelTwilioSMS service.
|
|
func NewChannelTwilioSMSService(repo *repository.ChannelTwilioSMSRepo) *ChannelTwilioSMSService {
|
|
return &ChannelTwilioSMSService{repo: repo}
|
|
}
|
|
|
|
// GetByID retrieves a Twilio SMS channel by ID.
|
|
func (s *ChannelTwilioSMSService) GetByID(ctx context.Context, id uint) (*channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
// GetByAccountSID retrieves a Twilio SMS channel by Twilio Account SID.
|
|
func (s *ChannelTwilioSMSService) GetByAccountSID(ctx context.Context, accountSID string) (*channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.FindByAccountSID(ctx, accountSID)
|
|
}
|
|
|
|
// GetByPhoneNumber retrieves a Twilio SMS channel by phone number.
|
|
func (s *ChannelTwilioSMSService) GetByPhoneNumber(ctx context.Context, phoneNumber string) (*channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.FindByPhoneNumber(ctx, phoneNumber)
|
|
}
|
|
|
|
// Create inserts a new Twilio SMS channel record.
|
|
func (s *ChannelTwilioSMSService) Create(ctx context.Context, ch *channelmodel.ChannelTwilioSMS) error {
|
|
if err := s.repo.Create(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to create Twilio SMS channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Twilio SMS channel created: id=%d phone=%s", ch.ID, ch.PhoneNumber)
|
|
return nil
|
|
}
|
|
|
|
// Update modifies an existing Twilio SMS channel.
|
|
func (s *ChannelTwilioSMSService) Update(ctx context.Context, ch *channelmodel.ChannelTwilioSMS) error {
|
|
if err := s.repo.Update(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to update Twilio SMS channel: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete soft-deletes a Twilio SMS channel.
|
|
func (s *ChannelTwilioSMSService) Delete(ctx context.Context, id uint) error {
|
|
if err := s.repo.Delete(ctx, id); err != nil {
|
|
applogger.L().Errorf("Failed to delete Twilio SMS channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("Twilio SMS channel deleted: id=%d", id)
|
|
return nil
|
|
}
|
|
|
|
// List retrieves all Twilio SMS channels.
|
|
func (s *ChannelTwilioSMSService) List(ctx context.Context) ([]channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.List(ctx)
|
|
}
|
|
|
|
// ListByAccount retrieves all Twilio SMS channels for a given account.
|
|
func (s *ChannelTwilioSMSService) ListByAccount(ctx context.Context, accountID uint) ([]channelmodel.ChannelTwilioSMS, error) {
|
|
return s.repo.ListByAccount(ctx, accountID)
|
|
}
|