Created a route to fetch recent modifications as a csv to allow creating clients

This commit is contained in:
Stuce 2025-07-03 09:42:31 +01:00
parent de60936cd2
commit 1e661031fb
8 changed files with 71 additions and 11 deletions

View file

@ -11,7 +11,7 @@ module Handler.Group where
import Import
import Text.Read
import Database.Persist.Sql (fromSqlKey, toSqlKey, rawSql)
import Database.Persist.Sql (fromSqlKey, toSqlKey)
getGroupR :: Handler Html
getGroupR = do
userId <- getUserId
@ -25,7 +25,8 @@ postAddGroupR = do
-- TODO: in a newer version, put insertUnique_
user <- getUserId
_ <- runDB $ do
gId <- insert $ Group g
currentTime <- liftIO getCurrentTime
gId <- insert $ Group g currentTime
success <- insertUnique $ GroupUser user gId
when (isNothing success) $ delete gId
redirect GroupR
@ -54,9 +55,4 @@ postDeleteGroupR = do
let ids = map toSqlKey ints :: [GroupId]
-- TODO: make sure the user has access to it aswell (this only works now for single user), and handle group owned by many
runDB $ deleteWhere [GroupId <-. ids]
redirect EditGroupR
getGroups :: Key User -> Handler [Entity Group]
getGroups userId =
let sql = "SELECT ?? FROM \"group\" JOIN group_user gu ON \"group\".id = gu.group_id WHERE gu.user = ?" in
runDB $ rawSql sql [toPersistValue userId]
redirect EditGroupR