Created
February 14, 2018 19:39
-
-
Save raderj89/cc0340dddcadd621f6b5d39cf9c80fb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_many :posts | |
has_many :comments | |
# id :integer not null, primary key | |
# name :string(50) default("") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ApplicationRecord | |
belongs_to :user | |
has_many :comments | |
# id :integer not null, primary key | |
# user_id :integer | |
# content :text default("") | |
# created_at :datetime | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsfeedController < ApplicationController | |
# 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. Comments | |
# should appear in order of oldest first, to newest last. | |
# TODO: Newsfeed endpoint here | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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" | |
}, | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment