{-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-}
module Lib
( someFunc
) where
import Data.Aeson
import GHC.Generics
import Control.Monad
import Data.Text
import qualified Data.HashMap.Strict as HM
import qualified Data.ByteString.Lazy as B
someFunc :: IO ()
someFunc = putStrLn "someFunc"
data NutrientPlanReference = NutrientPlanReference
{ orders :: [OrderReference]
, recipes :: [RecipeReference]
, ingredients :: [IngredientReference]
, foodItems :: [FoodItem]
} deriving (Show, Generic, FromJSON, ToJSON)
data NutrientPlan = NutrientPlan
{ orders :: [Order]
, recipes :: [Recipe]
, ingredients :: [Ingredient]
, foodItems :: [FoodItem]
} deriving (Show, Generic, FromJSON, ToJSON)
data OrderReference = OrderReference
{ name :: String
, recipes :: [String]
} deriving (Show, Generic, FromJSON, ToJSON)
data Order = Order
{ name :: String
, recipes :: [Recipe]
} deriving (Show, Generic, FromJSON, ToJSON)
data RecipeReference = RecipeReference
{ name :: String
, ingredients :: [String]
} deriving (Show, Generic, FromJSON, ToJSON)
data Recipe = Recipe
{ name :: String
, ingredients :: [Ingredient]
} deriving (Show, Generic, FromJSON, ToJSON)
data IngredientReference = IngredientReference
{ name :: String
, amount :: Float
} deriving (Show, Generic, FromJSON, ToJSON)
data Ingredient = Ingredient
{ name :: String
, amount :: Float
, foodItem :: FoodItem
} deriving (Show, Generic, FromJSON, ToJSON)
getIngredients :: [IngredientReference] -> [FoodItem] -> [Order]
-- getIngredients is =
data FoodItem = FoodItem
{ name :: String
, desc :: String
, amount :: Float
, price :: Float
, energy :: Float
, fat :: Float
, sfat :: Float
, carbs :: Float
, sugars :: Float
, protein :: Float
} deriving (Show, Generic, FromJSON, ToJSON)
decodedJSON = do
planText <- B.readFile "test-plan.json"
let req = decode planText :: Maybe NutrientPlanReference
print req
buildPlan :: NutrientPlanReference -> NutrientPlan
buildPlan plan = NutrientPlan
{ orders = []
, recipes = []
, ingredients = []
, foodItems = []
}
-- prints out the type brought in by the readFile function
debugPrint :: String -> IO ()
debugPrint str = putStrLn str
main = do
planText <- readFile "test-plan.json"
debugPrint planText
module Lib
( someFunc
) where
import Data.Aeson
import GHC.Generics
import Control.Monad
import Data.Text
import qualified Data.HashMap.Strict as HM
import qualified Data.ByteString.Lazy as B
someFunc :: IO ()
someFunc = putStrLn "someFunc"
data NutrientPlanReference = NutrientPlanReference
{ orders :: [OrderReference]
, recipes :: [RecipeReference]
, ingredients :: [IngredientReference]
, foodItems :: [FoodItem]
} deriving (Show, Generic, FromJSON, ToJSON)
data NutrientPlan = NutrientPlan
{ orders :: [Order]
, recipes :: [Recipe]
, ingredients :: [Ingredient]
, foodItems :: [FoodItem]
} deriving (Show, Generic, FromJSON, ToJSON)
data OrderReference = OrderReference
{ name :: String
, recipes :: [String]
} deriving (Show, Generic, FromJSON, ToJSON)
data Order = Order
{ name :: String
, recipes :: [Recipe]
} deriving (Show, Generic, FromJSON, ToJSON)
data RecipeReference = RecipeReference
{ name :: String
, ingredients :: [String]
} deriving (Show, Generic, FromJSON, ToJSON)
data Recipe = Recipe
{ name :: String
, ingredients :: [Ingredient]
} deriving (Show, Generic, FromJSON, ToJSON)
data IngredientReference = IngredientReference
{ name :: String
, amount :: Float
} deriving (Show, Generic, FromJSON, ToJSON)
data Ingredient = Ingredient
{ name :: String
, amount :: Float
, foodItem :: FoodItem
} deriving (Show, Generic, FromJSON, ToJSON)
getIngredients :: [IngredientReference] -> [FoodItem] -> [Order]
-- getIngredients is =
data FoodItem = FoodItem
{ name :: String
, desc :: String
, amount :: Float
, price :: Float
, energy :: Float
, fat :: Float
, sfat :: Float
, carbs :: Float
, sugars :: Float
, protein :: Float
} deriving (Show, Generic, FromJSON, ToJSON)
decodedJSON = do
planText <- B.readFile "test-plan.json"
let req = decode planText :: Maybe NutrientPlanReference
print req
buildPlan :: NutrientPlanReference -> NutrientPlan
buildPlan plan = NutrientPlan
{ orders = []
, recipes = []
, ingredients = []
, foodItems = []
}
-- prints out the type brought in by the readFile function
debugPrint :: String -> IO ()
debugPrint str = putStrLn str
main = do
planText <- readFile "test-plan.json"
debugPrint planText