@@ -13,7 +13,7 @@ import Data.List.Split (keepDelimsL, split, splitWhen, whenElt)
1313import Data.Text (strip )
1414import qualified Data.Text as T
1515import Data.Time.Clock (getCurrentTime )
16- import Database.DataType (PostType (.. ))
16+ import Database.DataType (ProgramType (.. ))
1717import Database.Persist (insertUnique )
1818import Database.Persist.Sqlite (SqlPersistM , insert_ )
1919import Database.Tables
@@ -41,18 +41,18 @@ addPostToDatabase programElements = do
4141 Left _ -> return ()
4242 Right (department, code) -> do
4343 currTime <- liftIO getCurrentTime
44- postExists <- insertUnique Post {
45- postName = getPostType code department,
46- postDepartment = department,
47- postCode = code,
48- postDescription = descriptionText,
49- postRequirements = renderTags requirementLines,
50- postCreated = currTime,
51- postModified = currTime
44+ programExists <- insertUnique Program {
45+ programName = getPostType code department,
46+ programDepartment = department,
47+ programCode = code,
48+ programDescription = descriptionText,
49+ programRequirements = renderTags requirementLines,
50+ programCreated = currTime,
51+ programModified = currTime
5252 }
53- case postExists of
53+ case programExists of
5454 Just key ->
55- mapM_ (insert_ . PostCategory key) requirements
55+ mapM_ (insert_ . ProgramCategory key) requirements
5656 Nothing -> return ()
5757 where
5858 isDescriptionSection tag = tagOpenAttrNameLit " div" " class" (T. isInfixOf " views-field-body" ) tag || isRequirementSection tag
@@ -73,12 +73,12 @@ postInfoParser = do
7373
7474-- | Extracts the post type (eg. major) from a post code if it is non-empty,
7575-- | or from a dept name otherwise
76- getPostType :: T. Text -> T. Text -> PostType
76+ getPostType :: T. Text -> T. Text -> ProgramType
7777getPostType " " deptName = getPostTypeFromName deptName
7878getPostType code _ = getPostTypeFromCode code
7979
8080-- | Extracts the post type (eg. major) from a post name (eg. "Biology Specialist")
81- getPostTypeFromName :: T. Text -> PostType
81+ getPostTypeFromName :: T. Text -> ProgramType
8282getPostTypeFromName deptName
8383 | T. isInfixOf " Specialist" deptName = Specialist
8484 | T. isInfixOf " Major" deptName = Major
@@ -87,12 +87,12 @@ getPostTypeFromName deptName
8787 | T. isInfixOf " Certificate" deptName = Certificate
8888 | otherwise = Other
8989
90- -- | Extracts the post type (eg. major) from a post code (eg. ASMAJ1689)
91- getPostTypeFromCode :: T. Text -> PostType
90+ -- | Extracts the program type (eg. major) from a program code (eg. ASMAJ1689)
91+ getPostTypeFromCode :: T. Text -> ProgramType
9292getPostTypeFromCode = abbrevToPost . T. take 3 . T. drop 2
9393
94- -- | Maps the post type abbreviations to their corresponding PostType
95- abbrevToPost :: T. Text -> PostType
94+ -- | Maps the post type abbreviations to their corresponding ProgramType
95+ abbrevToPost :: T. Text -> ProgramType
9696abbrevToPost " SPE" = Specialist
9797abbrevToPost " MAJ" = Major
9898abbrevToPost " MIN" = Minor
0 commit comments