Favourites are tracked, but not yet used
This commit is contained in:
parent
1bd645f25b
commit
2dde6c67bc
1
models
1
models
@ -69,6 +69,7 @@ CourseFavourite
|
|||||||
user UserId
|
user UserId
|
||||||
time UTCTime
|
time UTCTime
|
||||||
course CourseId
|
course CourseId
|
||||||
|
UniqueCourseFavourite user course
|
||||||
Lecturer
|
Lecturer
|
||||||
userId UserId
|
userId UserId
|
||||||
courseId CourseId
|
courseId CourseId
|
||||||
|
|||||||
2
routes
2
routes
@ -15,7 +15,7 @@
|
|||||||
/course/ CourseListR GET
|
/course/ CourseListR GET
|
||||||
!/course/new CourseNewR GET POST !lecturerAny
|
!/course/new CourseNewR GET POST !lecturerAny
|
||||||
!/course/#TermId CourseListTermR GET
|
!/course/#TermId CourseListTermR GET
|
||||||
/course/#TermId/#Text CourseR:
|
/course/#TermId/#Text CourseR !updateFavourite:
|
||||||
/show CourseShowR GET POST
|
/show CourseShowR GET POST
|
||||||
/edit CourseEditR GET POST !lecturer
|
/edit CourseEditR GET POST !lecturer
|
||||||
|
|
||||||
|
|||||||
@ -48,12 +48,14 @@ import Data.Conduit (($$))
|
|||||||
import Data.Conduit.List (sourceList)
|
import Data.Conduit.List (sourceList)
|
||||||
|
|
||||||
import Control.Monad.Except (MonadError(..), runExceptT)
|
import Control.Monad.Except (MonadError(..), runExceptT)
|
||||||
|
import Control.Monad.Trans.Maybe (MaybeT(..))
|
||||||
|
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
|
||||||
import Handler.Utils.Templates
|
import Handler.Utils.Templates
|
||||||
import Handler.Utils.StudyFeatures
|
import Handler.Utils.StudyFeatures
|
||||||
|
|
||||||
|
|
||||||
-- infixl 9 :$:
|
-- infixl 9 :$:
|
||||||
-- pattern a :$: b = a b
|
-- pattern a :$: b = a b
|
||||||
|
|
||||||
@ -144,7 +146,23 @@ instance Yesod UniWorX where
|
|||||||
-- b) Validates that incoming write requests include that token in either a header or POST parameter.
|
-- b) Validates that incoming write requests include that token in either a header or POST parameter.
|
||||||
-- To add it, chain it together with the defaultMiddleware: yesodMiddleware = defaultYesodMiddleware . defaultCsrfMiddleware
|
-- To add it, chain it together with the defaultMiddleware: yesodMiddleware = defaultYesodMiddleware . defaultCsrfMiddleware
|
||||||
-- For details, see the CSRF documentation in the Yesod.Core.Handler module of the yesod-core package.
|
-- For details, see the CSRF documentation in the Yesod.Core.Handler module of the yesod-core package.
|
||||||
yesodMiddleware = defaultYesodMiddleware
|
yesodMiddleware handler = do
|
||||||
|
res <- defaultYesodMiddleware handler
|
||||||
|
void . runMaybeT $ do
|
||||||
|
route@(routeAttrs -> attrs) <- MaybeT getCurrentRoute
|
||||||
|
case route of
|
||||||
|
CourseR tid csh _ | "updateFavourite" `elem` attrs -> do
|
||||||
|
uid <- MaybeT maybeAuthId
|
||||||
|
now <- liftIO $ getCurrentTime
|
||||||
|
void . lift . runDB . runMaybeT $ do
|
||||||
|
cid <- MaybeT . getKeyBy $ CourseTermShort tid csh
|
||||||
|
lift $ upsertBy
|
||||||
|
(UniqueCourseFavourite uid cid)
|
||||||
|
(CourseFavourite uid now cid)
|
||||||
|
[CourseFavouriteTime =. now]
|
||||||
|
|
||||||
|
_other -> return ()
|
||||||
|
return res
|
||||||
|
|
||||||
defaultLayout = defaultLinkLayout []
|
defaultLayout = defaultLinkLayout []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user