1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 01:14:51 +09:00

Replace some Esqueleto with much simpler Persistent queries

This commit is contained in:
fr33domlover 2016-03-03 08:35:29 +00:00
parent b20c672a01
commit 9afd341aca
4 changed files with 49 additions and 60 deletions

View file

@ -87,14 +87,10 @@ getPersonNewR = do
getPersonR :: Text -> Handler Html getPersonR :: Text -> Handler Html
getPersonR ident = do getPersonR ident = do
people <- runDB $ select $ from $ \ (sharer, person) -> do person <- runDB $ do
where_ $ Entity sid _s <- getBy404 $ UniqueSharerIdent ident
sharer ^. SharerIdent ==. val ident &&. Entity _pid p <- getBy404 $ UniquePersonIdent sid
sharer ^. SharerId ==. person ^. PersonIdent return p
return person defaultLayout $ do
case people of
[] -> notFound
p:ps -> defaultLayout $ do
let mperson = if null ps then Just p else Nothing
setTitle $ text $ "Vervis > People > " <> ident setTitle $ text $ "Vervis > People > " <> ident
$(widgetFile "person") $(widgetFile "person")

View file

@ -72,16 +72,11 @@ getProjectNewR ident = do
getProjectR :: Text -> Text -> Handler Html getProjectR :: Text -> Text -> Handler Html
getProjectR user proj = do getProjectR user proj = do
projects <- runDB $ select $ from $ \ (sharer, project) -> do project <- runDB $ do
where_ $ Entity sid _s <- getBy404 $ UniqueSharerIdent user
sharer ^. SharerIdent ==. val user &&. Entity _pid p <- getBy404 $ UniqueProject proj sid
project ^. ProjectIdent ==. val proj &&. return p
sharer ^. SharerId ==. project ^. ProjectSharer defaultLayout $ do
return project
case projects of
[] -> notFound
p:ps -> defaultLayout $ do
let mproject = if null ps then Just p else Nothing
setTitle $ text $ mconcat setTitle $ text $ mconcat
[ "Vervis > People > " [ "Vervis > People > "
, user , user

View file

@ -14,7 +14,6 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<h1>Vervis > People > #{ident} <h1>Vervis > People > #{ident}
$maybe Entity _pid _person <- mperson
<h2>About <h2>About
<p> <p>
This is the user page for <b>#{ident}</b> This is the user page for <b>#{ident}</b>
@ -23,6 +22,3 @@ $maybe Entity _pid _person <- mperson
<p> <p>
See See
<a href=@{ProjectsR ident}>projects</a>. <a href=@{ProjectsR ident}>projects</a>.
$nothing
<p>Internal error: More than one user with the same identifier!

View file

@ -14,7 +14,6 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<h1>Vervis > People > #{user} > Projects > #{proj} <h1>Vervis > People > #{user} > Projects > #{proj}
$maybe Entity _pid project <- mproject
<h2>About <h2>About
<p>This is the project page for <b>#{proj}</b>, shared by <b>#{user}</b>. <p>This is the project page for <b>#{proj}</b>, shared by <b>#{user}</b>.
@ -35,5 +34,8 @@ $maybe Entity _pid project <- mproject
$nothing $nothing
(none) (none)
$nothing <h2>Repos
<p>Internal error: More than one project per user/proj name pair!
<p>
See
<a href=@{ReposR user proj}>repos</a>.