diff --git a/Application/Helper/Elasticsearch.hs b/Application/Helper/Elasticsearch.hs index ea40206..e8fb41a 100644 --- a/Application/Helper/Elasticsearch.hs +++ b/Application/Helper/Elasticsearch.hs @@ -1,6 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} - module Application.Helper.Elasticsearch where import IHP.Prelude diff --git a/Application/Schema.sql b/Application/Schema.sql index 54f26c1..1b15722 100644 --- a/Application/Schema.sql +++ b/Application/Schema.sql @@ -39,7 +39,9 @@ CREATE TABLE paragraph_ctas ( CREATE INDEX paragraph_quotes_landing_page_id_index ON paragraph_quotes (landing_page_id); CREATE INDEX paragraph_ctas_landing_page_id_index ON paragraph_ctas (landing_page_id); CREATE TABLE news ( - id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL, + title TEXT NOT NULL, + body TEXT NOT NULL ); ALTER TABLE paragraph_ctas ADD CONSTRAINT paragraph_ctas_ref_landing_page_id FOREIGN KEY (landing_page_id) REFERENCES landing_pages (id) ON DELETE NO ACTION; ALTER TABLE paragraph_ctas ADD CONSTRAINT paragraph_ctas_ref_ref_landing_page_id FOREIGN KEY (ref_landing_page_id) REFERENCES landing_pages (id) ON DELETE NO ACTION; diff --git a/Web/Controller/News.hs b/Web/Controller/News.hs index 8509bfc..243ab9c 100644 --- a/Web/Controller/News.hs +++ b/Web/Controller/News.hs @@ -1,10 +1,7 @@ module Web.Controller.News where import Web.Controller.Prelude -import Web.View.News.Index -import Web.View.News.New -import Web.View.News.Edit -import Web.View.News.Show +import Application.Helper.Elasticsearch instance Controller NewsController where action NewsAction = do @@ -15,15 +12,15 @@ instance Controller NewsController where let news = newRecord render NewView { .. } - action ShowNewsAction { newsId } = do + action ShowNewsAction { .. } = do news <- fetch newsId render ShowView { .. } - action EditNewsAction { newsId } = do + action EditNewsAction { .. } = do news <- fetch newsId render EditView { .. } - action UpdateNewsAction { newsId } = do + action UpdateNewsAction { .. } = do news <- fetch newsId news |> buildNews @@ -31,17 +28,19 @@ instance Controller NewsController where Left news -> render EditView { .. } Right news -> do news <- news |> updateRecord + indexNews news -- Index updated news in Elasticsearch setSuccessMessage "News updated" - redirectTo EditNewsAction { .. } + redirectTo NewsAction action CreateNewsAction = do let news = newRecord @News news |> buildNews |> ifValid \case - Left news -> render NewView { .. } + Left news -> render NewView { .. } Right news -> do news <- news |> createRecord + indexNews news -- Index new news in Elasticsearch setSuccessMessage "News created" redirectTo NewsAction @@ -51,5 +50,10 @@ instance Controller NewsController where setSuccessMessage "News deleted" redirectTo NewsAction + action SearchNewsAction = do + query <- param @Text "query" + searchResults <- searchNewsHandler query + render SearchView { news = searchResults } + buildNews news = news - |> fill @'[] + |> fill @["title", "body"] \ No newline at end of file diff --git a/flake.nix b/flake.nix index 162c748..8e705f2 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,7 @@ }; # This is needed so when running tests in GitHub actions, we can execute `devenv up &` without an error. - process.implementation = "overmind"; + # process.implementation = "overmind"; }; }; };