diff --git a/lib/mindwendel/ideas.ex b/lib/mindwendel/ideas.ex index d581ee7e..5730f375 100644 --- a/lib/mindwendel/ideas.ex +++ b/lib/mindwendel/ideas.ex @@ -389,7 +389,15 @@ defmodule Mindwendel.Ideas do """ def decrement_comment_count(idea_id) do idea = Repo.get!(Idea, idea_id) - changeset = Idea.changeset(idea, %{comments_count: idea.comments_count - 1}) + + new_comments_count = + if idea.comments_count - 1 >= 0 do + idea.comments_count - 1 + else + 0 + end + + changeset = Idea.changeset(idea, %{comments_count: new_comments_count}) Repo.update(changeset) end diff --git a/lib/mindwendel_web/live/lane_live/index_component.html.heex b/lib/mindwendel_web/live/lane_live/index_component.html.heex index aca3f900..7c3b4231 100644 --- a/lib/mindwendel_web/live/lane_live/index_component.html.heex +++ b/lib/mindwendel_web/live/lane_live/index_component.html.heex @@ -175,36 +175,16 @@