Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2c98a57

Browse files
committed
Merge branch 'phoenix-1.4' into dev
2 parents df9aa68 + f732033 commit 2c98a57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+241
-238
lines changed

config/config.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ config :logger, :console,
2020
format: "$time $metadata[$level] $message\n",
2121
metadata: [:request_id]
2222

23-
config :phoenix, :format_encoders, json: Jason
24-
config :ecto, json_library: Jason
23+
config :phoenix, :json_library, Jason
2524

2625
# TODO move this config to secret later
2726
config :mastani_server, Helper.Guardian,

lib/helper/orm.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ defmodule Helper.ORM do
8787
defp inc_views_count(content, queryable) do
8888
{1, [result]} =
8989
Repo.update_all(
90-
from(p in queryable, where: p.id == ^content.id),
91-
[inc: [views: 1]],
92-
returning: [:views]
90+
from(p in queryable, where: p.id == ^content.id, select: p.views),
91+
inc: [views: 1]
9392
)
9493

95-
put_in(content.views, result.views)
94+
put_in(content.views, result)
9695
end
9796

9897
@doc """

lib/helper/radar_search.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule Helper.RadarSearch do
4848
end
4949

5050
# not valid io, just ignore it
51-
def locate_city(_ip), do: {:error, "invalid ip"}
51+
# def locate_city(_ip), do: {:error, "invalid ip"}
5252

5353
defp handle_result({:ok, result}) do
5454
case result do

lib/mastani_server/accounts/delegates/achievements.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ defmodule MastaniServer.Accounts.Delegate.Achievements do
121121
end
122122
end
123123

124-
@spec safe_minus(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
125-
defp safe_minus(count, unit) when is_integer(count) and is_integer(unit) and unit > 0 do
126-
case count <= 0 do
127-
true ->
128-
0
129-
130-
false ->
131-
count - unit
132-
end
133-
end
124+
# @spec safe_minus(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
125+
# defp safe_minus(count, unit) when is_integer(count) and is_integer(unit) and unit > 0 do
126+
# case count <= 0 do
127+
# true ->
128+
# 0
129+
130+
# false ->
131+
# count - unit
132+
# end
133+
# end
134134

135135
@doc """
136136
list communities which the user is editor in it

