Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to delete a page #25

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/cursif_web/resolvers/pages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ defmodule CursifWeb.Resolvers.Pages do
end
end

@spec delete_page(map(), map()) :: {:ok, Page.t()} | {:error, atom()}
def delete_page(%{id: id}, %{context: %{current_user: current_user}}) do
page = Pages.get_page!(id)

case Pages.delete_page(page) do
{:ok, page} -> {:ok, page}
{:error, changeset} -> {:error, changeset}
end
end

# Perhaps it should be defined in the context rather than here
@spec get_parent(map(), map()) :: {:ok, Page.t()} | {:error, atom()}
def get_parent(%{parent_id: parent_id, parent_type: "page"}, _context) do
Expand Down
10 changes: 10 additions & 0 deletions lib/cursif_web/schemas/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule CursifWeb.Schemas.Page do

@desc "Collection of mutations"
object :page_mutations do

@desc "Create a page"
field :create_page, :page do
arg(:title, non_null(:string))
arg(:content, :string)
Expand All @@ -25,6 +27,7 @@ defmodule CursifWeb.Schemas.Page do
resolve(&Pages.create_page/2)
end

@desc "Update a page"
field :update_page, :page do
arg(:id, non_null(:id))
arg(:title, :string)
Expand All @@ -34,5 +37,12 @@ defmodule CursifWeb.Schemas.Page do

resolve(&Pages.update_page/2)
end

@desc "Delete a page"
field :delete_page, :page do
arg(:id, non_null(:id))

resolve(&Pages.delete_page/2)
end
end
end
Loading