Skip to content

Commit

Permalink
More copy from AI
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Jul 24, 2024
1 parent 0469291 commit a6bb37c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
3 changes: 0 additions & 3 deletions Application/Helper/Elasticsearch.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Application.Helper.Elasticsearch where

import IHP.Prelude
Expand Down
4 changes: 3 additions & 1 deletion Application/Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions Web/Controller/News.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,33 +12,35 @@ 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
|> ifValid \case
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

Expand All @@ -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"]
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};
};
Expand Down

0 comments on commit a6bb37c

Please sign in to comment.