add Challenge to model

This commit is contained in:
Filip Gralinski 2015-08-29 13:13:16 +02:00
parent f63b296e11
commit 765dddc644
4 changed files with 50 additions and 2 deletions

View File

@ -3,6 +3,8 @@ module Model where
import ClassyPrelude.Yesod import ClassyPrelude.Yesod
import Database.Persist.Quasi import Database.Persist.Quasi
import PersistSHA1
-- You can define all of your database entities in the entities file. -- You can define all of your database entities in the entities file.
-- You can find more information on persistent and how to declare entities -- You can find more information on persistent and how to declare entities
-- at: -- at:

23
PersistSHA1.hs Normal file
View File

@ -0,0 +1,23 @@
module PersistSHA1 where
import ClassyPrelude.Yesod
import Database.Persist.Sql
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Numeric (showHex)
data SHA1 = SHA1 ByteString
deriving Show
toHex :: ByteString -> ByteString
toHex = BC.pack . concat . (map (flip showHex "")) . B.unpack
instance PersistField SHA1 where
toPersistValue (SHA1 t) = PersistDbSpecific t
fromPersistValue (PersistDbSpecific t) = Right $ SHA1 $ B.concat ["E'\\x", toHex(t), "'"]
fromPersistValue _ = Left "SHA1 values must be converted from PersistDbSpecific"
instance PersistFieldSql SHA1 where
sqlType _ = SqlOther "BYTEA"

View File

@ -8,5 +8,27 @@ Email
user UserId Maybe user UserId Maybe
verkey Text Maybe verkey Text Maybe
UniqueEmail email UniqueEmail email
Repo
-- By default this file is used in Model.hs (which is imported by Foundation.hs) url Text
branch Text
currentCommit SHA1
owner UserId
ready Bool default=False
stamp UTCTime default=now()
UniqueUrlBranch url branch
deriving Show
Challenge
publicRepo RepoId
privateRepo RepoId
name Text
UniqueName name
title Text
description Text
stamp UTCTime default=now()
Test
challenge ChallengeId
checksum SHA1
commit SHA1
active Bool default=True
UniqueChallengeChecksum challenge checksum
-- By default this file is used in Model.hs (which is imported by Foundation.hs)

View File

@ -18,6 +18,7 @@ library
Import Import
Import.NoFoundation Import.NoFoundation
Model Model
PersistSHA1
Settings Settings
Settings.StaticFiles Settings.StaticFiles
SharedTypes SharedTypes