50 lines
1.9 KiB
Haskell
50 lines
1.9 KiB
Haskell
|
|
module Web.Controller.InstitutionalKnowledge where
|
||
|
|
|
||
|
|
-- IHF Phase 12 — Platform Memory (IHUB-WP-0013 T05)
|
||
|
|
|
||
|
|
import Web.Controller.Prelude
|
||
|
|
import Web.View.InstitutionalKnowledge.Index
|
||
|
|
import Web.View.InstitutionalKnowledge.Show
|
||
|
|
import IHP.ModelSupport (sqlQuery)
|
||
|
|
|
||
|
|
instance Controller InstitutionalKnowledgeController where
|
||
|
|
beforeAction = ensureIsUser
|
||
|
|
|
||
|
|
action InstitutionalKnowledgeAction = do
|
||
|
|
entries <- query @InstitutionalKnowledgeEntry
|
||
|
|
|> orderByDesc #createdAt
|
||
|
|
|> limit 50
|
||
|
|
|> fetch
|
||
|
|
hubs <- query @Hub |> fetch
|
||
|
|
render IndexView { entries, hubs, mQuery = Nothing }
|
||
|
|
|
||
|
|
action ShowInstitutionalKnowledgeAction { knowledgeEntryId } = do
|
||
|
|
entry <- fetch knowledgeEntryId
|
||
|
|
hub <- fetch entry.hubId
|
||
|
|
mDecision <- case entry.decisionRecordId of
|
||
|
|
Nothing -> pure Nothing
|
||
|
|
Just did -> fetchOneOrNothing did
|
||
|
|
render ShowView { entry, hub, mDecision }
|
||
|
|
|
||
|
|
action QueryKnowledgeBaseAction = do
|
||
|
|
q <- param @Text "q"
|
||
|
|
mHubStr <- paramOrNothing @Text "hubId"
|
||
|
|
hubs <- query @Hub |> fetch
|
||
|
|
entries <- case mHubStr of
|
||
|
|
Nothing ->
|
||
|
|
sqlQuery
|
||
|
|
"SELECT * FROM institutional_knowledge_entries \
|
||
|
|
\ WHERE summary_tsv @@ plainto_tsquery('english', ?) \
|
||
|
|
\ ORDER BY ts_rank(summary_tsv, plainto_tsquery('english', ?)) DESC \
|
||
|
|
\ LIMIT 20"
|
||
|
|
(q, q)
|
||
|
|
Just hid ->
|
||
|
|
sqlQuery
|
||
|
|
"SELECT * FROM institutional_knowledge_entries \
|
||
|
|
\ WHERE hub_id = ? \
|
||
|
|
\ AND summary_tsv @@ plainto_tsquery('english', ?) \
|
||
|
|
\ ORDER BY ts_rank(summary_tsv, plainto_tsquery('english', ?)) DESC \
|
||
|
|
\ LIMIT 20"
|
||
|
|
(hid, q, q)
|
||
|
|
render IndexView { entries, hubs, mQuery = Just q }
|