@@ -12,35 +12,43 @@ defmodule GroupherServer.Statistics.Delegate.Contribute do
1212 @ community_contribute_days get_config ( :general , :community_contribute_days )
1313 @ user_contribute_months get_config ( :general , :user_contribute_months )
1414
15+ @ doc """
16+ update community's contributes record
17+ """
1518 def make_contribute ( % Community { id: id } ) do
1619 today = Timex . today ( ) |> Date . to_iso8601 ( )
1720
18- with { :ok , contribute } <- ORM . find_by ( CommunityContribute , community_id: id , date: today ) do
19- contribute |> inc_contribute_count ( :community ) |> done
20- else
21+ case ORM . find_by ( CommunityContribute , community_id: id , date: today ) do
22+ { :ok , contribute } ->
23+ contribute |> inc_contribute_count ( :community ) |> done
24+
2125 { :error , _ } ->
2226 CommunityContribute |> ORM . create ( % { community_id: id , date: today , count: 1 } )
2327 end
2428 end
2529
30+ @ doc """
31+ update user's contributes record
32+ """
2633 def make_contribute ( % User { id: id } ) do
2734 today = Timex . today ( ) |> Date . to_iso8601 ( )
2835
29- with { :ok , contribute } <- ORM . find_by ( UserContribute , user_id: id , date: today ) do
30- contribute |> inc_contribute_count ( :user ) |> done
31- else
36+ case ORM . find_by ( UserContribute , user_id: id , date: today ) do
37+ { :ok , contribute } ->
38+ contribute |> inc_contribute_count ( :user ) |> done
39+
3240 { :error , _ } ->
3341 UserContribute |> ORM . create ( % { user_id: id , date: today , count: 1 } )
3442 end
3543 end
3644
3745 @ doc """
38- Returns the list of user_contribute by latest 6 months .
46+ Returns the list of user_contribute by latest 6 days .
3947 """
40- def list_contributes ( % User { id: id } ) do
48+ def list_contributes_digest ( % User { id: id } ) do
4149 user_id = integerfy ( id )
4250
43- "user_contributes"
51+ UserContribute
4452 |> where ( [ c ] , c . user_id == ^ user_id )
4553 |> QueryBuilder . recent_inserted ( months: @ user_contribute_months )
4654 |> select ( [ c ] , % { date: c . date , count: c . count } )
@@ -49,13 +57,9 @@ defmodule GroupherServer.Statistics.Delegate.Contribute do
4957 |> done
5058 end
5159
52- def list_contributes ( % Community { id: id } ) do
53- % Community { id: id }
54- |> get_contributes ( )
55- |> to_counts_digest ( days: @ community_contribute_days )
56- |> done
57- end
58-
60+ @ doc """
61+ Returns the list of community_contribute by latest 6 days.
62+ """
5963 def list_contributes_digest ( % Community { id: id } ) do
6064 % Community { id: id }
6165 |> get_contributes ( )
@@ -66,7 +70,7 @@ defmodule GroupherServer.Statistics.Delegate.Contribute do
6670 defp get_contributes ( % Community { id: id } ) do
6771 community_id = integerfy ( id )
6872
69- "community_contributes"
73+ CommunityContribute
7074 |> where ( [ c ] , c . community_id == ^ community_id )
7175 |> QueryBuilder . recent_inserted ( days: @ community_contribute_days )
7276 |> select ( [ c ] , % { date: c . date , count: c . count } )
0 commit comments