lib/mastani_server/accounts/delegates/fans.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defmodule MastaniServer.Accounts.Delegate.Fans do
3131
:create_following,
3232
UserFollowing.changeset(%UserFollowing{}, %{user_id: user_id, following_id: follower_id})
3333
)
34-
|> Multi.run(:add_achievement, fn _ ->
34+
|> Multi.run(:add_achievement, fn _, _ ->
3535
Accounts.achieve(%User{id: follower_id}, :add, :follow)
3636
end)
3737
|> Repo.transaction()
@@ -70,13 +70,13 @@ defmodule MastaniServer.Accounts.Delegate.Fans do
7070
with true <- to_string(user_id) !== to_string(follower_id),
7171
{:ok, _follow_user} <- ORM.find(User, follower_id) do
7272
Multi.new()
73-
|> Multi.run(:delete_follower, fn _ ->
73+
|> Multi.run(:delete_follower, fn _, _ ->
7474
ORM.findby_delete(UserFollower, %{user_id: follower_id, follower_id: user_id})
7575
end)
76-
|> Multi.run(:delete_following, fn _ ->
76+
|> Multi.run(:delete_following, fn _, _ ->
7777
ORM.findby_delete(UserFollowing, %{user_id: user_id, following_id: follower_id})
7878
end)
79-
|> Multi.run(:minus_achievement, fn _ ->
79+
|> Multi.run(:minus_achievement, fn _, _ ->
8080
Accounts.achieve(%User{id: follower_id}, :minus, :follow)
8181
end)
8282
|> Repo.transaction()

lib/mastani_server/accounts/delegates/favorite_category.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
4040
def delete_favorite_category(%User{id: user_id}, id) do
4141
with {:ok, category} <- FavoriteCategory |> ORM.find_by(~m(id user_id)a) do
4242
Multi.new()
43-
|> Multi.run(:downgrade_achievement, fn _ ->
43+
|> Multi.run(:downgrade_achievement, fn _, _ ->
4444
# find user favvoried-contents(posts & jobs & videos) 's author,
4545
# and downgrade their's acieveents
4646
# NOTE: this is too fucking violent and should be refactor later
@@ -67,7 +67,7 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
6767

6868
{:ok, %{done: true}}
6969
end)
70-
|> Multi.run(:delete_category, fn _ ->
70+
|> Multi.run(:delete_category, fn _, _ ->
7171
category |> ORM.delete()
7272
end)
7373
|> Repo.transaction()
@@ -138,7 +138,7 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
138138
with {:ok, favorite_category} <-
139139
FavoriteCategory |> ORM.find_by(%{user_id: user.id, id: category_id}) do
140140
Multi.new()
141-
|> Multi.run(:favorite_content, fn _ ->
141+
|> Multi.run(:favorite_content, fn _, _ ->
142142
with {:ok, content_favorite} <- find_content_favorite(thread, content_id, user.id) do
143143
check_dup_category(content_favorite, favorite_category)
144144
else
@@ -149,7 +149,7 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
149149
end
150150
end
151151
end)
152-
|> Multi.run(:dec_old_category_count, fn %{favorite_content: content_favorite} ->
152+
|> Multi.run(:dec_old_category_count, fn _, %{favorite_content: content_favorite} ->
153153
with false <- is_nil(content_favorite.category_id),
154154
{:ok, old_category} <- FavoriteCategory |> ORM.find(content_favorite.category_id) do
155155
old_category
@@ -159,10 +159,10 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
159159
error -> {:error, error}
160160
end
161161
end)
162-
|> Multi.run(:update_content_category_id, fn %{favorite_content: content_favorite} ->
162+
|> Multi.run(:update_content_category_id, fn _, %{favorite_content: content_favorite} ->
163163
content_favorite |> ORM.update(%{category_id: favorite_category.id})
164164
end)
165-
|> Multi.run(:update_category_info, fn _ ->
165+
|> Multi.run(:update_category_info, fn _, _ ->
166166
last_updated = Timex.today() |> Timex.to_datetime()
167167

168168
favorite_category
@@ -199,10 +199,10 @@ defmodule MastaniServer.Accounts.Delegate.FavoriteCategory do
199199
with {:ok, favorite_category} <-
200200
FavoriteCategory |> ORM.find_by(%{user_id: user.id, id: category_id}) do
201201
Multi.new()
202-
|> Multi.run(:undo_favorite_action, fn _ ->
202+
|> Multi.run(:undo_favorite_action, fn _, _ ->
203203
CMS.undo_reaction(thread, :favorite, content_id, user)
204204
end)
205-
|> Multi.run(:update_category_info, fn _ ->
205+
|> Multi.run(:update_category_info, fn _, _ ->
206206
last_updated = Timex.today() |> Timex.to_datetime()
207207

208208
favorite_category

lib/mastani_server/accounts/delegates/mails.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule MastaniServer.Accounts.Delegate.Mails do
1313
def fetch_mentions(%User{} = user, filter) do
1414
with {:ok, mentions} <- Delivery.fetch_mentions(user, filter),
1515
{:ok, washed_mentions} <- wash_data(MentionMail, mentions.entries) do
16-
result = MentionMail |> Repo.insert_all(washed_mentions)
16+
MentionMail |> Repo.insert_all(washed_mentions)
1717
MentionMail |> messages_fetcher(washed_mentions, user, filter)
1818
end
1919
end
@@ -43,7 +43,7 @@ defmodule MastaniServer.Accounts.Delegate.Mails do
4343
end
4444
end
4545

46-
defp messages_fetcher(queryable, washed_data, %User{id: user_id}, %{
46+
defp messages_fetcher(queryable, _washed_data, %User{id: user_id}, %{
4747
page: page,
4848
size: size,
4949
read: read

lib/mastani_server/accounts/delegates/profile.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ defmodule MastaniServer.Accounts.Delegate.Profile do
126126

127127
defp register_github_user(github_profile) do
128128
Multi.new()
129-
|> Multi.run(:create_user, fn _ ->
129+
|> Multi.run(:create_user, fn _, _ ->
130130
create_user(github_profile, :github)
131131
end)
132-
|> Multi.run(:create_profile, fn %{create_user: user} ->
132+
|> Multi.run(:create_profile, fn _, %{create_user: user} ->
133133
create_profile(user, github_profile, :github)
134134
end)
135-
|> Multi.run(:init_achievement, fn %{create_user: user} ->
135+
|> Multi.run(:init_achievement, fn _, %{create_user: user} ->
136136
Achievement |> ORM.upsert_by([user_id: user.id], %{user_id: user.id})
137137
end)
138138
|> Repo.transaction()

lib/mastani_server/cms/delegates/article_curd.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
6868
{:ok, action} <- match_action(thread, :community),
6969
{:ok, community} <- ORM.find(Community, community_id) do
7070
Multi.new()
71-
|> Multi.run(:add_content_author, fn _ ->
71+
|> Multi.run(:add_content_author, fn _, _ ->
7272
action.target
7373
|> struct()
7474
|> action.target.changeset(attrs)
7575
|> Ecto.Changeset.put_change(:author_id, author.id)
7676
|> Repo.insert()
7777
end)
78-
|> Multi.run(:set_community, fn %{add_content_author: content} ->
78+
|> Multi.run(:set_community, fn _, %{add_content_author: content} ->
7979
ArticleOperation.set_community(community, thread, content.id)
8080
end)
81-
|> Multi.run(:set_topic, fn %{add_content_author: content} ->
81+
|> Multi.run(:set_topic, fn _, %{add_content_author: content} ->
8282
topic_title =
8383
case attrs |> Map.has_key?(:topic) do
8484
true -> attrs.topic
@@ -87,7 +87,7 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
8787

8888
ArticleOperation.set_topic(%Topic{title: topic_title}, thread, content.id)
8989
end)
90-
|> Multi.run(:set_community_flag, fn %{add_content_author: content} ->
90+
|> Multi.run(:set_community_flag, fn _, %{add_content_author: content} ->
9191
# TODO: remove this judge, as content should have a flag
9292
case action |> Map.has_key?(:flag) do
9393
true ->
@@ -99,17 +99,17 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
9999
{:ok, "pass"}
100100
end
101101
end)
102-
|> Multi.run(:set_tag, fn %{add_content_author: content} ->
102+
|> Multi.run(:set_tag, fn _, %{add_content_author: content} ->
103103
case attrs |> Map.has_key?(:tags) do
104104
true -> set_tags(community, thread, content.id, attrs.tags)
105105
false -> {:ok, "pass"}
106106
end
107107
end)
108-
|> Multi.run(:mention_users, fn %{add_content_author: content} ->
108+
|> Multi.run(:mention_users, fn _, %{add_content_author: content} ->
109109
Delivery.mention_from_content(thread, content, attrs, %User{id: user_id})
110110
{:ok, "pass"}
111111
end)
112-
|> Multi.run(:log_action, fn _ ->
112+
|> Multi.run(:log_action, fn _, _ ->
113113
Statistics.log_publish_action(%User{id: user_id})
114114
end)
115115
|> Repo.transaction()
@@ -132,7 +132,7 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
132132
{:error, [message: "set community flag", code: ecode(:create_fails)]}
133133
end
134134

135-
defp create_content_result({:error, :set_topic, result, _steps}) do
135+
defp create_content_result({:error, :set_topic, _result, _steps}) do
136136
{:error, [message: "set topic", code: ecode(:create_fails)]}
137137
end
138138

@@ -227,7 +227,7 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
227227
|> join(:inner, [p], content in assoc(p, :post))
228228
|> where(
229229
[p, c, t, content],
230-
c.raw == ^filter.community and t.raw == ^Map.get(filter, :topic, "posts")
230+
c.raw == ^community and t.raw == ^Map.get(filter, :topic, "posts")
231231
)
232232
|> select([p, c, t, content], content)
233233
# 10 pined contents per community/thread, at most
@@ -241,19 +241,21 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
241241
end
242242
end
243243

244-
defp add_pin_contents_ifneed(contents, CMS.Job, %{community: community} = filter) do
244+
defp add_pin_contents_ifneed(contents, CMS.Job, %{community: _community} = filter) do
245245
merge_pin_contents(contents, :job, CMS.PinedJob, filter)
246246
end
247247

248-
defp add_pin_contents_ifneed(contents, CMS.Video, %{community: community} = filter) do
248+
defp add_pin_contents_ifneed(contents, CMS.Video, %{community: _community} = filter) do
249249
merge_pin_contents(contents, :video, CMS.PinedVideo, filter)
250250
end
251251

252-
defp add_pin_contents_ifneed(contents, CMS.Repo, %{community: community} = filter) do
252+
defp add_pin_contents_ifneed(contents, CMS.Repo, %{community: _community} = filter) do
253253
merge_pin_contents(contents, :repo, CMS.PinedRepo, filter)
254254
end
255255

256-
defp merge_pin_contents(contents, thread, pin_schema, %{community: community} = filter) do
256+
defp add_pin_contents_ifneed(contents, _querable, _filter), do: contents
257+
258+
defp merge_pin_contents(contents, thread, pin_schema, %{community: _community} = filter) do
257259
with {:ok, normal_contents} <- contents,
258260
true <- Map.has_key?(filter, :community),
259261
true <- 1 == Map.get(normal_contents, :page_number) do
@@ -274,8 +276,6 @@ defmodule MastaniServer.CMS.Delegate.ArticleCURD do
274276
end
275277
end
276278

277-
defp add_pin_contents_ifneed(contents, _querable, _filter), do: contents
278-
279279
defp concat_contents(pined_content, normal_contents) do
280280
case pined_content |> Map.get(:total_count) do
281281
0 ->

lib/mastani_server/cms/delegates/article_operation.ex

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
4141
end
4242
end
4343

44-
def undo_pin_content(%Post{id: post_id}, %Community{id: community_id}, topic) do
45-
with {:ok, %{id: topic_id}} <- ORM.find_by(Topic, %{raw: topic}),
46-
{:ok, pined} <- ORM.find_by(PinedPost, ~m(post_id community_id topic_id)a),
47-
{:ok, deleted} <- ORM.delete(pined) do
48-
Post |> ORM.find(deleted.post_id)
49-
end
50-
end
51-
5244
def pin_content(%Job{id: job_id}, %Community{id: community_id}) do
5345
attrs = ~m(job_id community_id)a
5446

@@ -57,13 +49,6 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
5749
end
5850
end
5951

60-
def undo_pin_content(%Job{id: job_id}, %Community{id: community_id}) do
61-
with {:ok, pined} <- ORM.find_by(PinedJob, ~m(job_id community_id)a),
62-
{:ok, deleted} <- ORM.delete(pined) do
63-
Job |> ORM.find(deleted.job_id)
64-
end
65-
end
66-
6752
def pin_content(%Video{id: video_id}, %Community{id: community_id}) do
6853
attrs = ~m(video_id community_id)a
6954

@@ -72,13 +57,6 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
7257
end
7358
end
7459

75-
def undo_pin_content(%Video{id: video_id}, %Community{id: community_id}) do
76-
with {:ok, pined} <- ORM.find_by(PinedVideo, ~m(video_id community_id)a),
77-
{:ok, deleted} <- ORM.delete(pined) do
78-
Video |> ORM.find(deleted.video_id)
79-
end
80-
end
81-
8260
def pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
8361
attrs = ~m(repo_id community_id)a
8462

@@ -87,6 +65,28 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
8765
end
8866
end
8967

68+
def undo_pin_content(%Post{id: post_id}, %Community{id: community_id}, topic) do
69+
with {:ok, %{id: topic_id}} <- ORM.find_by(Topic, %{raw: topic}),
70+
{:ok, pined} <- ORM.find_by(PinedPost, ~m(post_id community_id topic_id)a),
71+
{:ok, deleted} <- ORM.delete(pined) do
72+
Post |> ORM.find(deleted.post_id)
73+
end
74+
end
75+
76+
def undo_pin_content(%Job{id: job_id}, %Community{id: community_id}) do
77+
with {:ok, pined} <- ORM.find_by(PinedJob, ~m(job_id community_id)a),
78+
{:ok, deleted} <- ORM.delete(pined) do
79+
Job |> ORM.find(deleted.job_id)
80+
end
81+
end
82+
83+
def undo_pin_content(%Video{id: video_id}, %Community{id: community_id}) do
84+
with {:ok, pined} <- ORM.find_by(PinedVideo, ~m(video_id community_id)a),
85+
{:ok, deleted} <- ORM.delete(pined) do
86+
Video |> ORM.find(deleted.video_id)
87+
end
88+
end
89+
9090
def undo_pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
9191
with {:ok, pined} <- ORM.find_by(PinedRepo, ~m(repo_id community_id)a),
9292
{:ok, deleted} <- ORM.delete(pined) do
@@ -222,16 +222,16 @@ defmodule MastaniServer.CMS.Delegate.ArticleOperation do
222222

223223
# make sure the reuest tag is in the current community thread
224224
# example: you can't set a other thread tag to this thread's article
225-
defp tag_in_community_thread?(%Community{id: communityId}, thread, tag) do
226-
with {:ok, community} <- ORM.find(Community, communityId) do
227-
matched_tags =
228-
Tag
229-
|> where([t], t.community_id == ^community.id)
230-
# |> where([t], t.thread == ^(to_string(thread) |> String.upcase()))
231-
|> where([t], t.thread == ^to_string(thread))
232-
|> Repo.all()
233-
234-
tag in matched_tags
235-
end
236-
end
225+
226+
# defp tag_in_community_thread?(%Community{id: communityId}, thread, tag) do
227+
# with {:ok, community} <- ORM.find(Community, communityId) do
228+
# matched_tags =
229+
# Tag
230+
# |> where([t], t.community_id == ^community.id)
231+
# |> where([t], t.thread == ^to_string(thread))
232+
# |> Repo.all()
233+
234+
# tag in matched_tags
235+
# end
236+
# end
237237
end

0 commit comments

Comments
 (0)