generated from coulomb/repo-seed
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled
80 lines
2.2 KiB
Haskell
80 lines
2.2 KiB
Haskell
module Web.Controller.Api.V2.Registries where
|
|
|
|
-- Public (unauthenticated) endpoints that enumerate the registered vocabulary.
|
|
-- GET /api/v2/widget-types
|
|
-- GET /api/v2/event-types
|
|
-- GET /api/v2/annotation-categories
|
|
-- GET /api/v2/policy-scopes
|
|
|
|
import Web.Types
|
|
import Generated.Types
|
|
import IHP.Prelude
|
|
import IHP.ControllerPrelude
|
|
import Data.Aeson (object, (.=))
|
|
|
|
instance Controller ApiV2RegistriesController where
|
|
|
|
action ApiV2ListWidgetTypesAction = do
|
|
types <- query @WidgetTypeRegistry
|
|
|> filterWhere (#status, "active")
|
|
|> orderByAsc #name
|
|
|> fetch
|
|
renderJson $ map wtToJson types
|
|
|
|
action ApiV2ListEventTypesAction = do
|
|
types <- query @EventTypeRegistry
|
|
|> filterWhere (#status, "active")
|
|
|> orderByAsc #name
|
|
|> fetch
|
|
renderJson $ map etToJson types
|
|
|
|
action ApiV2ListAnnotationCategoriesAction = do
|
|
cats <- query @AnnotationCategoryRegistry
|
|
|> filterWhere (#status, "active")
|
|
|> orderByAsc #name
|
|
|> fetch
|
|
renderJson $ map acToJson cats
|
|
|
|
action ApiV2ListPolicyScopesAction = do
|
|
scopes <- query @PolicyScopeRegistry
|
|
|> filterWhere (#status, "active")
|
|
|> orderByAsc #name
|
|
|> fetch
|
|
renderJson $ map psToJson scopes
|
|
|
|
wtToJson :: WidgetTypeRegistry -> Value
|
|
wtToJson r = object
|
|
[ "name" .= r.name
|
|
, "label" .= r.label_
|
|
, "description" .= r.description
|
|
, "ownerHubId" .= r.ownerHubId
|
|
, "status" .= r.status
|
|
]
|
|
|
|
etToJson :: EventTypeRegistry -> Value
|
|
etToJson r = object
|
|
[ "name" .= r.name
|
|
, "label" .= r.label_
|
|
, "description" .= r.description
|
|
, "ownerHubId" .= r.ownerHubId
|
|
, "status" .= r.status
|
|
]
|
|
|
|
acToJson :: AnnotationCategoryRegistry -> Value
|
|
acToJson r = object
|
|
[ "name" .= r.name
|
|
, "label" .= r.label_
|
|
, "description" .= r.description
|
|
, "ownerHubId" .= r.ownerHubId
|
|
, "status" .= r.status
|
|
]
|
|
|
|
psToJson :: PolicyScopeRegistry -> Value
|
|
psToJson r = object
|
|
[ "name" .= r.name
|
|
, "label" .= r.label_
|
|
, "description" .= r.description
|
|
, "ownerHubId" .= r.ownerHubId
|
|
, "status" .= r.status
|
|
]
|