<commit_before>{-# LANGUAGE TupleSections, OverloadedStrings, ScopedTypeVariables #-}
module Handler.Swag 
    ( getSwagR
    , postSwagBuyR
    ) where

import Import
import Utils
import Handler.SwagForms

getSwagR :: Handler Html
getSwagR = do
    (LdapUser cn mail act onfl fina) <- getLdapUser
    swags <- map entityVal `fmap` (runDB $ selectList [] [Asc SwagCost, Asc SwagName])
    forms <- mapM (\_ -> generateFormPost swagBuyForm) swags
    let swagsandforms = zip swags forms
    defaultLayout $ do
        setTitle "Swag"
        $(widgetFile "swag")

postSwagBuyR :: Int -> Handler Html
postSwagBuyR sidi = do
    let sid = fromIntegral sidi
    user <- getUser `fmap` waiRequest
    (LdapUser cn mail _ _ _) <- getLdapUser
    ((result, widget), enctype) <- runFormPost $ swagBuyForm
    case result of
        FormSuccess (SwagBuy num) -> do
            msg <- runDB $ do
                swag <- get $ SwagKey sid
                case swag of
                    Just (Swag _ n _ _ _ c a) -> do
                           if a - num >= 0
                               then do<commit_msg>bounds checking<commit_after>{-# LANGUAGE TupleSections, OverloadedStrings, ScopedTypeVariables #-}
module Handler.Swag 
    ( getSwagR
    , postSwagBuyR
    ) where

import Import
import Utils
import Handler.SwagForms

getSwagR :: Handler Html
getSwagR = do
    (LdapUser cn mail act onfl fina) <- getLdapUser
    swags <- map entityVal `fmap` (runDB $ selectList [] [Asc SwagCost, Asc SwagName])
    forms <- mapM (\_ -> generateFormPost swagBuyForm) swags
    let swagsandforms = zip swags forms
    defaultLayout $ do
        setTitle "Swag"
        $(widgetFile "swag")

postSwagBuyR :: Int -> Handler Html
postSwagBuyR sidi = do
    let sid = fromIntegral sidi
    user <- getUser `fmap` waiRequest
    (LdapUser cn mail _ _ _) <- getLdapUser
    ((result, widget), enctype) <- runFormPost $ swagBuyForm
    case result of
        FormSuccess (SwagBuy num) -> do
            msg <- runDB $ do
                swag <- get $ SwagKey sid
                case swag of
                    Just (Swag _ n _ _ _ c a) -> do
                           if a - num >= 0 && num > 0
                               then do
{'fraction_non_alphanumeric': 0.08344609833107804, 'fraction_numerical': 0.0013531799729364006, 'mean_word_length': 2.0217983651226157, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624886', 'n_tokens_mistral': 749, 'n_tokens_neox': 705, 'n_words': 216}