diff options
author | Joris | 2015-08-30 21:17:27 +0200 |
---|---|---|
committer | Joris | 2015-08-30 21:17:27 +0200 |
commit | c4eb771fa09e3972106d80ada6b3c4a023b85249 (patch) | |
tree | 9214b64628e34089b73ff6b4bdcb0edbc668a51e /src/Model/Json |
Fetch perfumes according to multiple materials
Diffstat (limited to 'src/Model/Json')
-rw-r--r-- | src/Model/Json/Search.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Model/Json/Search.hs b/src/Model/Json/Search.hs new file mode 100644 index 0000000..194a4c8 --- /dev/null +++ b/src/Model/Json/Search.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Model.Json.Search + ( Search(..) + , getMaterialIdentifier + ) where + +import Control.Monad (mzero) + +import Data.Aeson +import Data.Text (Text) +import Data.List (find) + +data Search = Search + { identifier :: Text + , kind :: Text + } deriving (Show) + +instance FromJSON Search where + parseJSON (Object v) = + Search <$> + v .: "id" <*> + v .: "type" + parseJSON _ = mzero + +getMaterialIdentifier :: [Search] -> Maybe Text +getMaterialIdentifier = fmap identifier . find ((==) "matiere" . kind) |