New route to perform a new analysis of the email
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0ac51ac06d
commit
dfc0eeb323
6 changed files with 183 additions and 4 deletions
|
|
@ -23,6 +23,7 @@ package analyzer
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -85,3 +86,32 @@ func (a *EmailAnalyzer) GetScoreSummaryText(result *AnalysisResult) string {
|
|||
}
|
||||
return a.generator.GetScoreSummaryText(result.Results)
|
||||
}
|
||||
|
||||
// APIAdapter adapts the EmailAnalyzer to work with the API package
|
||||
// This adapter implements the interface expected by the API handler
|
||||
type APIAdapter struct {
|
||||
analyzer *EmailAnalyzer
|
||||
}
|
||||
|
||||
// NewAPIAdapter creates a new API adapter for the email analyzer
|
||||
func NewAPIAdapter(cfg *config.Config) *APIAdapter {
|
||||
return &APIAdapter{
|
||||
analyzer: NewEmailAnalyzer(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
// AnalyzeEmailBytes performs analysis and returns JSON bytes directly
|
||||
func (a *APIAdapter) AnalyzeEmailBytes(rawEmail []byte, testID uuid.UUID) ([]byte, error) {
|
||||
result, err := a.analyzer.AnalyzeEmailBytes(rawEmail, testID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Marshal report to JSON
|
||||
reportJSON, err := json.Marshal(result.Report)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal report: %w", err)
|
||||
}
|
||||
|
||||
return reportJSON, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue