repository와 subscribe까지 잘 됨

This commit is contained in:
2025-12-08 21:57:18 +09:00
parent 619cdc7d6a
commit 94fae7c4fd
13 changed files with 336 additions and 11 deletions

47
internal/app/flow/flow.go Normal file
View File

@@ -0,0 +1,47 @@
package flow
import (
"context"
"errors"
"fmt"
"github.com/neatflowcv/seven-skies/internal/pkg/domain"
"github.com/neatflowcv/seven-skies/internal/pkg/repository"
"github.com/oklog/ulid/v2"
)
type Flow struct {
repo repository.Repository
}
func NewFlow(repo repository.Repository) *Flow {
return &Flow{
repo: repo,
}
}
func (f *Flow) CreateWeather(ctx context.Context, weather *Weather) error {
id := ulid.Make().String()
domainWeather := domain.NewWeather(
id,
domain.WeatherSource(weather.Source),
weather.TargetDate,
weather.ForecastDate,
domain.WeatherCondition(weather.Condition),
domain.Temperature{
Value: domain.Celsius(weather.Temperature),
},
)
err := f.repo.CreateWeather(ctx, domainWeather)
if err != nil {
if errors.Is(err, repository.ErrWeatherAlreadyExists) {
return ErrWeatherAlreadyExists
}
return fmt.Errorf("error in create weather: %w", err)
}
return nil
}