checking for album namesakes for user

This commit is contained in:
nek0 2016-12-19 02:44:44 +01:00
parent d8809907d2
commit 4d936a0910

View file

@ -48,18 +48,24 @@ postNewAlbumR = do
albumForm userId albumForm userId
case result of case result of
FormSuccess album -> do FormSuccess album -> do
-- Put album in Database namesakes <- runDB $ selectList [AlbumTitle ==. albumTitle album, albumOwner ==. userId] []
albumId <- runDB $ insert album if null lamesakes
-- add album reference in user then do
user <- runDB $ getJust userId -- Put album in Database
let albumList = userAlbums user albumId <- runDB $ insert album
let newAlbumList = albumId : albumList -- add album reference in user
runDB $ update userId [UserAlbums =. newAlbumList] user <- runDB $ getJust userId
-- create folder let albumList = userAlbums user
liftIO $ createDirectory $ "static" </> "data" </> unpack (extractKey userId) </> unpack (extractKey albumId) let newAlbumList = albumId : albumList
-- outro runDB $ update userId [UserAlbums =. newAlbumList]
setMessage "Album successfully created" -- create folder
redirect $ ProfileR userId liftIO $ createDirectory $ "static" </> "data" </> unpack (extractKey userId) </> unpack (extractKey albumId)
-- outro
setMessage "Album successfully created"
redirect $ AlbumR albumId
else do
setMessage $ "You already have an album named " ++ albumTitle album
redirect $ AlbumR $ entityKey $ head namesakes
_ -> do _ -> do
setMessage "There was an error creating the album" setMessage "There was an error creating the album"
redirect NewAlbumR redirect NewAlbumR