From 577f8634c8a5f98618a1ccbaa61156f9692137f5 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 19 Dec 2016 02:55:51 +0100 Subject: [PATCH] fixing vanity links --- Handler/Album.hs | 16 ++++++++++++++++ config/routes | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Handler/Album.hs b/Handler/Album.hs index f42e099..425a49e 100755 --- a/Handler/Album.hs +++ b/Handler/Album.hs @@ -48,3 +48,19 @@ getAlbumR albumId = do Nothing -> do setMessage "This album does not exist" redirect HomeR + +getBeautyAlbumR :: T.Text -> T.Text -> Handler Html +getBeautyAlbumR ownerName albumName = do + tempOwner <- runDB $ getBy $ UniqueUser ownerName + case tempOwner of + Just (Entity ownerId _) -> do + tempAlbum <- rundB $ selectFirst [AlbumTitle ==. albumName, albumOwner ==. ownerId] [] + case tempAlbum of + Just (Entity albumId _) -> + getAlbumR albumId + Nothing -> do + setMessage $ "This user has no album named " `T.append` albumName + redirect $ UserR ownerName + Nothing -> do + setMessage "This user does not exist" + redirect HomeR diff --git a/config/routes b/config/routes index 995913e..8734198 100755 --- a/config/routes +++ b/config/routes @@ -26,7 +26,8 @@ /logout LogoutR GET /activate/#T.Text ActivateR GET POST /profile/#UserId ProfileR GET -/user/#T.Text UserR GET +/#T.Text UserR GET +/#T.Text/T.Text BeatyAlbumR GET /upload UploadR GET POST /newalbum NewAlbumR GET POST /album/#AlbumId AlbumR GET