@@ -295,6 +295,9 @@ defmodule Helper.ORM do
295295 |> Repo . update ( )
296296 end
297297
298+ @ doc """
299+ extract common article info and assign it to 'article' field
300+ """
298301 def extract_and_assign_article ( % { entries: entries } = paged_articles ) do
299302 entries =
300303 Enum . map ( entries , fn item ->
@@ -307,24 +310,27 @@ defmodule Helper.ORM do
307310
308311 @ doc "extract common articles info"
309312 @ spec extract_articles ( T . paged_data ( ) , [ Atom . t ( ) ] ) :: T . paged_article_common ( )
310- def extract_articles ( % { entries: entries } = paged_articles , supported_threads ) do
313+ def extract_articles ( % { entries: entries } = paged_articles , threads \\ @ article_threads ) do
311314 paged_articles
312- |> Map . put ( :entries , Enum . map ( entries , & extract_article_info ( & 1 , supported_threads ) ) )
315+ |> Map . put ( :entries , Enum . map ( entries , & extract_article_info ( & 1 , threads ) ) )
313316 end
314317
315- defp extract_article_info ( reaction , supported_threads ) do
316- thread = Enum . find ( supported_threads , & ( not is_nil ( Map . get ( reaction , & 1 ) ) ) )
318+ defp extract_article_info ( reaction , threads ) do
319+ thread = Enum . find ( threads , & ( not is_nil ( Map . get ( reaction , & 1 ) ) ) )
317320 article = Map . get ( reaction , thread )
318321
319322 export_article_info ( thread , article )
320323 end
321324
322325 defp export_article_info ( thread , article ) do
326+ author = article . author . user
327+
323328 % {
324329 thread: thread ,
325330 id: article . id ,
326331 title: article . title ,
327- upvotes_count: Map . get ( article , :upvotes_count )
332+ upvotes_count: Map . get ( article , :upvotes_count ) ,
333+ author: author
328334 }
329335 end
330336end
0 commit comments