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

Commit 444c79b

Browse files
authored
chore(cms): remove video staff (#314)
* refactor(rm-video): remove video tests * refactor(rm-video): remove db table, relate-code, fix tests * chore(rm-video): fmt
1 parent dc2f95b commit 444c79b

File tree

78 files changed

+54
-3764
lines changed

Some content is hidden

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

78 files changed

+54
-3764
lines changed

lib/groupher_server/accounts/delegates/favorite_category.ex

+5-9
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,20 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
4141
with {:ok, category} <- FavoriteCategory |> ORM.find_by(~m(id user_id)a) do
4242
Multi.new()
4343
|> Multi.run(:downgrade_achievement, fn _, _ ->
44-
# find user favvoried-contents(posts & jobs & videos) 's author,
44+
# find user favvoried-contents(posts & jobs) 's author,
4545
# and downgrade their's acieveents
4646
# NOTE: this is too fucking violent and should be refactor later
47-
# we find favroted posts/jobs/videos author_ids then doengrade their achievement
47+
# we find favroted posts/jobs author_ids then doengrade their achievement
4848
# this implentment is limited, if the user have lots contents in a favoreted-category
4949
# ant those contents have diffenert author each, it may be fucked
5050
# should be in a queue job or sth
5151
{:ok, post_author_ids} = affected_author_ids(:post, CMS.PostFavorite, category)
5252
{:ok, job_author_ids} = affected_author_ids(:job, CMS.JobFavorite, category)
53-
{:ok, video_author_ids} = affected_author_ids(:video, CMS.VideoFavorite, category)
5453
{:ok, repo_author_ids} = affected_author_ids(:repo, CMS.RepoFavorite, category)
5554

5655
# author_ids_list = count_words(total_author_ids) |> Map.to_list
5756
author_ids_list =
58-
(post_author_ids ++ job_author_ids ++ video_author_ids ++ repo_author_ids)
57+
(post_author_ids ++ job_author_ids ++ repo_author_ids)
5958
|> count_words
6059
|> Map.to_list()
6160

@@ -76,7 +75,7 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
7675
end
7776

7877
# NOTE: this is too fucking violent and should be refactor later
79-
# we find favroted posts/jobs/videos author_ids then doengrade their achievement
78+
# we find favroted posts/jobs author_ids then doengrade their achievement
8079
# this implentment is limited, if the user have lots contents in a favoreted-category
8180
# ant those contents have diffenert author each, it may be fucked
8281
defp affected_author_ids(thread, queryable, category) do
@@ -136,7 +135,7 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
136135
end
137136

138137
@doc """
139-
set category for favorited content (post, job, video ...)
138+
set category for favorited content (post, job ...)
140139
"""
141140
def set_favorites(%User{} = user, thread, content_id, category_id) do
142141
with {:ok, favorite_category} <-
@@ -238,9 +237,6 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
238237
defp find_content_favorite(:job, content_id, user_id),
239238
do: JobFavorite |> ORM.find_by(%{job_id: content_id, user_id: user_id})
240239

241-
defp find_content_favorite(:video, content_id, user_id),
242-
do: VideoFavorite |> ORM.find_by(%{video_id: content_id, user_id: user_id})
243-
244240
defp find_content_favorite(:repo, content_id, user_id),
245241
do: RepoFavorite |> ORM.find_by(%{repo_id: content_id, user_id: user_id})
246242

lib/groupher_server/accounts/delegates/reacted_contents.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule GroupherServer.Accounts.Delegate.ReactedContents do
22
@moduledoc """
3-
get contents(posts, jobs, videos ...) that user reacted (star, favorite ..)
3+
get contents(posts, jobs ...) that user reacted (star, favorite ..)
44
"""
55
import GroupherServer.CMS.Utils.Matcher
66
import Ecto.Query, warn: false

lib/groupher_server/accounts/user.ex

-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ defmodule GroupherServer.Accounts.User do
5757
# stared contents
5858
has_many(:stared_posts, {"posts_stars", CMS.PostStar})
5959
has_many(:stared_jobs, {"jobs_stars", CMS.JobStar})
60-
has_many(:stared_videos, {"videos_stars", CMS.VideoStar})
6160

6261
# favorited contents
6362
has_many(:favorited_posts, {"posts_favorites", CMS.PostFavorite})
6463
has_many(:favorited_jobs, {"jobs_favorites", CMS.JobFavorite})
65-
has_many(:favorited_videos, {"videos_favorites", CMS.VideoFavorite})
6664
has_many(:favorited_repos, {"repos_favorites", CMS.RepoFavorite})
6765

6866
has_many(:favorite_categories, {"favorite_categories", FavoriteCategory})

lib/groupher_server/accounts/utils/loader.ex

-8
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ defmodule GroupherServer.Accounts.Utils.Loader do
5050
CMS.JobStar |> count_contents
5151
end
5252

53-
def query({"videos_stars", CMS.VideoStar}, %{count: _}) do
54-
CMS.VideoStar |> count_contents
55-
end
56-
5753
# favorited contents count
5854
def query({"posts_favorites", CMS.PostFavorite}, %{count: _}) do
5955
CMS.PostFavorite |> count_contents
@@ -63,10 +59,6 @@ defmodule GroupherServer.Accounts.Utils.Loader do
6359
CMS.JobFavorite |> count_contents
6460
end
6561

66-
def query({"videos_favorites", CMS.VideoFavorite}, %{count: _}) do
67-
CMS.VideoFavorite |> count_contents
68-
end
69-
7062
def query({"repos_favorites", CMS.RepoFavorite}, %{count: _}) do
7163
CMS.RepoFavorite |> count_contents
7264
end

lib/groupher_server/cms/community.ex

-9
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ defmodule GroupherServer.CMS.Community do
6161
join_keys: [community_id: :id, post_id: :id]
6262
)
6363

64-
many_to_many(
65-
:videos,
66-
Video,
67-
join_through: "communities_videos",
68-
join_keys: [community_id: :id, video_id: :id]
69-
)
70-
7164
many_to_many(
7265
:repos,
7366
Repo,
@@ -85,10 +78,8 @@ defmodule GroupherServer.CMS.Community do
8578
# posts_managers
8679
# jobs_managers
8780
# tuts_managers
88-
# videos_managers
8981
#
9082
# posts_block_list ...
91-
# videos_block_list ...
9283
timestamps(type: :utc_datetime)
9384
end
9485

lib/groupher_server/cms/delegates/article_curd.ex

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule GroupherServer.CMS.Delegate.ArticleCURD do
22
@moduledoc """
3-
CURD operation on post/job/video ...
3+
CURD operation on post/job ...
44
"""
55
import Ecto.Query, warn: false
66
import GroupherServer.CMS.Utils.Matcher
@@ -243,16 +243,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
243243
end)
244244
end
245245

246-
defp domain_filter_query(CMS.Video = queryable, filter) do
247-
Enum.reduce(filter, queryable, fn
248-
{:source, source}, queryable ->
249-
queryable |> where([content], content.source == ^source)
250-
251-
{_, _}, queryable ->
252-
queryable
253-
end)
254-
end
255-
256246
defp domain_filter_query(CMS.Repo = queryable, filter) do
257247
Enum.reduce(filter, queryable, fn
258248
{:sort, :most_github_star}, queryable ->
@@ -327,10 +317,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
327317
merge_pin_contents(contents, :job, CMS.PinedJob, filter)
328318
end
329319

330-
defp add_pin_contents_ifneed(contents, CMS.Video, %{community: _community} = filter) do
331-
merge_pin_contents(contents, :video, CMS.PinedVideo, filter)
332-
end
333-
334320
defp add_pin_contents_ifneed(contents, CMS.Repo, %{community: _community} = filter) do
335321
merge_pin_contents(contents, :repo, CMS.PinedRepo, filter)
336322
end
@@ -441,7 +427,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
441427
defp content_id(:post, id), do: %{post_id: id}
442428
defp content_id(:job, id), do: %{job_id: id}
443429
defp content_id(:repo, id), do: %{repo_id: id}
444-
defp content_id(:video, id), do: %{video_id: id}
445430

446431
# for create content step in Multi.new
447432
defp exec_create_content(target, attrs, %Author{id: aid}, %Community{id: cid}) do

lib/groupher_server/cms/delegates/article_operation.ex

+1-24
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
1717
Job,
1818
JobCommunityFlag,
1919
RepoCommunityFlag,
20-
Video,
21-
VideoCommunityFlag,
2220
Tag,
2321
Topic,
2422
PinedPost,
2523
PinedJob,
26-
PinedVideo,
2724
PinedRepo
2825
}
2926

@@ -50,14 +47,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
5047
end
5148
end
5249

53-
def pin_content(%Video{id: video_id}, %Community{id: community_id}) do
54-
attrs = ~m(video_id community_id)a
55-
56-
with {:ok, pined} <- ORM.findby_or_insert(PinedVideo, attrs, attrs) do
57-
Video |> ORM.find(pined.video_id)
58-
end
59-
end
60-
6150
def pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
6251
attrs = ~m(repo_id community_id)a
6352

@@ -81,13 +70,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
8170
end
8271
end
8372

84-
def undo_pin_content(%Video{id: video_id}, %Community{id: community_id}) do
85-
with {:ok, pined} <- ORM.find_by(PinedVideo, ~m(video_id community_id)a),
86-
{:ok, deleted} <- ORM.delete(pined) do
87-
Video |> ORM.find(deleted.video_id)
88-
end
89-
end
90-
9173
def undo_pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
9274
with {:ok, pined} <- ORM.find_by(PinedRepo, ~m(repo_id community_id)a),
9375
{:ok, deleted} <- ORM.delete(pined) do
@@ -128,11 +110,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
128110
RepoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
129111
end
130112

131-
defp insert_flag_record(%Video{id: video_id}, community_id, attrs) do
132-
clauses = ~m(video_id community_id)a
133-
VideoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
134-
end
135-
136113
@doc """
137114
set content to diffent community
138115
"""
@@ -159,7 +136,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
159136
end
160137

161138
@doc """
162-
set general tag for post / tuts / videos ...
139+
set general tag for post / tuts ...
163140
refined tag can't set by this func, use set_refined_tag instead
164141
"""
165142
# check community first

lib/groupher_server/cms/delegates/article_reaction.ex

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule GroupherServer.CMS.Delegate.ArticleReaction do
22
@moduledoc """
3-
reaction[favorite, star, watch ...] on article [post, job, video...]
3+
reaction[favorite, star, watch ...] on article [post, job...]
44
"""
55
import Helper.Utils, only: [done: 1, done: 2]
66
import GroupherServer.CMS.Utils.Matcher
@@ -14,7 +14,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleReaction do
1414
alias Ecto.Multi
1515

1616
@doc """
17-
favorite / star / watch CMS contents like post / tuts / video ...
17+
favorite / star / watch CMS contents like post / tuts ...
1818
"""
1919
def reaction(thread, react, content_id, %User{id: user_id}) do
2020
with {:ok, action} <- match_action(thread, react),
@@ -56,7 +56,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleReaction do
5656

5757
# ------
5858
@doc """
59-
unfavorite / unstar / unwatch CMS contents like post / tuts / video ...
59+
unfavorite / unstar / unwatch CMS contents like post / tuts ...
6060
"""
6161
def undo_reaction(thread, react, content_id, %User{id: user_id}) do
6262
with {:ok, action} <- match_action(thread, react),
@@ -108,10 +108,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleReaction do
108108
dynamic([p], p.job_id == ^id and ^user_where)
109109
end
110110

111-
defp dynamic_reaction_where(:video, id, user_where) do
112-
dynamic([p], p.video_id == ^id and ^user_where)
113-
end
114-
115111
defp dynamic_reaction_where(:repo, id, user_where) do
116112
dynamic([p], p.repo_id == ^id and ^user_where)
117113
end

lib/groupher_server/cms/delegates/comment_curd.ex

-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
1515
alias GroupherServer.CMS.{
1616
PostCommentReply,
1717
JobCommentReply,
18-
VideoCommentReply,
1918
RepoCommentReply
2019
}
2120

@@ -213,17 +212,6 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
213212
end
214213
end
215214

216-
defp bridge_reply(:video, queryable, comment, attrs) do
217-
with {:ok, reply} <- ORM.create(queryable, attrs) do
218-
ORM.update(reply, %{reply_id: comment.id})
219-
220-
{:ok, _} =
221-
VideoCommentReply |> ORM.create(%{video_comment_id: comment.id, reply_id: reply.id})
222-
223-
queryable |> ORM.find(reply.id)
224-
end
225-
end
226-
227215
defp bridge_reply(:repo, queryable, comment, attrs) do
228216
with {:ok, reply} <- ORM.create(queryable, attrs) do
229217
ORM.update(reply, %{reply_id: comment.id})
@@ -256,27 +244,21 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
256244
# merge_comment_attrs when create comemnt
257245
defp merge_comment_attrs(:post, attrs, id), do: attrs |> Map.merge(%{post_id: id})
258246
defp merge_comment_attrs(:job, attrs, id), do: attrs |> Map.merge(%{job_id: id})
259-
defp merge_comment_attrs(:video, attrs, id), do: attrs |> Map.merge(%{video_id: id})
260247
defp merge_comment_attrs(:repo, attrs, id), do: attrs |> Map.merge(%{repo_id: id})
261248

262249
defp merge_reply_attrs(:post, attrs, comment),
263250
do: attrs |> Map.merge(%{post_id: comment.post_id})
264251

265252
defp merge_reply_attrs(:job, attrs, comment), do: attrs |> Map.merge(%{job_id: comment.job_id})
266253

267-
defp merge_reply_attrs(:video, attrs, comment),
268-
do: attrs |> Map.merge(%{video_id: comment.video_id})
269-
270254
defp merge_reply_attrs(:repo, attrs, comment),
271255
do: attrs |> Map.merge(%{repo_id: comment.repo_id})
272256

273257
defp dynamic_comment_where(:post, id), do: dynamic([c], c.post_id == ^id)
274258
defp dynamic_comment_where(:job, id), do: dynamic([c], c.job_id == ^id)
275-
defp dynamic_comment_where(:video, id), do: dynamic([c], c.video_id == ^id)
276259
defp dynamic_comment_where(:repo, id), do: dynamic([c], c.repo_id == ^id)
277260

278261
defp dynamic_reply_where(:post, comment), do: dynamic([c], c.post_id == ^comment.post_id)
279262
defp dynamic_reply_where(:job, comment), do: dynamic([c], c.job_id == ^comment.job_id)
280-
defp dynamic_reply_where(:video, comment), do: dynamic([c], c.video_id == ^comment.video_id)
281263
defp dynamic_reply_where(:repo, comment), do: dynamic([c], c.repo_id == ^comment.repo_id)
282264
end

lib/groupher_server/cms/delegates/comment_reaction.ex

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ defmodule GroupherServer.CMS.Delegate.CommentReaction do
2222

2323
defp merge_thread_comment_id(:post_comment, comment_id), do: %{post_comment_id: comment_id}
2424
defp merge_thread_comment_id(:job_comment, comment_id), do: %{job_comment_id: comment_id}
25-
defp merge_thread_comment_id(:video_comment, comment_id), do: %{video_comment_id: comment_id}
2625
defp merge_thread_comment_id(:repo_comment, comment_id), do: %{repo_comment_id: comment_id}
2726

2827
defp feel_comment(thread, comment_id, user_id, feeling) do

lib/groupher_server/cms/delegates/community_curd.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
5757
end
5858

5959
@doc """
60-
create a Tag base on type: post / tuts / videos ...
60+
create a Tag base on type: post / tuts ...
6161
"""
6262
# TODO: change to create_tag(community, thread, attrs, ....)
6363
def create_tag(%Community{id: community_id}, thread, attrs, %Accounts.User{id: user_id}) do

lib/groupher_server/cms/delegates/favorited_category.ex

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule GroupherServer.CMS.Delegate.FavoritedContents do
22
@moduledoc """
3-
CURD operation on post/job/video ...
3+
CURD operation on post/job ...
44
"""
55
alias Helper.ORM
66

@@ -20,12 +20,6 @@ defmodule GroupherServer.CMS.Delegate.FavoritedContents do
2020
|> handle_reault
2121
end
2222

23-
def favorited_category(:video, id, %User{id: user_id}) do
24-
CMS.VideoFavorite
25-
|> ORM.find_by(video_id: id, user_id: user_id)
26-
|> handle_reault
27-
end
28-
2923
def favorited_category(:repo, id, %User{id: user_id}) do
3024
CMS.RepoFavorite
3125
|> ORM.find_by(repo_id: id, user_id: user_id)

lib/groupher_server/cms/delegates/search.ex

-10
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ defmodule GroupherServer.CMS.Delegate.Search do
4141
|> done()
4242
end
4343

44-
@doc """
45-
search video by title
46-
"""
47-
def search_items(:video, %{title: title} = _args) do
48-
Video
49-
|> where([c], ilike(c.title, ^"%#{title}%") or ilike(c.desc, ^"%#{title}%"))
50-
|> ORM.paginater(page: 1, size: @search_items_count)
51-
|> done()
52-
end
53-
5444
@doc """
5545
search repo by title
5646
"""

lib/groupher_server/cms/delegates/seeds.ex

-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,6 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
435435
end)
436436
end
437437

438-
# tagfy only post job repo and video
439-
440438
defp tagfy_threads(communities, _threads, bot, :city) when is_list(communities) do
441439
Enum.each(communities, fn community ->
442440
create_tags(community, :post, bot, :city)

0 commit comments

Comments
 (0)