feat: Implement user preferences (saved cities, search history) with Redis storage and API handlers

This commit is contained in:
2026-08-17 14:30:54 +03:00
parent 2907ed3e0d
commit 5842667fff
8 changed files with 1073 additions and 81 deletions

View File

@@ -1,62 +0,0 @@
package main
import (
"context"
"log"
"time"
"trip-planner/internal/cache"
"trip-planner/internal/yandex"
)
// stationStatusKey returns the Redis key for station status.
func stationStatusKey(id string) *cache.CacheKey {
return &cache.CacheKey{
Kind: "station",
Code: id,
}
}
func main() {
ctx := context.Background()
// Initialize Redis cache
redisClient := cache.NewRedisCache(&cache.RedisConfig{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
// Initialize Yandex client
yandexClient := yandex.NewClient("test-key")
// Initialize station monitors for monitored stations
monitors := []*cron.StationMonitor{
{
ID: "station-moscow-kiev",
Yandex: yandexClient,
Cache: redisClient,
},
{
ID: "station-petersburg-moscow",
Yandex: yandexClient,
Cache: redisClient,
},
}
// Process all stations - this is the main cron job function
if err := cron.ProcessAllStations(ctx, monitors); err != nil {
log.Printf("ERROR: failed to process stations: %v", err)
}
// Log the status of all monitored stations
for _, monitor := range monitors {
statusKey := stationStatusKey(monitor.ID)
statusData, err := monitor.Cache.Get(ctx, statusKey)
if err == nil && statusData != nil {
log.Printf("INFO: station %s status: %s", monitor.ID, string(statusData))
}
}
log.Println("Cron job completed")
}