Skip to content

Commit

Permalink
feat(profile): decrement post count db function for user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsey committed Jun 25, 2024
1 parent 80a83ad commit 62bd1fe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/epochtalk_server/models/profile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ defmodule EpochtalkServer.Models.Profile do
Repo.update_all(query, inc: [post_count: 1])
end

@doc """
Decrements the `post_count` field given a `User` id
"""
@spec decrement_post_count(user_id :: non_neg_integer) :: {non_neg_integer(), nil}
def decrement_post_count(user_id) do
query = from p in Profile, where: p.user_id == ^user_id
Repo.update_all(query, inc: [post_count: -1])
end

@doc """
Creates `Profile` record for a specific `User`
"""
Expand Down

0 comments on commit 62bd1fe

Please sign in to comment.