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 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 #label_ |> fetch renderJson $ map wtToJson types action ApiV2ListEventTypesAction = do types <- query @EventTypeRegistry |> filterWhere (#status, "active") |> orderByAsc #label_ |> fetch renderJson $ map etToJson types action ApiV2ListAnnotationCategoriesAction = do cats <- query @AnnotationCategoryRegistry |> filterWhere (#status, "active") |> orderByAsc #label_ |> fetch renderJson $ map acToJson cats 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 ]