blob: 194a4c80119ad2910678187760826d73cca704a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
|