|
|
|
|
@ -42,18 +42,19 @@ func (p Provider) Name() string {
|
|
|
|
|
|
|
|
|
|
func (p Provider) Get(ctx context.Context, location string) ([]prayer.Times, error) {
|
|
|
|
|
times, err := p.loadTimes(ctx, location)
|
|
|
|
|
if err == nil && len(times) != 0 {
|
|
|
|
|
return times, nil
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to load prayer times from db: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if len(times) > 0 {
|
|
|
|
|
return times, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
times, err = p.provider.Get(ctx, location)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to get prayer times: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(times) > 1 {
|
|
|
|
|
if len(times) > 0 {
|
|
|
|
|
if err := p.saveTimes(ctx, location, times); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to save times to db: %w", err)
|
|
|
|
|
}
|
|
|
|
|
@ -112,7 +113,7 @@ func Migrate(con *sql.DB) error {
|
|
|
|
|
type prayerTimesRow struct {
|
|
|
|
|
ProviderID int64 `db:"provider_id"`
|
|
|
|
|
LocationID string `db:"location_id"`
|
|
|
|
|
Date time.Time `db:"date"`
|
|
|
|
|
Date string `db:"date"`
|
|
|
|
|
Fajr string `db:"fajr"`
|
|
|
|
|
Sunrise string `db:"sunrise"`
|
|
|
|
|
Dhuhr string `db:"dhuhr"`
|
|
|
|
|
@ -166,7 +167,7 @@ func (p Provider) saveTimes(ctx context.Context, locationID string, times []pray
|
|
|
|
|
|
|
|
|
|
func (p Provider) loadTimes(ctx context.Context, locationID string) ([]prayer.Times, error) {
|
|
|
|
|
now := p.clockFunc()
|
|
|
|
|
today := now.Truncate(time.Hour * 24)
|
|
|
|
|
today := now.UTC().Truncate(time.Hour * 24)
|
|
|
|
|
|
|
|
|
|
q := p.db.
|
|
|
|
|
From(goqu.T("prayer_times").As("pt")).
|
|
|
|
|
|