feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection. Refs #19 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/tradarr/backend/internal/ai"
|
||||
"github.com/tradarr/backend/internal/companycatalog"
|
||||
"github.com/tradarr/backend/internal/generation"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
@ -18,10 +19,11 @@ import (
|
||||
|
||||
type Fixtures struct {
|
||||
SummaryModelID string `json:"summaryModelID"`
|
||||
IndexQuery string `json:"indexQuery"`
|
||||
IndexName string `json:"indexName"`
|
||||
IndexSymbol string `json:"indexSymbol"`
|
||||
IndexFIGI string `json:"indexFIGI"`
|
||||
CompanyQuery string `json:"companyQuery"`
|
||||
CompanyID string `json:"companyID"`
|
||||
CompanyName string `json:"companyName"`
|
||||
CompanySymbol string `json:"companySymbol"`
|
||||
CompanyFIGI string `json:"companyFIGI"`
|
||||
SummarySentinel string `json:"summarySentinel"`
|
||||
ArticleTitle string `json:"articleTitle"`
|
||||
ArticleURL string `json:"articleURL"`
|
||||
@ -30,15 +32,44 @@ type Fixtures struct {
|
||||
}
|
||||
|
||||
func DefaultFixtures() Fixtures {
|
||||
return Fixtures{"00000000-0000-0000-0000-000000001203", "E2E index", "E2E Financial Index", "E2EIDX", "BBG000E2E001", "E2E synthesized financial summary", "E2E private article title", "https://fixture.invalid/private-article", "E2E private article body", "pending-candidate-id"}
|
||||
return Fixtures{"00000000-0000-0000-0000-000000001203", "E2E Company", "isin:US0000000001", "E2E Company Inc.", "E2ECO", "BBG000E2E001", "E2E synthesized financial summary", "E2E private article title", "https://fixture.invalid/private-article", "E2E private article body", "pending-candidate-id"}
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
Model string `json:"model,omitempty"`
|
||||
Kind string `json:"kind"`
|
||||
Query string `json:"query,omitempty"`
|
||||
CompanyID string `json:"company_id,omitempty"`
|
||||
Symbols []string `json:"symbols,omitempty"`
|
||||
CandidateID string `json:"candidate_id,omitempty"`
|
||||
}
|
||||
|
||||
// FakeCompanyCatalog keeps the browser journey deterministic and entirely
|
||||
// local. It exercises the production catalog port without OpenFIGI traffic.
|
||||
type FakeCompanyCatalog struct{ Fakes *Fakes }
|
||||
|
||||
func (c FakeCompanyCatalog) SearchCompanies(query string, limit int) ([]companycatalog.Company, error) {
|
||||
company := c.Fakes.company()
|
||||
c.Fakes.record(Event{Kind: "companySearches", Query: query})
|
||||
if limit < 1 || !strings.Contains(strings.ToLower(company.Name), strings.ToLower(strings.TrimSpace(query))) {
|
||||
return []companycatalog.Company{}, nil
|
||||
}
|
||||
return []companycatalog.Company{company}, nil
|
||||
}
|
||||
|
||||
func (c FakeCompanyCatalog) ResolveCompany(companyID string) (companycatalog.Company, error) {
|
||||
company := c.Fakes.company()
|
||||
c.Fakes.record(Event{Kind: "companyResolutions", CompanyID: companyID})
|
||||
if companyID != company.CompanyID {
|
||||
return companycatalog.Company{}, companycatalog.ErrUnknownCompany
|
||||
}
|
||||
return company, nil
|
||||
}
|
||||
|
||||
func (f *Fakes) company() companycatalog.Company {
|
||||
return companycatalog.Company{CompanyID: f.Fixture.CompanyID, Name: f.Fixture.CompanyName, YahooSymbol: f.Fixture.CompanySymbol, FIGI: f.Fixture.CompanyFIGI, Exchange: "E2E Exchange", MIC: "XEEE", Country: "E2E Country"}
|
||||
}
|
||||
|
||||
type Fakes struct {
|
||||
mu sync.Mutex
|
||||
Fixture Fixtures
|
||||
@ -60,7 +91,7 @@ func (f *Fakes) Handler() http.Handler {
|
||||
mux.HandleFunc("/audit", func(w http.ResponseWriter, r *http.Request) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"openfigiSearches": f.counts["openfigiSearches"], "scraperCalls": f.counts["scraperCalls"], "layaRankingCalls": f.counts["layaRankingCalls"], "layaSummaryCalls": f.counts["layaSummaryCalls"], "events": f.Events})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"openfigiSearches": f.counts["openfigiSearches"], "companySearches": f.counts["companySearches"], "companyResolutions": f.counts["companyResolutions"], "scraperCalls": f.counts["scraperCalls"], "layaRankingCalls": f.counts["layaRankingCalls"], "layaSummaryCalls": f.counts["layaSummaryCalls"], "events": f.Events})
|
||||
})
|
||||
mux.HandleFunc("/v3/search", func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
@ -72,7 +103,7 @@ func (f *Fakes) Handler() http.Handler {
|
||||
return
|
||||
}
|
||||
f.record(Event{Kind: "openfigiSearches"})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"data": []map[string]string{{"name": f.Fixture.IndexName, "ticker": f.Fixture.IndexSymbol, "figi": f.Fixture.IndexFIGI, "marketSector": "Index"}}})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"data": []map[string]string{{"name": f.Fixture.CompanyName, "ticker": f.Fixture.CompanySymbol, "figi": f.Fixture.CompanyFIGI, "marketSector": "Index"}}})
|
||||
})
|
||||
mux.HandleFunc("/scrape", func(w http.ResponseWriter, r *http.Request) {
|
||||
var symbols []string
|
||||
|
||||
Reference in New Issue
Block a user