33{-# LANGUAGE DuplicateRecordFields #-}
44{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6- {-# LANGUAGE InstanceSigs #-}
76{-# LANGUAGE MultiParamTypeClasses #-}
87{-# LANGUAGE OverloadedLabels #-}
98{-# LANGUAGE OverloadedLists #-}
@@ -22,12 +21,12 @@ import Data.Proxy
2221-- import Control.Exception ( throw)
2322import Data.Swagger hiding (Contact )
2423import Database.Selda
25- -- import Database.Selda.SqlType as Selda
26- import GHC.OverloadedLabels
2724import Data.Int
2825
2926import IOHK.Certification.Persistence.Structure.Profile
3027import IOHK.Certification.Persistence.Structure.Subscription
28+ import IOHK.Certification.Persistence.Structure.Certification
29+ import IOHK.Certification.Persistence.Structure.Run
3130
3231import qualified Data.Text as Text
3332import qualified Data.Aeson.KeyMap as KM
@@ -118,118 +117,6 @@ instance ToSchema ProfileDTO where
118117 return $ NamedSchema (Just " ProfileDTO" ) $ profileSchema
119118 & properties %~ (`mappend` [ (" dapp" , dappSchema) ])
120119
121- --------------------------------------------------------------------------------
122- -- | Certification
123- {-
124- data CertificationLevel = L0 | L1 | L2 | L3
125- deriving (Generic,Show,Read,Eq,Ord,Enum)
126-
127- instance SqlType CertificationLevel where
128- mkLit n = LCustom TInt64 (LInt64 (toInt64 n))
129- where
130- toInt64 = \case
131- L0 -> 0
132- L1 -> 1
133- L2 -> 2
134- L3 -> 3
135- sqlType _ = TInt64
136- fromSql (SqlInt64 0) = L0
137- fromSql (SqlInt64 1) = L1
138- fromSql (SqlInt64 2) = L2
139- fromSql (SqlInt64 3) = L3
140- fromSql v = throw $ userError $ "fromSql: expected SqlInt64, got " ++ show v
141- defaultValue = mkLit L1
142-
143- instance ToJSON CertificationLevel where
144- toJSON = toJSON . \case
145- L0 -> "l0" :: String
146- L1 -> "l1"
147- L2 -> "l2"
148- L3 -> "l3"
149-
150- instance FromJSON CertificationLevel where
151- parseJSON = withText "CertificationLevel" $ \case
152- "l0" -> pure L0
153- "l1" -> pure L1
154- "l2" -> pure L2
155- "l3" -> pure L3
156- _ -> fail "CertificationLevel"
157-
158- instance ToSchema CertificationLevel where
159- declareNamedSchema _ = do
160- let values = [ "l0", "l1", "l2", "l3" ] :: [Value]
161- return $ NamedSchema (Just "CertificationLevel") $ mempty
162- & type_ ?~ SwaggerString
163- & enum_ ?~ values
164- -}
165-
166- data Certification = Certification
167- { certId :: ID Certification
168- , certTransactionId :: Text
169- , certCreatedAt :: UTCTime
170- } deriving (Generic ,Show )
171-
172- instance FromJSON Certification where
173- parseJSON = withObject " Certification" $ \ v -> Certification def
174- <$> v .: " transactionId"
175- <*> v .: " createdAt"
176-
177- instance ToJSON Certification where
178- toJSON (Certification {.. }) = object
179- [ " transactionId" .= certTransactionId
180- , " createdAt" .= certCreatedAt
181- ]
182-
183- instance ToSchema Certification where
184- declareNamedSchema _ = do
185- textSchema <- declareSchemaRef (Proxy :: Proxy Text )
186- utcSchema <- declareSchemaRef (Proxy :: Proxy UTCTime )
187- return $ NamedSchema (Just " Certification" ) $ mempty
188- & type_ ?~ SwaggerObject
189- & properties .~
190- [ (" transactionId" , textSchema)
191- , (" createdAt" , utcSchema)
192- ]
193- & required .~ [ " createdAt" ]
194-
195- instance SqlRow Certification
196-
197- -- one to one mapping with Run
198- data L1Certification = L1Certification
199- { l1CertRunId :: UUID
200- , l1CertId :: ID Certification
201- } deriving (Generic ,Show )
202-
203- instance SqlRow L1Certification
204-
205- data L1CertificationDTO = L1CertificationDTO
206- { l1Certification :: L1Certification
207- , certification :: Certification
208- }
209-
210- instance ToJSON L1CertificationDTO where
211- toJSON L1CertificationDTO {.. } = Object (x <> y)
212- where
213- x = case toJSON certification of
214- Object obj -> obj
215- _ -> KM. empty
216- y = KM. fromList [ " runId" .= l1CertRunId l1Certification ]
217-
218- instance FromJSON L1CertificationDTO where
219- parseJSON = withObject " L1CertificationDTO" $ \ v -> do
220- l1Certification <- L1Certification
221- <$> v .: " runId"
222- <*> pure def
223- L1CertificationDTO l1Certification <$> v .: " runId"
224-
225- instance ToSchema L1CertificationDTO where
226- declareNamedSchema _ = do
227- certificationSchema <- declareSchema (Proxy :: Proxy Certification )
228- uuidSchema <- declareSchemaRef (Proxy :: Proxy UUID )
229- return $ NamedSchema (Just " TierDTO" ) $ certificationSchema
230- & properties %~ (`mappend` [ (" certRunId" , uuidSchema) ])
231- & required %~ (<> [ " certRunId" ])
232-
233120--------------------------------------------------------------------------------
234121-- | Dapp
235122
@@ -275,115 +162,6 @@ instance ToJSON DApp where
275162
276163instance SqlRow DApp
277164
278- --------------------------------------------------------------------------------
279- -- | Run
280-
281- data Status = Queued | Failed | Succeeded | ReadyForCertification | Certified | Aborted
282- deriving (Show , Read , Bounded , Enum , Eq , Generic )
283-
284- instance ToJSON Status where
285- toJSON :: Status -> Value
286- toJSON Queued = toJSON (" queued" :: Text )
287- toJSON Failed = toJSON (" failed" :: Text )
288- toJSON Succeeded = toJSON (" succeeded" :: Text )
289- toJSON ReadyForCertification = toJSON (" ready-for-certification" :: Text )
290- toJSON Certified = toJSON (" certified" :: Text )
291- toJSON Aborted = toJSON (" aborted" :: Text )
292-
293- instance FromJSON Status where
294- parseJSON =
295- withText " Status" handle
296- where
297- handle " queued" = pure Queued
298- handle " failed" = pure Failed
299- handle " succeeded" = pure Succeeded
300- handle " certified" = pure Succeeded
301- handle " ready-for-certification" = pure ReadyForCertification
302- handle " aborted" = pure Aborted
303- handle t = fail $ " provided text (" ++ show t ++ " ) is not a Status"
304-
305- instance SqlType Status
306-
307- type CommitHash = Text
308- type CertificationPrice = Int64
309- data Run = Run
310- { runId :: UUID
311- , created :: UTCTime
312- , finishedAt :: Maybe UTCTime
313- , syncedAt :: UTCTime
314- , repoUrl :: Text
315- , commitDate :: UTCTime
316- , commitHash :: CommitHash
317- , runStatus :: Status
318- , profileId :: ID Profile
319- , certificationPrice :: CertificationPrice
320- , reportContentId :: Maybe Text
321- } deriving (Generic ,Show )
322-
323- instance ToSchema Status where
324- declareNamedSchema _ = do
325- let values = [" queued" , " failed" , " succeeded" , " certified" , " ready-for-certification" ," aborted" ] :: [Value ]
326- return $ NamedSchema (Just " RunStatus" ) $ mempty
327- & type_ ?~ SwaggerString
328- & enum_ ?~ values
329-
330- instance ToSchema Run where
331- declareNamedSchema _ = do
332- utcSchema <- declareSchemaRef (Proxy :: Proxy UTCTime )
333- utcSchemaM <- declareSchemaRef (Proxy :: Proxy (Maybe UTCTime ))
334- textSchema <- declareSchemaRef (Proxy :: Proxy Text )
335- statusSchema <- declareSchemaRef (Proxy :: Proxy Status )
336- uuidSchema <- declareSchemaRef (Proxy :: Proxy UUID )
337- intSchema <- declareSchemaRef (Proxy :: Proxy Int )
338- return $ NamedSchema (Just " Run" ) $ mempty
339- & type_ ?~ SwaggerObject
340- & properties .~
341- [ (" created" , utcSchema)
342- , (" runId" , uuidSchema)
343- , (" finishedAt" , utcSchemaM)
344- , (" syncedAt" , utcSchema)
345- , (" repoUrl" , textSchema)
346- , (" commitDate" , utcSchema)
347- , (" commitHash" , textSchema)
348- , (" runStatus" , statusSchema)
349- , (" certificationPrice" , intSchema)
350- , (" reportContentId" , textSchema)
351- ]
352- & required .~ [ " runId" , " created" , " utcSchema" , " repoUrl"
353- , " commitDate" ," commitHash" , " runStatus" , " certificationPrice" ]
354-
355- instance ToJSON Run where
356- toJSON (Run {.. }) = object
357- [ " runId" .= runId
358- , " created" .= created
359- , " finishedAt" .= finishedAt
360- , " syncedAt" .= syncedAt
361- , " repoUrl" .= repoUrl
362- , " commitDate" .= commitDate
363- , " commitHash" .= commitHash
364- , " runStatus" .= runStatus
365- , " certificationPrice" .= certificationPrice
366- , " reportContentId" .= reportContentId
367- ]
368-
369- instance FromJSON Run where
370- parseJSON = withObject " Run" $ \ v -> Run
371- <$> v .: " runId"
372- <*> v .: " created"
373- <*> v .:? " finishedAt" .!= Nothing
374- <*> v .: " syncedAt"
375- <*> v .: " repoUrl"
376- <*> v .: " commitDate"
377- <*> v .: " commitHash"
378- <*> v .: " runStatus"
379- <*> pure def
380- <*> v .: " certificationPrice"
381- <*> v .:? " reportContentId" .!= Nothing
382-
383- instance SqlRow Run
384- instance IsLabel " profileId" (ID Profile -> Profile -> Profile ) where
385- fromLabel v p = p { profileId = v}
386-
387165--------------------------------------------------------------------------------
388166-- | Wallet transactions
389167
@@ -433,25 +211,6 @@ transactionEntries = table "entry"
433211 [ # txEntryId :- autoPrimary
434212 , # txEntryTxId :- foreignKey transactions # wtxId
435213 ]
436- runs :: Table Run
437- runs = table " run"
438- [ # runId :- primary
439- , # profileId :- foreignKey profiles # profileId
440- , # created :- index
441- ]
442-
443- certifications :: Table Certification
444- certifications = table " certification"
445- [ # certId :- primary
446- ]
447-
448- l1Certifications :: Table L1Certification
449- l1Certifications = table " certification"
450- [ # l1CertRunId :- primary
451- , # l1CertRunId :- foreignKey runs # runId
452- , # l1CertId :- foreignKey certifications # certId
453- ]
454-
455214dapps :: Table DApp
456215dapps = table " dapp"
457216 [ # dappId :- unique
@@ -461,6 +220,7 @@ dapps = table "dapp"
461220createTables :: MonadSelda m => m ()
462221createTables = do
463222 createTable certifications
223+ createTable onChainCertifications
464224 createTable profiles
465225 createTable dapps
466226 createTable runs
0 commit comments