Skip to content

Commit

Permalink
feat(api): delete thread message by id
Browse files Browse the repository at this point in the history
  • Loading branch information
Irere123 committed Aug 19, 2024
1 parent 5e0d04f commit 42900cd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/lib/breeze/routes/v1/threads.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,21 @@ defmodule Breeze.Routes.V1.Threads do
|> send_resp(401, Jason.encode!(%{error: "UNAUTHORIZED"}))
end
end

delete "/delete-message" do
%Plug.Conn{params: %{"messageId" => message_id}} = conn

resp =
case Messages.delete_thread_message_by_id(message_id) do
{:ok, _} ->
%{success: true}

{:error, changeset_error} ->
error = Spek.Utils.Errors.changeset_to_first_err_message(changeset_error)
%{error: error, success: true}
end

conn
|> send_resp(200, Jason.encode!(resp))
end
end
1 change: 1 addition & 0 deletions api/lib/telescope/channels.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Telescope.Channels do

# MUTATIONS
defdelegate create_thread(data), to: Telescope.Mutations.Channels
defdelegate delete_thread_by_id(thread_id), to: Telescope.Mutations.Channels
defdelegate delete_channel(channel_id, user_id), to: Telescope.Mutations.Channels
defdelegate create_channel(data, user_id), to: Telescope.Mutations.Channels
defdelegate join_channel(channel_id, user_id), to: Telescope.Mutations.Channels
Expand Down
1 change: 1 addition & 0 deletions api/lib/telescope/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ defmodule Telescope.Messages do

# MUTATIONS
defdelegate create_thread_message(data), to: Telescope.Mutations.Messages
defdelegate delete_thread_message_by_id(message_id), to: Telescope.Mutations.Messages
end
4 changes: 4 additions & 0 deletions api/lib/telescope/mutations/channels.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ defmodule Telescope.Mutations.Channels do
|> Repo.insert!(returning: true)
|> Repo.preload(:creator)
end

def delete_thread_by_id(thread_id) do
%Thread{id: thread_id} |> Repo.delete()
end
end
4 changes: 4 additions & 0 deletions api/lib/telescope/mutations/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ defmodule Telescope.Mutations.Messages do
|> Repo.insert!(returning: true)
|> Repo.preload(:user)
end

def delete_thread_message_by_id(message_id) do
%Message{id: message_id} |> Repo.delete()
end
end
6 changes: 6 additions & 0 deletions api/lib/telescope/schemas/thread.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ defmodule Telescope.Schemas.Thread do
|> cast_embed(:peoplePreviewList)
|> validate_required([:channelId, :creatorId, :name, :peoplePreviewList])
end

def edit_changeset(thread, params \\ %{}) do
thread
|> cast(params, [:name])
|> validate_required([:name])
end
end

0 comments on commit 42900cd

Please sign in to comment.