41 lines
1.4 KiB
Haskell
41 lines
1.4 KiB
Haskell
|
|
module Web.Controller.Api.V2.RequirementCandidates 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 ApiV2RequirementCandidatesController where
|
||
|
|
|
||
|
|
action ApiV2IndexRequirementCandidatesAction = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
(page, perPage) <- getPageParams
|
||
|
|
let off = (page - 1) * perPage
|
||
|
|
total <- query @RequirementCandidate |> fetchCount
|
||
|
|
rcs <- query @RequirementCandidate
|
||
|
|
|> orderByDesc #createdAt
|
||
|
|
|> limit perPage
|
||
|
|
|> offset off
|
||
|
|
|> fetch
|
||
|
|
renderJson $ paginatedResponse (map rcToJson rcs) page perPage total
|
||
|
|
|
||
|
|
action ApiV2ShowRequirementCandidateAction { requirementCandidateId } = do
|
||
|
|
_consumer <- requireApiConsumer
|
||
|
|
rc <- fetch requirementCandidateId
|
||
|
|
renderJson (rcToJson rc)
|
||
|
|
|
||
|
|
rcToJson :: RequirementCandidate -> Value
|
||
|
|
rcToJson rc = object
|
||
|
|
[ "id" .= rc.id
|
||
|
|
, "title" .= rc.title
|
||
|
|
, "description" .= rc.description
|
||
|
|
, "sourceWidgetId" .= rc.sourceWidgetId
|
||
|
|
, "sourceThreadId" .= rc.sourceThreadId
|
||
|
|
, "sourceAnnotationId" .= rc.sourceAnnotationId
|
||
|
|
, "category" .= rc.category
|
||
|
|
, "status" .= rc.status
|
||
|
|
, "createdAt" .= rc.createdAt
|
||
|
|
]
|