diff --git a/cmd/server/main.go b/cmd/server/main.go index 14c7cba6..461edfce 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -185,8 +185,12 @@ func main() { addSearchRoutes(logger, router, searcher) addValuesRoutes(logger, router, searcher) + var genericEntities []pubsearch.Entity[pubsearch.Value] + genericSDNs := generalizeOFACSDNs(searcher.SDNs, searcher.Addresses) - v2SearchService := searchv2.NewService[ofac.SDN](logger, genericSDNs) + genericEntities = append(genericEntities, genericSDNs...) + + v2SearchService := searchv2.NewService(logger, genericEntities) addSearchV2Routes(logger, router, v2SearchService) // Setup our web UI to be served as well @@ -271,8 +275,8 @@ func handleDownloadStats(updates chan *DownloadStats, handle func(stats *Downloa } } -func generalizeOFACSDNs(input []*SDN, ofacAddresses []*Address) []pubsearch.Entity[ofac.SDN] { - var out []pubsearch.Entity[ofac.SDN] +func generalizeOFACSDNs(input []*SDN, ofacAddresses []*Address) []pubsearch.Entity[pubsearch.Value] { + var out []pubsearch.Entity[pubsearch.Value] for _, sdn := range input { if sdn.SDN == nil { continue diff --git a/internal/search/service.go b/internal/search/service.go index b62cc3a0..6eb053a2 100644 --- a/internal/search/service.go +++ b/internal/search/service.go @@ -10,30 +10,30 @@ import ( ) type Service interface { - Search(ctx context.Context) + Search(ctx context.Context, query search.Entity[search.Value]) ([]SearchedEntity[search.Value], error) } -func NewService[T any](logger log.Logger, entities []search.Entity[T]) Service { +func NewService(logger log.Logger, entities []search.Entity[search.Value]) Service { - fmt.Printf("v2search NewService(%d entities)\n", len(entities)) //nolint:forbidigo + fmt.Printf("v2search NewService(%d entity types)\n", len(entities)) //nolint:forbidigo - return &service[T]{ + return &service{ logger: logger, entities: entities, } } -type service[T any] struct { +type service struct { logger log.Logger - entities []search.Entity[T] + entities []search.Entity[search.Value] } -func (s *service[T]) Search(ctx context.Context) { +func (s *service) Search(ctx context.Context, query search.Entity[search.Value]) ([]SearchedEntity[search.Value], error) { for _, entity := range s.entities { if len(entity.Addresses) > 0 { bs, _ := json.Marshal(entity) fmt.Printf("\n\n %s \n", string(bs)) //nolint:forbidigo - return + return nil, nil } } @@ -41,4 +41,8 @@ func (s *service[T]) Search(ctx context.Context) { // type SearchedEntity[T any] struct { // search.Entity[T] // Match float64 `json:"match"` + + var out []SearchedEntity[search.Value] + + return out, nil } diff --git a/pkg/ofac/mapper.go b/pkg/ofac/mapper.go index 0e7d7815..4a598c81 100644 --- a/pkg/ofac/mapper.go +++ b/pkg/ofac/mapper.go @@ -111,8 +111,8 @@ func extractCountry(remark string) string { return "" } -func ToEntity(sdn SDN, addresses []Address, comments []SDNComments) search.Entity[SDN] { - out := search.Entity[SDN]{ +func ToEntity(sdn SDN, addresses []Address, comments []SDNComments) search.Entity[search.Value] { + out := search.Entity[search.Value]{ Name: sdn.SDNName, Source: search.SourceUSOFAC, SourceData: sdn, diff --git a/pkg/ofac/mapper_person_test.go b/pkg/ofac/mapper_person_test.go index 53cb80a6..d74e05a9 100644 --- a/pkg/ofac/mapper_person_test.go +++ b/pkg/ofac/mapper_person_test.go @@ -44,7 +44,9 @@ func TestMapper__Person(t *testing.T) { require.Nil(t, e.Aircraft) require.Nil(t, e.Vessel) - require.Equal(t, "15102", e.SourceData.EntityID) + sourceData, ok := e.SourceData.(SDN) + require.True(t, ok) + require.Equal(t, "15102", sourceData.EntityID) } func TestMapper__CompletePerson(t *testing.T) { diff --git a/pkg/ofac/mapper_vehicles_test.go b/pkg/ofac/mapper_vehicles_test.go index 07cde3ca..5fdf389d 100644 --- a/pkg/ofac/mapper_vehicles_test.go +++ b/pkg/ofac/mapper_vehicles_test.go @@ -38,7 +38,9 @@ func TestMapper__Vessel(t *testing.T) { require.Equal(t, "9187629", e.Vessel.IMONumber) require.Equal(t, "572469210", e.Vessel.MMSI) - require.Equal(t, "15036", e.SourceData.EntityID) + sourceData, ok := e.SourceData.(SDN) + require.True(t, ok) + require.Equal(t, "15036", sourceData.EntityID) } func TestMapper__Aircraft(t *testing.T) { @@ -69,7 +71,9 @@ func TestMapper__Aircraft(t *testing.T) { require.Equal(t, "Airbus A321-131", e.Aircraft.Model) require.Equal(t, "550", e.Aircraft.SerialNumber) - require.Equal(t, "18158", e.SourceData.EntityID) + sourceData, ok := e.SourceData.(SDN) + require.True(t, ok) + require.Equal(t, "18158", sourceData.EntityID) } func TestMapper__CompleteVessel(t *testing.T) { diff --git a/pkg/search/models.go b/pkg/search/models.go index 01783eec..a03b5896 100644 --- a/pkg/search/models.go +++ b/pkg/search/models.go @@ -4,7 +4,9 @@ import ( "time" ) -type Entity[T any] struct { +type Value interface{} + +type Entity[T Value] struct { Name string `json:"name"` Type EntityType `json:"entityType"` Source SourceList `json:"sourceList"`