Skip to content

Commit

Permalink
Merge pull request #6 from chrisdedman/notebook-update
Browse files Browse the repository at this point in the history
Update and Delete a Notebook
  • Loading branch information
PenguinBoi12 authored Aug 4, 2023
2 parents a757b86 + 0205253 commit 4010ad9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
20 changes: 20 additions & 0 deletions lib/cursif_web/resolvers/notebooks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ defmodule CursifWeb.Resolvers.Notebooks do
end
end

@spec update_notebook(map(), map()) :: {:ok, Notebook.t()} | {:error, atom()}
def update_notebook(%{id: id} = args, _context) do
notebook = Notebooks.get_notebook!(id)

case Notebooks.update_notebook(notebook, args) do
{:ok, notebook} -> {:ok, notebook}
{:error, changeset} -> {:error, changeset}
end
end

@spec delete_notebook(map(), map()) :: {:ok, Notebook.t()} | {:error, atom()}
def delete_notebook(%{id: id}, _context) do
notebook = Notebooks.get_notebook!(id)

case Notebooks.delete_notebook(notebook) do
{:ok, notebook} -> {:ok, notebook}
{:error, changeset} -> {:error, changeset}
end
end

# @spec get_owner(map(), map(), map()) :: {:ok, User.t()}
def get_owner(notebook, _args, _context) do
{:ok, Notebooks.get_owner!(notebook)}
Expand Down
35 changes: 27 additions & 8 deletions lib/cursif_web/schema/notebook_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@ defmodule CursifWeb.Schema.NotebookTypes do
field :owner_type, :string
field :pages, list_of(:page)
field :collaborators, list_of(:partial_user)
field :macros, list_of(:macro)

field :owner, :owner do
resolve(&Notebooks.get_owner/3)
end
end

@desc "Macro representation"
object :macro do
field :id, :id
field :title, :string
field :pattern, :string
field :code, :string
end

union :owner do
types([:partial_user])

Expand All @@ -37,6 +30,14 @@ defmodule CursifWeb.Schema.NotebookTypes do
end
end

@desc "Macro representation"
object :macro do
field :id, :id
field :title, :string
field :pattern, :string
field :code, :string
end

@desc "Notebook queries"
object :notebook_queries do
@desc "Get the list of notebooks"
Expand Down Expand Up @@ -74,6 +75,24 @@ defmodule CursifWeb.Schema.NotebookTypes do
resolve(&Notebooks.create_notebook/2)
end

@desc "Update a notebook"
field :update_notebook, :notebook do
arg(:id, non_null(:id))
arg(:title, :string)
arg(:description, :string)
arg(:owner_id, :id)
arg(:owner_type, :string)

resolve(&Notebooks.update_notebook/2)
end

@desc "Delete an notebook"
field :delete_notebook, :notebook do
arg(:id, non_null(:id))

resolve(&Notebooks.delete_notebook/2)
end

@desc "Create a macro"
field :create_macro, :macro do
arg(:title, non_null(:string))
Expand Down

0 comments on commit 4010ad9

Please sign in to comment.