Files
gochat/internal/service/widget_test_service.go
T
2026-06-04 15:44:48 +08:00

45 lines
1.3 KiB
Go

package service
import (
"context"
"errors"
"github.com/gochat/gochat/internal/model"
"github.com/gochat/gochat/internal/repository"
applogger "github.com/gochat/gochat/pkg/logger"
)
// WidgetTestService implements business logic for WidgetTest operations.
// Reference: Chatwoot resources :widget_tests, only: [:index] — read-only, not in production.
// Returns test data for widget/UI integration testing.
type WidgetTestService struct {
repo *repository.WidgetTestRepo
}
// NewWidgetTestService creates a new WidgetTestService.
func NewWidgetTestService(repo *repository.WidgetTestRepo) *WidgetTestService {
return &WidgetTestService{repo: repo}
}
// List retrieves all widget test scenarios.
func (s *WidgetTestService) List(ctx context.Context) ([]model.WidgetTest, error) {
tests, err := s.repo.ListAll(ctx)
if err != nil {
applogger.L().Errorf("WidgetTestService.List error: %v", err)
return nil, err
}
return tests, nil
}
// ListByType retrieves widget test scenarios filtered by type.
func (s *WidgetTestService) ListByType(ctx context.Context, typ string) ([]model.WidgetTest, error) {
if typ == "" {
return nil, errors.New("type is required")
}
tests, err := s.repo.ListByType(ctx, typ)
if err != nil {
applogger.L().Errorf("WidgetTestService.ListByType error: %v", err)
return nil, err
}
return tests, nil
}