feat: search

This commit is contained in:
2026-04-23 16:57:51 +02:00
parent b6255122a9
commit 5d16a89d1c
4 changed files with 659 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ defmodule BDS.Posts do
alias BDS.Posts.Post
alias BDS.Projects
alias BDS.Repo
alias BDS.Search
alias BDS.Slug
def create_post(attrs) do
@@ -42,6 +43,14 @@ defmodule BDS.Posts do
published_excerpt: nil
})
|> Repo.insert()
|> case do
{:ok, post} ->
:ok = Search.sync_post(post)
{:ok, post}
error ->
error
end
end
def update_post(post_id, attrs) do
@@ -61,6 +70,14 @@ defmodule BDS.Posts do
post
|> Post.changeset(updates)
|> Repo.update()
|> case do
{:ok, updated_post} ->
:ok = Search.sync_post(updated_post)
{:ok, updated_post}
error ->
error
end
else
{:error, changeset} -> {:error, changeset}
end
@@ -92,6 +109,14 @@ defmodule BDS.Posts do
updated_at: updated_at
})
|> Repo.update()
|> case do
{:ok, updated_post} ->
:ok = Search.sync_post(updated_post)
{:ok, updated_post}
error ->
error
end
end
end
@@ -116,6 +141,7 @@ defmodule BDS.Posts do
%Post{} = post ->
delete_post_file(post)
Repo.delete!(post)
:ok = Search.delete_post(post.id)
{:ok, :deleted}
end
end
@@ -129,6 +155,14 @@ defmodule BDS.Posts do
post
|> Post.changeset(%{status: :archived, updated_at: System.system_time(:second)})
|> Repo.update()
|> case do
{:ok, updated_post} ->
:ok = Search.sync_post(updated_post)
{:ok, updated_post}
error ->
error
end
%Post{} = post ->
{:error,
@@ -345,6 +379,7 @@ defmodule BDS.Posts do
post
|> Post.changeset(attrs)
|> Repo.insert_or_update!()
|> tap(&Search.sync_post/1)
end
defp parse_post_status(status) when is_atom(status), do: status