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.
78 lines
3.0 KiB
Go
78 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"
|
|
)
|
|
|
|
// ChannelTikTokService implements business logic for TikTok channel operations.
|
|
// Reference: TikTok Business API — https://business-api.tiktok.com/portal/docs
|
|
//
|
|
// TikTok Business channels use the TikTok Business Messaging API to send/receive
|
|
// messages via a connected TikTok Business account. The access token grants
|
|
// messaging permissions for TikTok Direct Message interactions.
|
|
type ChannelTikTokService struct {
|
|
repo *repository.ChannelTikTokRepo
|
|
}
|
|
|
|
// NewChannelTikTokService creates a new ChannelTikTok service.
|
|
func NewChannelTikTokService(repo *repository.ChannelTikTokRepo) *ChannelTikTokService {
|
|
return &ChannelTikTokService{repo: repo}
|
|
}
|
|
|
|
// GetByID retrieves a TikTok channel by ID.
|
|
func (s *ChannelTikTokService) GetByID(ctx context.Context, id uint) (*channelmodel.ChannelTikTok, error) {
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
// GetByInboxID retrieves a TikTok channel by inbox ID.
|
|
func (s *ChannelTikTokService) GetByInboxID(ctx context.Context, inboxID uint) (*channelmodel.ChannelTikTok, error) {
|
|
return s.repo.FindByInboxID(ctx, inboxID)
|
|
}
|
|
|
|
// GetByAccountAndInboxID retrieves a TikTok channel scoped to an account and inbox.
|
|
func (s *ChannelTikTokService) GetByAccountAndInboxID(ctx context.Context, accountID, inboxID uint) (*channelmodel.ChannelTikTok, error) {
|
|
return s.repo.FindByAccountAndInboxID(ctx, accountID, inboxID)
|
|
}
|
|
|
|
// FindByTikTokBusinessID retrieves a TikTok channel by TikTok Business ID.
|
|
func (s *ChannelTikTokService) FindByTikTokBusinessID(ctx context.Context, businessID string) (*channelmodel.ChannelTikTok, error) {
|
|
return s.repo.FindByTikTokBusinessID(ctx, businessID)
|
|
}
|
|
|
|
// Create inserts a new TikTok channel record.
|
|
func (s *ChannelTikTokService) Create(ctx context.Context, ch *channelmodel.ChannelTikTok) error {
|
|
if err := s.repo.Create(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to create TikTok channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("TikTok channel created: id=%d business_id=%s", ch.ID, ch.TikTokBusinessID)
|
|
return nil
|
|
}
|
|
|
|
// Update modifies an existing TikTok channel.
|
|
func (s *ChannelTikTokService) Update(ctx context.Context, ch *channelmodel.ChannelTikTok) error {
|
|
if err := s.repo.Update(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to update TikTok channel: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete soft-deletes a TikTok channel.
|
|
func (s *ChannelTikTokService) Delete(ctx context.Context, id uint) error {
|
|
if err := s.repo.Delete(ctx, id); err != nil {
|
|
applogger.L().Errorf("Failed to delete TikTok channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("TikTok channel deleted: id=%d", id)
|
|
return nil
|
|
}
|
|
|
|
// ListByAccount retrieves all TikTok channels for an account.
|
|
func (s *ChannelTikTokService) ListByAccount(ctx context.Context, accountID uint) ([]channelmodel.ChannelTikTok, error) {
|
|
return s.repo.ListByAccount(ctx, accountID)
|
|
} |