diff --git a/priv/repo/seeds_development.exs b/priv/repo/seeds_development.exs index d5c26e37..74f71aa7 100644 --- a/priv/repo/seeds_development.exs +++ b/priv/repo/seeds_development.exs @@ -100,43 +100,41 @@ for comment_body <- resources["comments"] do end IO.puts "---- Generating forum posts" -for resource <- resources["forum_posts"] do - for {forum_name, topics} <- resource do - forum = Repo.get_by!(Forum, short_name: forum_name) +for %{"forum" => forum_name, "topics" => topics} <- resources["forum_posts"] do + forum = Repo.get_by!(Forum, short_name: forum_name) - for {topic_name, [first_post | posts]} <- topics do - Topics.create_topic( - forum, - request_attributes, - %{ - "title" => topic_name, - "posts" => %{ - "0" => %{ - "body" => first_post, - } + for %{"title" => topic_name, "posts" => [first_post | posts]} <- topics do + Topics.create_topic( + forum, + request_attributes, + %{ + "title" => topic_name, + "posts" => %{ + "0" => %{ + "body" => first_post, } } - ) - |> case do - {:ok, %{topic: topic}} -> - for post <- posts do - Posts.create_post( - topic, - request_attributes, - %{"body" => post} - ) - |> case do - {:ok, %{post: post}} -> - Posts.reindex_post(post) + } + ) + |> case do + {:ok, %{topic: topic}} -> + for post <- posts do + Posts.create_post( + topic, + request_attributes, + %{"body" => post} + ) + |> case do + {:ok, %{post: post}} -> + Posts.reindex_post(post) - {:error, :post, changeset, _so_far} -> - IO.inspect changeset.errors - end + {:error, :post, changeset, _so_far} -> + IO.inspect changeset.errors end + end - {:error, :topic, changeset, _so_far} -> - IO.inspect changeset.errors - end + {:error, :topic, changeset, _so_far} -> + IO.inspect changeset.errors end end end diff --git a/priv/repo/seeds_development.json b/priv/repo/seeds_development.json index 36311e3b..a31b420a 100644 --- a/priv/repo/seeds_development.json +++ b/priv/repo/seeds_development.json @@ -57,23 +57,27 @@ "spoilers inside of a table\n\nHello | World\n--- | ---:\n`||cool beans!||` | ||cool beans!||" ], "forum_posts": [{ - "dis": [{ - "Example topic": [ - "example post", - "yet another example post" - ] - }, - { - "Second example topic": [ - "post", - "post 2" - ] - } - ] - }, + "forum": "dis", + "topics": [{ + "title": "Example Topic", + "posts": [ + "example post", + "yet another example post" + ] + }, + { + "title": "Second Example Topic", + "posts": [ + "post", + "post 2" + ] + } + ]}, { - "art": [{ - "Embedded images": [ + "forum": "art", + "topics": [{ + "title": "Embedded Images", + "posts": [ ">>1t >>1s >>1p", ">>1", "non-existent: >>1000t >>1000s >>1000p >>1000"