Skip to content

Cross-API Data Fusion #9

@mheadd

Description

@mheadd

Summary

Combine Multiple Sources

// NEW: internal/mcp/handlers.go
type EnrichedParkInfo struct {
    Park      models.Park           `json:"park"`
    Alerts    []models.Alert        `json:"alerts,omitempty"`
    Weather   *models.Weather       `json:"current_weather,omitempty"`
    Nearby    []models.RecreationArea `json:"nearby_recreation,omitempty"`
}

func (s *Server) handleGetCompleteParkInfo(ctx context.Context, input GetParkDetailsInput) (*EnrichedParkInfo, error) {
    // Parallel fetching with errgroup
    var (
        park    *models.Park
        alerts  []models.Alert
        weather *models.Weather
    )
    
    g, gctx := errgroup.WithContext(ctx)
    
    g.Go(func() error {
        var err error
        park, err = s.npsClient.GetParkDetails(gctx, input.ParkCode)
        return err
    })
    
    g.Go(func() error {
        var err error
        alerts, err = s.npsClient.GetAlerts(gctx, input.ParkCode)
        return err
    })
    
    g.Go(func() error {
        if park != nil && park.Latitude != "" {
            lat, _ := strconv.ParseFloat(park.Latitude, 64)
            lon, _ := strconv.ParseFloat(park.Longitude, 64)
            var err error
            weather, err = s.weatherClient.GetCurrentWeather(gctx, lat, lon, "imperial")
            return err
        }
        return nil
    })
    
    if err := g.Wait(); err != nil {
        return nil, err
    }
    
    return &EnrichedParkInfo{
        Park:    *park,
        Alerts:  alerts,
        Weather: weather,
    }, nil
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions