[row-handle]: Fix build and use composite implementation for WeatherProvider
authorEvgenii Akentev <i@ak3n.com>
Thu, 30 Mar 2023 19:02:46 +0000 (23:02 +0400)
committerEvgenii Akentev <i@ak3n.com>
Thu, 30 Mar 2023 19:02:46 +0000 (23:02 +0400)
row-handle/domain/WeatherProvider.hs
row-handle/impl/SuperWeatherProvider.hs

index a767a0c3a86cc663268d62cbccf5e548723b3d8f..2a18204a320b8acac1ddfa1b3c2b86205a91d139 100644 (file)
@@ -11,7 +11,7 @@ import qualified WindProvider
 import qualified TemperatureProvider
 import QueryTypes
 
-data WeatherData = WeatherData { temperature :: T.Temperature, wind :: W.WindSpeed }
+data WeatherData = WeatherData { temperature :: TemperatureProvider.Temperature, wind :: WindProvider.WindSpeed }
 
 -- We union the methods of providers and extend it with a common method.
 type Methods = ("getWeatherData" .== (Location -> Day -> IO WeatherData))
@@ -23,5 +23,5 @@ type Handle = HandleRow Methods
 getWeatherData :: Handle -> Location -> Day -> IO WeatherData
 getWeatherData = getMethod @"getWeatherData"
 
-getWindData :: Handle -> Location -> Day -> IO W.WindSpeed
+getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed
 getWindData = getMethod @"getWindData"
index 3a110f247ff552c9dbce5240ab6e06619d80f8b8..7b9c6500ea83f14e8654d354a202d26263823b86 100644 (file)
@@ -1,4 +1,6 @@
+{-# LANGUAGE RecordWildCards #-}
 {-# LANGUAGE OverloadedLabels #-}
+
 module SuperWeatherProvider where
 
 import Data.Row
@@ -8,8 +10,11 @@ import qualified WindProvider
 import QueryTypes
 
 new :: WindProvider.Handle -> TemperatureProvider.Handle -> Handle
-new wp tp = #getWeatherData .== getSuperWeatherData .+ wp .+ tp
+new wp tp = #getWeatherData .== (getSuperWeatherData wp tp) .+ wp .+ tp
 
 -- | This is some concrete implementation `WeatherProvider` interface
-getSuperWeatherData :: Location -> Day -> IO WeatherData
-getSuperWeatherData _ _ = return $ WeatherData 30 10
+getSuperWeatherData :: WindProvider.Handle -> TemperatureProvider.Handle -> Location -> Day -> IO WeatherData
+getSuperWeatherData wp tp loc day = do
+  temperature <- TemperatureProvider.getTemperatureData tp loc day
+  wind <- WindProvider.getWindData wp loc day
+  return $ WeatherData{..}