Skip to content

Commit 94b084c

Browse files
authored
Fixed Focus info popup by restoring post route (#1575)
1 parent cc23c8f commit 94b084c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### 🐛 Bug fixes
1212

13+
- Fixed a bug that was causing the focus info popup to appear blank
14+
1315
### 🔧 Internal changes
1416

1517
- Refactored navigation bar into a React component (for the graph, grid and generate pages only - the about page navigation bar is still rendered using Blaze)

app/Database/CourseQueries.hs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and serve the information back to the client.
99
-}
1010

1111
module Database.CourseQueries
12-
(returnPost,
12+
(retrievePost,
13+
returnPost,
1314
reqsForPost,
1415
prereqsForCourse,
1516
returnMeeting,
@@ -26,7 +27,29 @@ import qualified Data.Text as T (Text, append, isPrefixOf, snoc, tail, toUpper,
2627
import Database.Persist.Sqlite (Entity, PersistValue (PersistText), SqlPersistM, entityKey,
2728
entityVal, rawSql, selectFirst, selectList, (<-.), (==.))
2829
import Database.Tables as Tables
30+
import Happstack.Server.SimpleHTTP (Request, Response, ServerPart, askRq, ifModifiedSince,
31+
lookText')
2932
import Models.Course (buildCourse, buildMeetTimes)
33+
import Util.Happstack (createJSONResponse)
34+
35+
-- | Takes a http request with a post code and sends a JSON response containing the post data
36+
-- | if the post data has been modified since the timestamp in the request,
37+
-- | or a 304 "Not Modified" response otherwise
38+
retrievePost :: ServerPart Response
39+
retrievePost = do
40+
req <- askRq
41+
code <- lookText' "code"
42+
liftIO $ queryPost req code
43+
44+
-- | Queries the database for the post data then returns a JSON response of it
45+
-- | if the post data has been modified since the timestamp in the request,
46+
-- | or a 304 "Not Modified" response otherwise
47+
queryPost :: Request -> T.Text -> IO Response
48+
queryPost req code = do
49+
postMaybe <- returnPost code
50+
case postMaybe of
51+
Nothing -> return $ createJSONResponse (Nothing :: Maybe Post)
52+
Just post -> return $ ifModifiedSince (postModified post) req (createJSONResponse post)
3053

3154
-- | Queries the database for information about the post then returns the post value
3255
returnPost :: T.Text -> IO (Maybe Post)

app/Routes.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Controllers.Generate as GenerateController (findAndSavePrereqsResponse, g
77
import Controllers.Graph as GraphsController (getGraphJSON, graphImageResponse, graphResponse,
88
index, saveGraphJSON)
99
import Controllers.Timetable as TimetableController
10+
import Database.CourseQueries (retrievePost)
1011
import Happstack.Server (Browsing (DisableBrowsing), Response, ServerPart, ServerPartT,
1112
ToMessage (toResponse), dir, noTrailingSlash, nullDir, seeOther,
1213
serveDirectory)
@@ -27,6 +28,7 @@ strictRoutes = [
2728
("image", graphImageResponse),
2829
("timetable-image", TimetableController.exportTimetableImageResponse),
2930
("timetable-pdf", TimetableController.exportTimetablePDFResponse),
31+
("post", retrievePost),
3032
("draw", drawResponse),
3133
("about", aboutResponse),
3234
("graphs", GraphsController.index),

0 commit comments

Comments
 (0)