Skip to content

Instantly share code, notes, and snippets.

@ahmadhasankhan
Forked from ericktai/1_user.rb
Last active November 26, 2017 19:24
Show Gist options
  • Save ahmadhasankhan/9427f50ba87e2b4835c2ebe848911564 to your computer and use it in GitHub Desktop.
Save ahmadhasankhan/9427f50ba87e2b4835c2ebe848911564 to your computer and use it in GitHub Desktop.

Revisions

  1. ahmadhasankhan revised this gist Nov 26, 2017. 8 changed files with 912 additions and 0 deletions.
    1 change: 1 addition & 0 deletions 1_user.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    class User < ApplicationRecord
    has_many :posts
    has_many :comments

    # id :integer not null, primary key
    # name :string(50) default("")
    end
    13 changes: 13 additions & 0 deletions 2_post.rb
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,17 @@ class Post < ApplicationRecord
    # user_id :integer
    # content :text default("")
    # created_at :datetime

    DEFAULT_PAGE_LIMIT = 50

    # By default fetching records in descending order, however, we can always override the default scope using unscoped method
    default_scope -> { order(created_at: :desc) }

    # We can reuse this anywhere and pass the different limit as per the need, By default limit is 50
    scope :most_recent, ->(limit = DEFAULT_PAGE_LIMIT) { preload_conditions.limit(limit) }

    # This will preload related objects when you include it in the query
    def self.preload_conditions
    includes(:user, comments: [:user])
    end
    end
    3 changes: 3 additions & 0 deletions 4_newsfeed_controller.rb
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,7 @@ class NewsfeedController < ApplicationController
    # will also include the User object of the Comment's author.

    # TODO: Newsfeed endpoint here
    def index
    @news_feeds = Post.most_recent.paginate(page: params[:page], per_page: 50)
    end
    end
    5 changes: 5 additions & 0 deletions newsfeed-_comment.json.jbuilder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    json.comments comments do |comment|
    json.type comment.class.name
    json.partial! 'newsfeed/user', user: comment.user
    json.content comment.content
    end
    4 changes: 4 additions & 0 deletions newsfeed-_feed.json.jbuilder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    json.type post.class.name
    json.content post.content
    json.partial! 'newsfeed/user', user: post.user
    json.partial! 'newsfeed/comment', comments: post.comments
    4 changes: 4 additions & 0 deletions newsfeed-_user.json.jbuilder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    json.user do
    json.type user.class.name
    json.name user.name
    end
    1 change: 1 addition & 0 deletions newsfeed-index.json.jbuilder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    json.array! @news_feeds, partial: 'newsfeed/feed', as: :post
    881 changes: 881 additions & 0 deletions output.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,881 @@
    [
    {
    "type": "Post",
    "content": "using loop 50",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": []
    },
    {
    "type": "Post",
    "content": "using loop 49",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 56"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 48",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 54"
    },
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 55"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 47",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 51"
    },
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 52"
    },
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 53"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 46",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": []
    },
    {
    "type": "Post",
    "content": "using loop 45",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": []
    },
    {
    "type": "Post",
    "content": "using loop 44",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": []
    },
    {
    "type": "Post",
    "content": "using loop 43",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": []
    },
    {
    "type": "Post",
    "content": "using loop 41",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 49"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 42",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 50"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 0",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 8"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 1",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 9"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 2",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 10"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 3",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 11"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 4",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 12"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 5",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 13"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 6",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 14"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 7",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 15"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 8",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 16"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 9",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 17"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 10",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 18"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 11",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 19"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 12",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 20"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 13",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 21"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 14",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 22"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 15",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 23"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 16",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 24"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 17",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 25"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 18",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 26"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 19",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 27"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 20",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 28"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 21",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 29"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 22",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 30"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 23",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 31"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 24",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 32"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 25",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 33"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 26",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 34"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 27",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 35"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 28",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 36"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 29",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 37"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 30",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 38"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 31",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 39"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 32",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 40"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 33",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 41"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 34",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 42"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 35",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 43"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 36",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 44"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 37",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 45"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 38",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Hassan"
    },
    "content": "This is comment 46"
    }
    ]
    },
    {
    "type": "Post",
    "content": "using loop 39",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "ahmad"
    },
    "content": "This is comment 47"
    }
    ]
    }
    ]
  2. Jimmie Tyrrell revised this gist Jul 27, 2017. 2 changed files with 3 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 1_user.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    class User < ApplicationRecord
    has_many :posts
    has_many :comments
    # id :integer not null, primary key
    # name :string(50) default("")
    end
    1 change: 1 addition & 0 deletions 2_post.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    class Post < ApplicationRecord
    belongs_to :user
    has_many :comments

    # id :integer not null, primary key
    # user_id :integer
  3. Jimmie Tyrrell revised this gist Jun 9, 2017. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions 5_example.json
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,51 @@

    [
    {
    "type": "Post",
    "content": "First post",
    "user": {
    "type": "User",
    "name": "Luke"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Leia"
    },
    "content": "First comment"
    },
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Han"
    },
    "content": "Second comment"
    },
    ]
    },
    {
    "type": "Post",
    "content": "Second post",
    "user": {
    "type": "User",
    "name": "Darth Vader"
    },
    "comments": [
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Boba Fett"
    },
    "content": "Third comment"
    },
    {
    "type": "Comment",
    "user": {
    "type": "User",
    "name": "Jabba"
    },
    "content": "Fourth comment"
  4. Jimmie Tyrrell revised this gist May 30, 2017. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions 4_newsfeed_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    class NewsfeedController < ApplicationController
    # Endpoint that returns a JSON object of Posts, each Post with an array of Comments
    # associated with it. Each Post and Comment also has information about the User
    # who wrote the content.
    # JSON endpoint that returns an array of Post objects in order of
    # newest first, to oldest last. Each Post contains a User object
    # (the author of the Post), and an array of Comments. Each Comment
    # will also include the User object of the Comment's author.

    # TODO: Newsfeed endpoint here
    end
  5. Jimmie Tyrrell revised this gist May 30, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion 2_post.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@ class Post < ApplicationRecord

    # id :integer not null, primary key
    # user_id :integer
    # title :string(50) default("")
    # content :text default("")
    # created_at :datetime
    end
  6. Jimmie Tyrrell revised this gist May 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 5_example.json
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    },
    {
    "user": {
    "name": "Leia"
    "name": "Han"
    },
    "content": "Second comment"
    },
  7. Jimmie Tyrrell revised this gist May 30, 2017. 2 changed files with 44 additions and 44 deletions.
    45 changes: 1 addition & 44 deletions 4_newsfeed_controller.rb
    Original file line number Diff line number Diff line change
    @@ -2,49 +2,6 @@ class NewsfeedController < ApplicationController
    # Endpoint that returns a JSON object of Posts, each Post with an array of Comments
    # associated with it. Each Post and Comment also has information about the User
    # who wrote the content.
    #
    # [
    # {
    # "content": "First post",
    # "user": {
    # "name": "Luke"
    # },
    # "comments": [
    # {
    # "user": {
    # "name": "Leia"
    # },
    # "content": "First comment"
    # },
    # {
    # "user": {
    # "name": "Leia"
    # },
    # "content": "Second comment"
    # },
    # ]
    # },
    # {
    # "content": "Second post",
    # "user": {
    # "name": "Darth Vader"
    # },
    # "comments": [
    # {
    # "user": {
    # "name": "Boba Fett"
    # },
    # "content": "Third comment"
    # },
    # {
    # "user": {
    # "name": "Jabba"
    # },
    # "content": "Fourth comment"
    # },
    # ]
    # }
    # ]


    # TODO: Newsfeed endpoint here
    end
    43 changes: 43 additions & 0 deletions 5_example.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@

    [
    {
    "content": "First post",
    "user": {
    "name": "Luke"
    },
    "comments": [
    {
    "user": {
    "name": "Leia"
    },
    "content": "First comment"
    },
    {
    "user": {
    "name": "Leia"
    },
    "content": "Second comment"
    },
    ]
    },
    {
    "content": "Second post",
    "user": {
    "name": "Darth Vader"
    },
    "comments": [
    {
    "user": {
    "name": "Boba Fett"
    },
    "content": "Third comment"
    },
    {
    "user": {
    "name": "Jabba"
    },
    "content": "Fourth comment"
    },
    ]
    }
    ]
  8. Jimmie Tyrrell revised this gist May 30, 2017. 4 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  9. Jimmie Tyrrell revised this gist May 30, 2017. 4 changed files with 23 additions and 26 deletions.
    10 changes: 10 additions & 0 deletions comment.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    class Comment < ApplicationRecord
    belongs_to :user
    belongs_to :post

    # id :integer not null, primary key
    # user_id :integer
    # post_id :integer
    # content :text default("")
    # created_at :datetime
    end
    26 changes: 0 additions & 26 deletions gistfile1.rb → newsfeed_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,3 @@
    class User < ApplicationRecord
    # id :integer not null, primary key
    # name :string(50) default("")
    end

    class Post < ApplicationRecord
    belongs_to :user

    # id :integer not null, primary key
    # user_id :integer
    # title :string(50) default("")
    # content :text default("")
    # created_at :datetime
    end

    class Comment < ApplicationRecord
    belongs_to :user
    belongs_to :post

    # id :integer not null, primary key
    # user_id :integer
    # post_id :integer
    # content :text default("")
    # created_at :datetime
    end

    class NewsfeedController < ApplicationController
    # Endpoint that returns a JSON object of Posts, each Post with an array of Comments
    # associated with it. Each Post and Comment also has information about the User
    9 changes: 9 additions & 0 deletions post.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    class Post < ApplicationRecord
    belongs_to :user

    # id :integer not null, primary key
    # user_id :integer
    # title :string(50) default("")
    # content :text default("")
    # created_at :datetime
    end
    4 changes: 4 additions & 0 deletions user.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    class User < ApplicationRecord
    # id :integer not null, primary key
    # name :string(50) default("")
    end
  10. Jimmie Tyrrell renamed this gist May 30, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.txt → gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ class Post < ApplicationRecord
    # user_id :integer
    # title :string(50) default("")
    # content :text default("")
    # created_at :datetime
    end

    class Comment < ApplicationRecord
    @@ -20,6 +21,7 @@ class Comment < ApplicationRecord
    # user_id :integer
    # post_id :integer
    # content :text default("")
    # created_at :datetime
    end

    class NewsfeedController < ApplicationController
  11. Jimmie Tyrrell revised this gist May 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    class User < ApplicationRecord
    # id :integer not null, primary key
    # name :string(50) default("")
    # name :string(50) default("")
    end

    class Post < ApplicationRecord
  12. Jimmie Tyrrell created this gist May 30, 2017.
    74 changes: 74 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    class User < ApplicationRecord
    # id :integer not null, primary key
    # name :string(50) default("")
    end

    class Post < ApplicationRecord
    belongs_to :user

    # id :integer not null, primary key
    # user_id :integer
    # title :string(50) default("")
    # content :text default("")
    end

    class Comment < ApplicationRecord
    belongs_to :user
    belongs_to :post

    # id :integer not null, primary key
    # user_id :integer
    # post_id :integer
    # content :text default("")
    end

    class NewsfeedController < ApplicationController
    # Endpoint that returns a JSON object of Posts, each Post with an array of Comments
    # associated with it. Each Post and Comment also has information about the User
    # who wrote the content.
    #
    # [
    # {
    # "content": "First post",
    # "user": {
    # "name": "Luke"
    # },
    # "comments": [
    # {
    # "user": {
    # "name": "Leia"
    # },
    # "content": "First comment"
    # },
    # {
    # "user": {
    # "name": "Leia"
    # },
    # "content": "Second comment"
    # },
    # ]
    # },
    # {
    # "content": "Second post",
    # "user": {
    # "name": "Darth Vader"
    # },
    # "comments": [
    # {
    # "user": {
    # "name": "Boba Fett"
    # },
    # "content": "Third comment"
    # },
    # {
    # "user": {
    # "name": "Jabba"
    # },
    # "content": "Fourth comment"
    # },
    # ]
    # }
    # ]

    # TODO: Newsfeed endpoint here
    end