File tree Expand file tree Collapse file tree 4 files changed +11
-1
lines changed Expand file tree Collapse file tree 4 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -34,4 +34,5 @@ defmodule Reddit.Category.Community do
34
34
defp clean_name ( name ) do
35
35
name |> String . split |> Enum . join
36
36
end
37
+
37
38
end
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ defmodule Reddit.Users.User do
5
5
extensions: [ PowResetPassword ]
6
6
7
7
import Ecto.Changeset
8
+ import Ecto.Query , only: [ from: 2 ]
8
9
9
10
alias Reddit.Users.User
10
11
alias Reddit.Repo
@@ -41,4 +42,9 @@ defmodule Reddit.Users.User do
41
42
def profile ( param ) do
42
43
Repo . get_by ( User , username: param )
43
44
end
45
+
46
+ def karma_update ( user_id , k ) do
47
+ from ( u in User , update: [ inc: [ karma: ^ k ] ] , where: u . id == ^ user_id )
48
+ |> Repo . update_all ( [ ] )
49
+ end
44
50
end
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ defmodule RedditWeb.CommunityController do
3
3
4
4
alias Reddit.Category
5
5
alias Reddit.Category.Community
6
+ alias Reddit.Users.User
6
7
7
8
def index ( conn , _params ) do
8
9
communities = Category . list_communities ( )
@@ -20,6 +21,8 @@ defmodule RedditWeb.CommunityController do
20
21
21
22
case Category . create_community ( conn . assigns . current_user , community ) do
22
23
{ :ok , community } ->
24
+ User . karma_update ( conn . assigns . current_user . id , 1 )
25
+
23
26
conn
24
27
|> put_flash ( :info , "Community created successfully." )
25
28
|> redirect ( to: Routes . community_path ( conn , :show , community . name ) )
Original file line number Diff line number Diff line change 30
30
</ div >
31
31
32
32
< div class = "karma float-left mt-2 mr-2 " >
33
- 0
33
+ <%= @ current_user . karma %>
34
34
< span class = "fa fa-star text-warning " > </ span >
35
35
</ div >
36
36
<% else %>
You can’t perform that action at this time.
0 commit comments