1 {-# LANGUAGE TemplateHaskell, TypeFamilies, OverloadedStrings #-} 2 module Databrary.Model.Category.Types 3 ( Category(..) 4 ) where 5 6 import Data.Function (on) 7 import Data.Int (Int16) 8 import Data.Ord (comparing) 9 import qualified Data.Text as T 10 import Instances.TH.Lift () 11 import Language.Haskell.TH.Lift (deriveLift) 12 13 import Databrary.Has (Has(..)) 14 import Databrary.Model.Kind 15 import Databrary.Model.Id.Types 16 17 type instance IdType Category = Int16 18 19 data Category = Category 20 { categoryId :: !(Id Category) 21 , categoryName :: !T.Text 22 , categoryDescription :: !(Maybe T.Text) 23 } deriving (Show) 24 25 instance Kinded Category where 26 kindOf _ = "category" 27 28 instance Eq Category where 29 (==) = on (==) categoryId 30 (/=) = on (/=) categoryId 31 32 instance Ord Category where 33 compare = comparing categoryId 34 35 -- makeHasRec ''Category ['categoryId] 36 instance Has (Id Category) Category where 37 view = categoryId 38 39 deriveLift ''Category