@@ -74,6 +74,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
74
74
|> Multi . run ( :set_community , fn _ , % { create_content: content } ->
75
75
ArticleOperation . set_community ( community , thread , content . id )
76
76
end )
77
+ |> Multi . run ( :set_meta , fn _ , % { create_content: content } ->
78
+ ArticleOperation . set_meta ( thread , content . id )
79
+ end )
77
80
|> Multi . run ( :set_topic , fn _ , % { create_content: content } ->
78
81
exec_set_topic ( thread , content . id , attrs )
79
82
end )
@@ -127,8 +130,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
127
130
|> Multi . run ( :update_content , fn _ , _ ->
128
131
ORM . update ( content , args )
129
132
end )
133
+ |> Multi . run ( :update_meta , fn _ , % { update_content: update_content } ->
134
+ ArticleOperation . update_meta ( update_content , :is_edited )
135
+ end )
130
136
|> 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 )
132
139
end )
133
140
|> Repo . transaction ( )
134
141
|> update_content_result ( )
@@ -407,6 +414,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
407
414
{ :error , [ message: "set community" , code: ecode ( :create_fails ) ] }
408
415
end
409
416
417
+ defp create_content_result ( { :error , :set_meta , _result , _steps } ) do
418
+ { :error , [ message: "set meta info" , code: ecode ( :create_fails ) ] }
419
+ end
420
+
410
421
defp create_content_result ( { :error , :set_community_flag , _result , _steps } ) do
411
422
{ :error , [ message: "set community flag" , code: ecode ( :create_fails ) ] }
412
423
end
@@ -423,10 +434,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
423
434
{ :error , [ message: "log action" , code: ecode ( :create_fails ) ] }
424
435
end
425
436
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 }
430
438
defp update_content_result ( { :error , :update_content , result , _steps } ) , do: { :error , result }
431
439
defp update_content_result ( { :error , :update_tag , result , _steps } ) , do: { :error , result }
432
440
@@ -479,9 +487,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
479
487
{ :ok , :pass }
480
488
end
481
489
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}
483
492
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
485
496
with { :ok , content } <- ORM . find ( content . __struct__ , content . id , preload: :tags ) do
486
497
tags =
487
498
Enum . reduce ( tags_ids , [ ] , fn t , acc ->
@@ -502,4 +513,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
502
513
|> Repo . update ( )
503
514
end
504
515
end
516
+
517
+ defp exec_update_tags ( _content , _ ) , do: { :ok , :pass }
505
518
end