{-# LANGUAGE RecordWildCards #-}
module BDCS.Requirements(insertRequirement,
insertGroupRequirement)
where
import Control.Monad.IO.Class(MonadIO)
import Database.Esqueleto
import BDCS.DB(GroupRequirements(..), Requirements(..), orInsert)
import BDCS.Groups(findRequires, findGroupRequirements)
insertGroupRequirement :: MonadIO m => GroupRequirements -> SqlPersistT m (Key GroupRequirements)
insertGroupRequirement gr@GroupRequirements{..} =
findGroupRequirements groupRequirementsGroup_id groupRequirementsReq_id `orInsert` gr
insertRequirement :: MonadIO m => Requirements -> SqlPersistT m (Key Requirements)
insertRequirement req@Requirements{..} =
findRequires requirementsReq_language requirementsReq_context requirementsReq_strength requirementsReq_expr `orInsert` req