Commit 5927df2e authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

check existence user first, dummy.

parent 60e8186f
......@@ -45,8 +45,9 @@ getUserProfileCoach authres profilename = do
postUserFollowCoach ::
MonadIO m => AuthResult User -> Text -> CoachT m NoContent
postUserFollowCoach (Authenticated user) profilename = do
muser <- runDb $ getBy $ UniqueUsername profilename
follows <- runDb $ selectFollows (userUsername user) profilename
unless (null follows) $
unless (null follows || isNothing muser) $
throwError err409 {errBody = "Already followed that profile"}
runDb $ insertFollows (userUsername user) profilename
return NoContent
......@@ -54,8 +55,9 @@ postUserFollowCoach _ _ = throwError err401
deleteUserFollowCoach :: MonadIO m => AuthResult User -> Text -> CoachT m NoContent
deleteUserFollowCoach (Authenticated user) profilename = do
muser <- runDb $ getBy $ UniqueUsername profilename
follows <- runDb $ selectFollows (userUsername user) profilename
when (null follows) $
when (null follows || isNothing muser) $
throwError err404 {errBody = "You are not following that profile"}
runDb $ deleteFollows (userUsername user) profilename
return NoContent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment