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

chore(cms): remove video staff #314

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/groupher_server/accounts/delegates/favorite_category.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
with {:ok, category} <- FavoriteCategory |> ORM.find_by(~m(id user_id)a) do
Multi.new()
|> Multi.run(:downgrade_achievement, fn _, _ ->
# find user favvoried-contents(posts & jobs & videos) 's author,
# find user favvoried-contents(posts & jobs) 's author,
# and downgrade their's acieveents
# NOTE: this is too fucking violent and should be refactor later
# we find favroted posts/jobs/videos author_ids then doengrade their achievement
# we find favroted posts/jobs author_ids then doengrade their achievement
# this implentment is limited, if the user have lots contents in a favoreted-category
# ant those contents have diffenert author each, it may be fucked
# should be in a queue job or sth
{:ok, post_author_ids} = affected_author_ids(:post, CMS.PostFavorite, category)
{:ok, job_author_ids} = affected_author_ids(:job, CMS.JobFavorite, category)
{:ok, video_author_ids} = affected_author_ids(:video, CMS.VideoFavorite, category)
{:ok, repo_author_ids} = affected_author_ids(:repo, CMS.RepoFavorite, category)

# author_ids_list = count_words(total_author_ids) |> Map.to_list
author_ids_list =
(post_author_ids ++ job_author_ids ++ video_author_ids ++ repo_author_ids)
(post_author_ids ++ job_author_ids ++ repo_author_ids)
|> count_words
|> Map.to_list()

Expand All @@ -76,7 +75,7 @@ defmodule GroupherServer.Accounts.Delegate.FavoriteCategory do
end

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

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

defp find_content_favorite(:video, content_id, user_id),
do: VideoFavorite |> ORM.find_by(%{video_id: content_id, user_id: user_id})

defp find_content_favorite(:repo, content_id, user_id),
do: RepoFavorite |> ORM.find_by(%{repo_id: content_id, user_id: user_id})

Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/accounts/delegates/reacted_contents.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GroupherServer.Accounts.Delegate.ReactedContents do
@moduledoc """
get contents(posts, jobs, videos ...) that user reacted (star, favorite ..)
get contents(posts, jobs ...) that user reacted (star, favorite ..)
"""
import GroupherServer.CMS.Utils.Matcher
import Ecto.Query, warn: false
Expand Down
2 changes: 0 additions & 2 deletions lib/groupher_server/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ defmodule GroupherServer.Accounts.User do
# stared contents
has_many(:stared_posts, {"posts_stars", CMS.PostStar})
has_many(:stared_jobs, {"jobs_stars", CMS.JobStar})
has_many(:stared_videos, {"videos_stars", CMS.VideoStar})

# favorited contents
has_many(:favorited_posts, {"posts_favorites", CMS.PostFavorite})
has_many(:favorited_jobs, {"jobs_favorites", CMS.JobFavorite})
has_many(:favorited_videos, {"videos_favorites", CMS.VideoFavorite})
has_many(:favorited_repos, {"repos_favorites", CMS.RepoFavorite})

has_many(:favorite_categories, {"favorite_categories", FavoriteCategory})
Expand Down
8 changes: 0 additions & 8 deletions lib/groupher_server/accounts/utils/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ defmodule GroupherServer.Accounts.Utils.Loader do
CMS.JobStar |> count_contents
end

def query({"videos_stars", CMS.VideoStar}, %{count: _}) do
CMS.VideoStar |> count_contents
end

# favorited contents count
def query({"posts_favorites", CMS.PostFavorite}, %{count: _}) do
CMS.PostFavorite |> count_contents
Expand All @@ -63,10 +59,6 @@ defmodule GroupherServer.Accounts.Utils.Loader do
CMS.JobFavorite |> count_contents
end

def query({"videos_favorites", CMS.VideoFavorite}, %{count: _}) do
CMS.VideoFavorite |> count_contents
end

def query({"repos_favorites", CMS.RepoFavorite}, %{count: _}) do
CMS.RepoFavorite |> count_contents
end
Expand Down
9 changes: 0 additions & 9 deletions lib/groupher_server/cms/community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ defmodule GroupherServer.CMS.Community do
join_keys: [community_id: :id, post_id: :id]
)

many_to_many(
:videos,
Video,
join_through: "communities_videos",
join_keys: [community_id: :id, video_id: :id]
)

many_to_many(
:repos,
Repo,
Expand All @@ -85,10 +78,8 @@ defmodule GroupherServer.CMS.Community do
# posts_managers
# jobs_managers
# tuts_managers
# videos_managers
#
# posts_block_list ...
# videos_block_list ...
timestamps(type: :utc_datetime)
end

Expand Down
17 changes: 1 addition & 16 deletions lib/groupher_server/cms/delegates/article_curd.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GroupherServer.CMS.Delegate.ArticleCURD do
@moduledoc """
CURD operation on post/job/video ...
CURD operation on post/job ...
"""
import Ecto.Query, warn: false
import GroupherServer.CMS.Utils.Matcher
Expand Down Expand Up @@ -243,16 +243,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
end)
end

defp domain_filter_query(CMS.Video = queryable, filter) do
Enum.reduce(filter, queryable, fn
{:source, source}, queryable ->
queryable |> where([content], content.source == ^source)

{_, _}, queryable ->
queryable
end)
end

defp domain_filter_query(CMS.Repo = queryable, filter) do
Enum.reduce(filter, queryable, fn
{:sort, :most_github_star}, queryable ->
Expand Down Expand Up @@ -327,10 +317,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
merge_pin_contents(contents, :job, CMS.PinedJob, filter)
end

defp add_pin_contents_ifneed(contents, CMS.Video, %{community: _community} = filter) do
merge_pin_contents(contents, :video, CMS.PinedVideo, filter)
end

defp add_pin_contents_ifneed(contents, CMS.Repo, %{community: _community} = filter) do
merge_pin_contents(contents, :repo, CMS.PinedRepo, filter)
end
Expand Down Expand Up @@ -441,7 +427,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
defp content_id(:post, id), do: %{post_id: id}
defp content_id(:job, id), do: %{job_id: id}
defp content_id(:repo, id), do: %{repo_id: id}
defp content_id(:video, id), do: %{video_id: id}

# for create content step in Multi.new
defp exec_create_content(target, attrs, %Author{id: aid}, %Community{id: cid}) do
Expand Down
25 changes: 1 addition & 24 deletions lib/groupher_server/cms/delegates/article_operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
Job,
JobCommunityFlag,
RepoCommunityFlag,
Video,
VideoCommunityFlag,
Tag,
Topic,
PinedPost,
PinedJob,
PinedVideo,
PinedRepo
}

Expand All @@ -50,14 +47,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
end
end

def pin_content(%Video{id: video_id}, %Community{id: community_id}) do
attrs = ~m(video_id community_id)a

with {:ok, pined} <- ORM.findby_or_insert(PinedVideo, attrs, attrs) do
Video |> ORM.find(pined.video_id)
end
end

def pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
attrs = ~m(repo_id community_id)a

Expand All @@ -81,13 +70,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
end
end

def undo_pin_content(%Video{id: video_id}, %Community{id: community_id}) do
with {:ok, pined} <- ORM.find_by(PinedVideo, ~m(video_id community_id)a),
{:ok, deleted} <- ORM.delete(pined) do
Video |> ORM.find(deleted.video_id)
end
end

def undo_pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do
with {:ok, pined} <- ORM.find_by(PinedRepo, ~m(repo_id community_id)a),
{:ok, deleted} <- ORM.delete(pined) do
Expand Down Expand Up @@ -128,11 +110,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
RepoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
end

defp insert_flag_record(%Video{id: video_id}, community_id, attrs) do
clauses = ~m(video_id community_id)a
VideoCommunityFlag |> ORM.upsert_by(clauses, Map.merge(attrs, clauses))
end

@doc """
set content to diffent community
"""
Expand All @@ -159,7 +136,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
end

@doc """
set general tag for post / tuts / videos ...
set general tag for post / tuts ...
refined tag can't set by this func, use set_refined_tag instead
"""
# check community first
Expand Down
10 changes: 3 additions & 7 deletions lib/groupher_server/cms/delegates/article_reaction.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GroupherServer.CMS.Delegate.ArticleReaction do
@moduledoc """
reaction[favorite, star, watch ...] on article [post, job, video...]
reaction[favorite, star, watch ...] on article [post, job...]
"""
import Helper.Utils, only: [done: 1, done: 2]
import GroupherServer.CMS.Utils.Matcher
Expand All @@ -14,7 +14,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleReaction do
alias Ecto.Multi

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

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

defp dynamic_reaction_where(:video, id, user_where) do
dynamic([p], p.video_id == ^id and ^user_where)
end

defp dynamic_reaction_where(:repo, id, user_where) do
dynamic([p], p.repo_id == ^id and ^user_where)
end
Expand Down
18 changes: 0 additions & 18 deletions lib/groupher_server/cms/delegates/comment_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
alias GroupherServer.CMS.{
PostCommentReply,
JobCommentReply,
VideoCommentReply,
RepoCommentReply
}

Expand Down Expand Up @@ -213,17 +212,6 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
end
end

defp bridge_reply(:video, queryable, comment, attrs) do
with {:ok, reply} <- ORM.create(queryable, attrs) do
ORM.update(reply, %{reply_id: comment.id})

