@@ -30,34 +30,39 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
3030 alias GroupherServer.CMS.Repo , as: CMSRepo
3131 alias GroupherServer.Repo
3232
33- alias Ecto.Multi
34-
3533 @ max_pinned_article_count_per_thread Community . max_pinned_article_count_per_thread ( )
3634
3735 @ spec pin_article ( T . article_thread ( ) , Integer . t ( ) , Integer . t ( ) ) :: { :ok , PinnedArticle . t ( ) }
3836 def pin_article ( thread , article_id , community_id ) do
3937 with { :ok , info } <- match ( thread ) ,
4038 { :ok , community } <- ORM . find ( Community , community_id ) ,
41- { :ok , _ } <- check_pinned_article_count ( community_id , thread ) do
42- Multi . new ( )
43- |> Multi . run ( :update_article_pinned_flag , fn _ , _ ->
44- # ORM.update(comment, %{is_pinned: true})
45- { :ok , :pass }
46- end )
47- |> Multi . run ( :create_pinned_article , fn _ , _ ->
48- thread_upcase = thread |> to_string |> String . upcase ( )
49-
50- args =
51- Map . put (
52- % { community_id: community . id , thread: thread_upcase } ,
53- info . foreign_key ,
54- article_id
55- )
56-
57- PinnedArticle |> ORM . create ( args )
58- end )
59- |> Repo . transaction ( )
60- |> create_pinned_article_result ( )
39+ { :ok , _ } <- check_pinned_article_count ( community . id , thread ) do
40+ thread_upcase = thread |> to_string |> String . upcase ( )
41+
42+ args =
43+ Map . put (
44+ % { community_id: community . id , thread: thread_upcase } ,
45+ info . foreign_key ,
46+ article_id
47+ )
48+
49+ PinnedArticle |> ORM . create ( args )
50+ end
51+ end
52+
53+ @ spec undo_pin_article ( T . article_thread ( ) , Integer . t ( ) , Integer . t ( ) ) :: { :ok , PinnedArticle . t ( ) }
54+ def undo_pin_article ( thread , article_id , community_id ) do
55+ with { :ok , info } <- match ( thread ) do
56+ thread_upcase = thread |> to_string |> String . upcase ( )
57+
58+ args =
59+ Map . put (
60+ % { community_id: community_id , thread: thread_upcase } ,
61+ info . foreign_key ,
62+ article_id
63+ )
64+
65+ ORM . findby_delete ( PinnedArticle , args )
6166 end
6267 end
6368
@@ -306,10 +311,4 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
306311 _ -> { :ok , :pass }
307312 end
308313 end
309-
310- defp create_pinned_article_result ( { :ok , % { create_pinned_article: result } } ) , do: { :ok , result }
311-
312- defp create_pinned_article_result ( { :error , _ , result , _steps } ) do
313- { :error , result }
314- end
315314end
0 commit comments