41 lines
1.3 KiB
Haskell
41 lines
1.3 KiB
Haskell
|
|
module Web.Controller.Api.V2.DecisionRecords 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 ApiV2DecisionRecordsController where
|
||
|
|
|
||
|
|
action ApiV2IndexDecisionRecordsAction = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
(page, perPage) <- getPageParams
|
||
|
|
let off = (page - 1) * perPage
|
||
|
|
total <- query @DecisionRecord |> fetchCount
|
||
|
|
drs <- query @DecisionRecord
|
||
|
|
|> orderByDesc #createdAt
|
||
|
|
|> limit perPage
|
||
|
|
|> offset off
|
||
|
|
|> fetch
|
||
|
|
renderJson $ paginatedResponse (map drToJson drs) page perPage total
|
||
|
|
|
||
|
|
action ApiV2ShowDecisionRecordAction { decisionRecordId } = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
dr <- fetch decisionRecordId
|
||
|
|
renderJson (drToJson dr)
|
||
|
|
|
||
|
|
drToJson :: DecisionRecord -> Value
|
||
|
|
drToJson dr = object
|
||
|
|
[ "id" .= dr.id
|
||
|
|
, "title" .= dr.title
|
||
|
|
, "rationale" .= dr.rationale
|
||
|
|
, "outcome" .= dr.outcome
|
||
|
|
, "requirementId" .= dr.requirementId
|
||
|
|
, "candidateId" .= dr.candidateId
|
||
|
|
, "decidedAt" .= dr.decidedAt
|
||
|
|
, "notes" .= dr.notes
|
||
|
|
, "createdAt" .= dr.createdAt
|
||
|
|
]
|