repository와 subscribe까지 잘 됨
This commit is contained in:
7
internal/app/flow/errors.go
Normal file
7
internal/app/flow/errors.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package flow
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrWeatherAlreadyExists = errors.New("weather already exists")
|
||||
)
|
||||
47
internal/app/flow/flow.go
Normal file
47
internal/app/flow/flow.go
Normal 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
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package flow
|
||||
|
||||
type Service struct {}
|
||||
|
||||
func NewService() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
11
internal/app/flow/weather.go
Normal file
11
internal/app/flow/weather.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package flow
|
||||
|
||||
import "time"
|
||||
|
||||
type Weather struct {
|
||||
Source string
|
||||
TargetDate time.Time
|
||||
ForecastDate time.Time
|
||||
Condition string
|
||||
Temperature float64 // Celsius
|
||||
}
|
||||
Reference in New Issue
Block a user