list daily weathers 구현
This commit is contained in:
@@ -3,6 +3,7 @@ package gorm
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/neatflowcv/seven-skies/internal/pkg/domain"
|
||||
"github.com/neatflowcv/seven-skies/internal/pkg/repository"
|
||||
@@ -42,3 +43,17 @@ func (r *Repository) CreateWeather(ctx context.Context, weather *domain.Weather)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) ListWeathers(ctx context.Context, from, to time.Time) ([]*domain.Weather, error) {
|
||||
weathers, err := gorm.G[*Weather](r.db).Where("target_date BETWEEN ? AND ?", from, to).Find(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list weathers: %w", err)
|
||||
}
|
||||
|
||||
var ret []*domain.Weather
|
||||
for _, weather := range weathers {
|
||||
ret = append(ret, weather.toDomain())
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -25,3 +25,14 @@ func newModelWeather(weather *domain.Weather) *Weather {
|
||||
Temperature: float64(weather.Temperature().Value),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Weather) toDomain() *domain.Weather {
|
||||
return domain.NewWeather(
|
||||
w.ID,
|
||||
domain.WeatherSource(w.Source),
|
||||
w.TargetDate,
|
||||
w.ForecastDate,
|
||||
domain.WeatherCondition(w.Condition),
|
||||
domain.Temperature{Value: domain.Celsius(w.Temperature)},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/neatflowcv/seven-skies/internal/pkg/domain"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
CreateWeather(ctx context.Context, weather *domain.Weather) error
|
||||
ListWeathers(ctx context.Context, from, to time.Time) ([]*domain.Weather, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user