@@ -32,38 +32,35 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
3232 @ spec pin_article ( T . article_thread ( ) , Integer . t ( ) , Integer . t ( ) ) :: { :ok , PinnedArticle . t ( ) }
3333 def pin_article ( thread , article_id , community_id ) do
3434 with { :ok , info } <- match ( thread ) ,
35- { :ok , community } <- ORM . find ( Community , community_id ) ,
36- { :ok , _ } <- check_pinned_article_count ( community . id , thread ) do
37- thread_upcase = thread |> to_string |> String . upcase ( )
38-
39- args =
40- Map . put (
41- % { community_id: community . id , thread: thread_upcase } ,
42- info . foreign_key ,
43- article_id
44- )
45-
46- PinnedArticle |> ORM . create ( args )
35+ args <- pack_pin_args ( thread , article_id , community_id ) ,
36+ { :ok , _ } <- check_pinned_article_count ( args . community_id , thread ) ,
37+ { :ok , _ } <- ORM . create ( PinnedArticle , args ) do
38+ ORM . find ( info . model , article_id )
4739 end
4840 end
4941
5042 @ spec undo_pin_article ( T . article_thread ( ) , Integer . t ( ) , Integer . t ( ) ) :: { :ok , PinnedArticle . t ( ) }
5143 def undo_pin_article ( thread , article_id , community_id ) do
52- with { :ok , info } <- match ( thread ) do
53- thread_upcase = thread |> to_string |> String . upcase ( )
54-
55- args =
56- Map . put (
57- % { community_id: community_id , thread: thread_upcase } ,
58- info . foreign_key ,
59- article_id
60- )
61-
44+ with { :ok , info } <- match ( thread ) ,
45+ args <- pack_pin_args ( thread , article_id , community_id ) do
6246 ORM . findby_delete ( PinnedArticle , args )
6347 ORM . find ( info . model , article_id )
6448 end
6549 end
6650
51+ defp pack_pin_args ( thread , article_id , community_id ) do
52+ with { :ok , info } <- match ( thread ) ,
53+ { :ok , community } <- ORM . find ( Community , community_id ) do
54+ thread_upcase = thread |> to_string |> String . upcase ( )
55+
56+ Map . put (
57+ % { community_id: community . id , thread: thread_upcase } ,
58+ info . foreign_key ,
59+ article_id
60+ )
61+ end
62+ end
63+
6764 @ doc """
6865 trash / untrash articles
6966 """
0 commit comments