@@ -74,6 +74,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
7474 |> Multi . run ( :set_community , fn _ , % { create_content: content } ->
7575 ArticleOperation . set_community ( community , thread , content . id )
7676 end )
77+ |> Multi . run ( :set_meta , fn _ , % { create_content: content } ->
78+ ArticleOperation . set_meta ( thread , content . id )
79+ end )
7780 |> Multi . run ( :set_topic , fn _ , % { create_content: content } ->
7881 exec_set_topic ( thread , content . id , attrs )
7982 end )
@@ -127,8 +130,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
127130 |> Multi . run ( :update_content , fn _ , _ ->
128131 ORM . update ( content , args )
129132 end )
133+ |> Multi . run ( :update_meta , fn _ , % { update_content: update_content } ->
134+ ArticleOperation . update_meta ( update_content , :is_edited )
135+ end )
130136 |> Multi . run ( :update_tag , fn _ , _ ->
131- exec_update_tags ( content , args . tags )
137+ # TODO: move it to ArticleOperation moudel
138+ exec_update_tags ( content , args )
132139 end )
133140 |> Repo . transaction ( )
134141 |> update_content_result ( )
@@ -407,6 +414,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
407414 { :error , [ message: "set community" , code: ecode ( :create_fails ) ] }
408415 end
409416
417+ defp create_content_result ( { :error , :set_meta , _result , _steps } ) do
418+ { :error , [ message: "set meta info" , code: ecode ( :create_fails ) ] }
419+ end
420+
410421 defp create_content_result ( { :error , :set_community_flag , _result , _steps } ) do
411422 { :error , [ message: "set community flag" , code: ecode ( :create_fails ) ] }
412423 end
@@ -423,10 +434,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
423434 { :error , [ message: "log action" , code: ecode ( :create_fails ) ] }
424435 end
425436
426- # except Job, other content will just pass, should use set_tag function instead
427- # defp exec_update_tags(_, _tags_ids), do: {:ok, :pass}
428-
429- defp update_content_result ( { :ok , % { update_content: result } } ) , do: { :ok , result }
437+ defp update_content_result ( { :ok , % { update_meta: result } } ) , do: { :ok , result }
430438 defp update_content_result ( { :error , :update_content , result , _steps } ) , do: { :error , result }
431439 defp update_content_result ( { :error , :update_tag , result , _steps } ) , do: { :error , result }
432440
@@ -479,9 +487,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
479487 { :ok , :pass }
480488 end
481489
482- defp exec_update_tags ( _content , tags_ids ) when length ( tags_ids ) == 0 , do: { :ok , :pass }
490+ # except Job, other content will just pass, should use set_tag function instead
491+ # defp exec_update_tags(_, _tags_ids), do: {:ok, :pass}
483492
484- defp exec_update_tags ( content , tags_ids ) do
493+ defp exec_update_tags ( _content , % { tags: tags_ids } ) when tags_ids == [ ] , do: { :ok , :pass }
494+
495+ defp exec_update_tags ( content , % { tags: tags_ids } ) do
485496 with { :ok , content } <- ORM . find ( content . __struct__ , content . id , preload: :tags ) do
486497 tags =
487498 Enum . reduce ( tags_ids , [ ] , fn t , acc ->
@@ -502,4 +513,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
502513 |> Repo . update ( )
503514 end
504515 end
516+
517+ defp exec_update_tags ( _content , _ ) , do: { :ok , :pass }
505518end
0 commit comments