checking for album namesakes for user
This commit is contained in:
parent
d8809907d2
commit
4d936a0910
1 changed files with 18 additions and 12 deletions
|
@ -48,18 +48,24 @@ postNewAlbumR = do
|
|||
albumForm userId
|
||||
case result of
|
||||
FormSuccess album -> do
|
||||
-- Put album in Database
|
||||
albumId <- runDB $ insert album
|
||||
-- add album reference in user
|
||||
user <- runDB $ getJust userId
|
||||
let albumList = userAlbums user
|
||||
let newAlbumList = albumId : albumList
|
||||
runDB $ update userId [UserAlbums =. newAlbumList]
|
||||
-- create folder
|
||||
liftIO $ createDirectory $ "static" </> "data" </> unpack (extractKey userId) </> unpack (extractKey albumId)
|
||||
-- outro
|
||||
setMessage "Album successfully created"
|
||||
redirect $ ProfileR userId
|
||||
namesakes <- runDB $ selectList [AlbumTitle ==. albumTitle album, albumOwner ==. userId] []
|
||||
if null lamesakes
|
||||
then do
|
||||
-- Put album in Database
|
||||
albumId <- runDB $ insert album
|
||||
-- add album reference in user
|
||||
user <- runDB $ getJust userId
|
||||
let albumList = userAlbums user
|
||||
let newAlbumList = albumId : albumList
|
||||
runDB $ update userId [UserAlbums =. newAlbumList]
|
||||
-- create folder
|
||||
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
|
||||
setMessage "There was an error creating the album"
|
||||
redirect NewAlbumR
|
||||
|
|
Loading…
Reference in a new issue