aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Json/Search.hs
blob: 74f0ec999b870fcf6301d4f6af9e5ee797bdc183 (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
28
29
30
{-# LANGUAGE OverloadedStrings #-}

module Model.Json.Search
  ( Search(..)
  , getMaterialSearch
  ) where

import Control.Monad (mzero)
import Control.Applicative ((<$>), (<*>))

import Data.Aeson
import Data.Text (Text)
import Data.List (find)

data Search = Search
  { identifier :: Text
  , kind :: Text
  , name :: Text
  } deriving (Show)

instance FromJSON Search where
  parseJSON (Object v) =
    Search <$>
      v .: "id" <*>
      v .: "type" <*>
      v .: "name"
  parseJSON _ = mzero

getMaterialSearch :: [Search] -> Maybe Search
getMaterialSearch = find ((==) "matiere" . kind)