{:ok, _} =
VideoCommentReply |> ORM.create(%{video_comment_id: comment.id, reply_id: reply.id})

queryable |> ORM.find(reply.id)
end
end

defp bridge_reply(:repo, queryable, comment, attrs) do
with {:ok, reply} <- ORM.create(queryable, attrs) do
ORM.update(reply, %{reply_id: comment.id})
Expand Down Expand Up @@ -256,27 +244,21 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
# merge_comment_attrs when create comemnt
defp merge_comment_attrs(:post, attrs, id), do: attrs |> Map.merge(%{post_id: id})
defp merge_comment_attrs(:job, attrs, id), do: attrs |> Map.merge(%{job_id: id})
defp merge_comment_attrs(:video, attrs, id), do: attrs |> Map.merge(%{video_id: id})
defp merge_comment_attrs(:repo, attrs, id), do: attrs |> Map.merge(%{repo_id: id})

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

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

defp merge_reply_attrs(:video, attrs, comment),
do: attrs |> Map.merge(%{video_id: comment.video_id})

defp merge_reply_attrs(:repo, attrs, comment),
do: attrs |> Map.merge(%{repo_id: comment.repo_id})

defp dynamic_comment_where(:post, id), do: dynamic([c], c.post_id == ^id)
defp dynamic_comment_where(:job, id), do: dynamic([c], c.job_id == ^id)
defp dynamic_comment_where(:video, id), do: dynamic([c], c.video_id == ^id)
defp dynamic_comment_where(:repo, id), do: dynamic([c], c.repo_id == ^id)

defp dynamic_reply_where(:post, comment), do: dynamic([c], c.post_id == ^comment.post_id)
defp dynamic_reply_where(:job, comment), do: dynamic([c], c.job_id == ^comment.job_id)
defp dynamic_reply_where(:video, comment), do: dynamic([c], c.video_id == ^comment.video_id)
defp dynamic_reply_where(:repo, comment), do: dynamic([c], c.repo_id == ^comment.repo_id)
end
1 change: 0 additions & 1 deletion lib/groupher_server/cms/delegates/comment_reaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule GroupherServer.CMS.Delegate.CommentReaction do

defp merge_thread_comment_id(:post_comment, comment_id), do: %{post_comment_id: comment_id}
defp merge_thread_comment_id(:job_comment, comment_id), do: %{job_comment_id: comment_id}
defp merge_thread_comment_id(:video_comment, comment_id), do: %{video_comment_id: comment_id}
defp merge_thread_comment_id(:repo_comment, comment_id), do: %{repo_comment_id: comment_id}

defp feel_comment(thread, comment_id, user_id, feeling) do
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/delegates/community_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
end

@doc """
create a Tag base on type: post / tuts / videos ...
create a Tag base on type: post / tuts ...
"""
# TODO: change to create_tag(community, thread, attrs, ....)
def create_tag(%Community{id: community_id}, thread, attrs, %Accounts.User{id: user_id}) do
Expand Down
8 changes: 1 addition & 7 deletions lib/groupher_server/cms/delegates/favorited_category.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GroupherServer.CMS.Delegate.FavoritedContents do
@moduledoc """
CURD operation on post/job/video ...
CURD operation on post/job ...
"""
alias Helper.ORM

Expand All @@ -20,12 +20,6 @@ defmodule GroupherServer.CMS.Delegate.FavoritedContents do
|> handle_reault
end

def favorited_category(:video, id, %User{id: user_id}) do
CMS.VideoFavorite
|> ORM.find_by(video_id: id, user_id: user_id)
|> handle_reault
end

def favorited_category(:repo, id, %User{id: user_id}) do
CMS.RepoFavorite
|> ORM.find_by(repo_id: id, user_id: user_id)
Expand Down
10 changes: 0 additions & 10 deletions lib/groupher_server/cms/delegates/search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ defmodule GroupherServer.CMS.Delegate.Search do
|> done()
end

@doc """
search video by title
"""
def search_items(:video, %{title: title} = _args) do
Video
|> where([c], ilike(c.title, ^"%#{title}%") or ilike(c.desc, ^"%#{title}%"))
|> ORM.paginater(page: 1, size: @search_items_count)
|> done()
end

@doc """
search repo by title
"""
Expand Down
2 changes: 0 additions & 2 deletions lib/groupher_server/cms/delegates/seeds.ex
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,6 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
end)
end

# tagfy only post job repo and video

defp tagfy_threads(communities, _threads, bot, :city) when is_list(communities) do
Enum.each(communities, fn community ->
create_tags(community, :post, bot, :city)
Expand Down
Loading