• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Courseography / courseography / 6ca2fc21-e28e-4b1f-931e-25ce91baa664

16 Sep 2025 02:22AM UTC coverage: 54.687%. Remained the same
6ca2fc21-e28e-4b1f-931e-25ce91baa664

push

circleci

web-flow
Refactored Database files to MVC architecture (#1604)

* created Program file in models folder
* created Meeting file in models folder
* removed CourseQueries.hs and CourseInsertion.hs
* renamed post -> program across the codebase, excluding database tables and route names

485 of 952 branches covered (50.95%)

Branch coverage included in aggregate %.

31 of 87 new or added lines in 6 files covered. (35.63%)

2 existing lines in 1 file now uncovered.

2187 of 3934 relevant lines covered (55.59%)

160.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/app/Controllers/Program.hs
1
module Controllers.Program(index, retrieveProgram) where
2

3
import Config (runDb)
4
import Control.Monad.IO.Class (liftIO)
5
import qualified Data.Text as T (Text, unlines)
6
import Database.Persist (Entity)
7
import Database.Persist.Sqlite (SqlPersistM, entityVal, selectList)
8
import Database.Tables as Tables (Post, postCode, postModified)
9
import Happstack.Server (Request, Response, ServerPart, askRq, ifModifiedSince, lookText',
10
                         toResponse)
11
import Models.Program (returnProgram)
12
import Util.Happstack (createJSONResponse)
13

14
-- | Builds a list of all program codes in the database
15
index :: ServerPart Response
16
index = do
1✔
17
    response <- liftIO $ runDb $ do
3✔
18
        programsList :: [Entity Post] <- selectList [] []
1✔
19
        let codes = map (postCode . entityVal) programsList
3✔
20
        return $ T.unlines codes :: SqlPersistM T.Text
3✔
21
    return $ toResponse response
3✔
22

23
-- | Takes a http request with a program code and sends a JSON response containing the program data
24
-- | if the program data has been modified since the timestamp in the request,
25
-- | or a 304 "Not Modified" response otherwise
26
retrieveProgram :: ServerPart Response
NEW
27
retrieveProgram = do
×
NEW
28
    req <- askRq
×
NEW
29
    code <- lookText' "code"
×
NEW
30
    liftIO $ queryProgram req code
×
31

32
-- | Queries the database for the program data then returns a JSON response of it
33
-- | if the program data has been modified since the timestamp in the request,
34
-- | or a 304 "Not Modified" response otherwise
35
queryProgram :: Request -> T.Text -> IO Response
NEW
36
queryProgram req code = do
×
NEW
37
    programMaybe <- returnProgram code
×
NEW
38
    case programMaybe of
×
NEW
39
        Nothing -> return $ createJSONResponse (Nothing :: Maybe Post)
×
NEW
40
        Just program -> return $ ifModifiedSince (postModified program) req (createJSONResponse program)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc