forked from filipg/gonito
add Challenge to model
This commit is contained in:
parent
f63b296e11
commit
765dddc644
2
Model.hs
2
Model.hs
@ -3,6 +3,8 @@ module Model where
|
||||
import ClassyPrelude.Yesod
|
||||
import Database.Persist.Quasi
|
||||
|
||||
import PersistSHA1
|
||||
|
||||
-- You can define all of your database entities in the entities file.
|
||||
-- You can find more information on persistent and how to declare entities
|
||||
-- at:
|
||||
|
23
PersistSHA1.hs
Normal file
23
PersistSHA1.hs
Normal 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"
|
@ -8,5 +8,27 @@ Email
|
||||
user UserId Maybe
|
||||
verkey Text Maybe
|
||||
UniqueEmail email
|
||||
|
||||
Repo
|
||||
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)
|
||||
|
@ -18,6 +18,7 @@ library
|
||||
Import
|
||||
Import.NoFoundation
|
||||
Model
|
||||
PersistSHA1
|
||||
Settings
|
||||
Settings.StaticFiles
|
||||
SharedTypes
|
||||
|
Loading…
Reference in New Issue
Block a user