39 lines
1.3 KiB
Haskell
39 lines
1.3 KiB
Haskell
|
|
module Web.Controller.Api.V2.DeploymentRecords where
|
||
|
|
|
||
|
|
import Web.Types
|
||
|
|
import Generated.Types
|
||
|
|
import IHP.Prelude
|
||
|
|
import IHP.ControllerPrelude
|
||
|
|
import Data.Aeson (object, (.=))
|
||
|
|
import Web.Controller.Api.V2.Auth (requireApiConsumer, paginatedResponse, getPageParams)
|
||
|
|
|
||
|
|
instance Controller ApiV2DeploymentRecordsController where
|
||
|
|
|
||
|
|
action ApiV2IndexDeploymentRecordsAction = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
(page, perPage) <- getPageParams
|
||
|
|
let off = (page - 1) * perPage
|
||
|
|
total <- query @DeploymentRecord |> fetchCount
|
||
|
|
drs <- query @DeploymentRecord
|
||
|
|
|> orderByDesc #deployedAt
|
||
|
|
|> limit perPage
|
||
|
|
|> offset off
|
||
|
|
|> fetch
|
||
|
|
renderJson $ paginatedResponse (map depToJson drs) page perPage total
|
||
|
|
|
||
|
|
action ApiV2ShowDeploymentRecordAction { deploymentRecordId } = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
dr <- fetch deploymentRecordId
|
||
|
|
renderJson (depToJson dr)
|
||
|
|
|
||
|
|
depToJson :: DeploymentRecord -> Value
|
||
|
|
depToJson dr = object
|
||
|
|
[ "id" .= dr.id
|
||
|
|
, "implRefId" .= dr.implRefId
|
||
|
|
, "decisionId" .= dr.decisionId
|
||
|
|
, "versionRef" .= dr.versionRef
|
||
|
|
, "deployedAt" .= dr.deployedAt
|
||
|
|
, "notes" .= dr.notes
|
||
|
|
, "createdAt" .= dr.createdAt
|
||
|
|
]
|