1 {-# LANGUAGE OverloadedStrings, TemplateHaskell, TypeFamilies #-} 2 module Databrary.Model.Container.Types 3 ( ContainerRow(..) 4 , Container(..) 5 , getContainerVolumeRole 6 , getContainerRelease 7 ) where 8 9 import Data.Foldable (fold) 10 import qualified Data.Text as T 11 12 import Databrary.Has (Has(..)) 13 import Databrary.Model.Time 14 import Databrary.Model.Kind 15 import Databrary.Model.Release.Types 16 import Databrary.Model.Id.Types 17 import Databrary.Model.Volume.Types 18 import Databrary.Model.Permission.Types 19 20 type instance IdType Container = Int32 21 22 data ContainerRow = ContainerRow 23 { containerId :: Id Container 24 , containerTop :: Bool 25 , containerName :: Maybe T.Text 26 , containerDate :: Maybe Date 27 } -- deriving (Eq, Show) 28 29 data Container = Container 30 { containerRow :: !ContainerRow 31 , containerRelease :: Maybe Release 32 , containerVolume :: Volume 33 } 34 35 getContainerVolumeRole :: Container -> VolumeRolePolicy 36 getContainerVolumeRole = volumeRolePolicy . containerVolume 37 38 getContainerRelease :: Container -> EffectiveRelease 39 getContainerRelease c = 40 EffectiveRelease { 41 effRelPublic = (fold . containerRelease) c 42 , effRelPrivate = ReleasePRIVATE -- TODO: name hardcoded default level for Private release centrally 43 } 44 45 instance Kinded Container where 46 kindOf _ = "container" 47 48 instance Has (Id Container) ContainerRow where 49 view = containerId 50 51 instance Has (Id Container) Container where 52 view = (view . containerRow) 53 instance Has (Maybe Release) Container where 54 view = containerRelease 55 instance Has Volume Container where 56 view = containerVolume 57 instance Has Permission Container where 58 view = (view . containerVolume) 59 instance Has (Id Volume) Container where 60 view = (view . containerVolume) 61 62 ERROR: ("",8,Loc 62 1,[],[(Loc 62 3,Loc 62 24,TopLevelDecl False 0),(Loc 62 3,Loc 62 24,NotTicked),(Loc 62 10,Loc 62 24,NotTicked),(Loc 64 3,Loc 64 33,TopLevelDecl False 1),(Loc 64 3,Loc 64 33,IsTicked),(Loc 64 10,Loc 64 33,IsTicked),(Loc 64 11,Loc 64 14,IsTicked),(Loc 64 18,Loc 64 32,IsTicked),(Loc 66 3,Loc 66 33,TopLevelDecl False 0),(Loc 66 3,Loc 66 33,NotTicked)])