forgot creation and deletion of certein references

This commit is contained in:
nek0 2014-09-07 06:57:53 +02:00
parent 11e70530b3
commit cf2c3f652f
3 changed files with 22 additions and 0 deletions

View file

@ -122,6 +122,13 @@ postMediumDeleteR mediumId = do
confirm <- lookupPostParam "confirm"
case confirm of
Just "confirm" -> do
-- delete references first
albumId <- return $ mediumAlbum medium
album <- runDB $ getJust albumId
mediaList <- return $ albumContent album
newMediaList <- return $ removeItem mediumId mediaList
-- update reference List
runDB $ update albumId [AlbumContent =. newMediaList]
liftIO $ removeFile (normalise $ tail $ mediumPath medium)
runDB $ delete mediumId
setMessage "Medium succesfully deleted"

View file

@ -27,8 +27,16 @@ postNewAlbumR = do
((result, albumWidget), enctype) <- runFormPost (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
albumList <- return $ userAlbums user
newAlbumList <- return $ 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

View file

@ -10,6 +10,7 @@ module Helper
, tagField
, sendMail
, generateString
, removeItem
)
where
@ -108,3 +109,9 @@ sendMail toEmail subject body =
generateString :: IO T.Text
generateString = (toHex . B.pack . take 16 . randoms) <$> newStdGen
removeItem :: Eq a => a -> [a] -> [a]
removeItem _ [] = []
removeItem x (y:ys)
| x == y = removeItem x ys
| otherwise = y : removeItem x ys