Created
January 7, 2019 11:20
-
-
Save surendra-wal/c628441670bafffe760e15369bbb8b17 to your computer and use it in GitHub Desktop.
RoR assignment test - 01
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 | |
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 | |
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 | |
# 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 | |
# Response Format | |
[ | |
{ | |
"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
Assuming the app a newsfeed page - similar it to Facebook posts or LinkedIn Posts - where a User can create a message Post. Others can Comment on the post. The skeleton models are provided above.
The application will fetch posts from the newsfeed_controller. Presume that there are hundreds of posts per day. There may be a web app or mobile app or 3rd party consumer.
Build out the newsfeed_controllerso that someone can fetch newsfeeds and produce the JSON above. You can presume that you only fetch 50 at a time.
Please create a new rails app to do this question. We need a working Rails app for our evaluation.
You are free to use any gems/plugins that you want to.
Some considerations that we want you to work on:
Can you make the queries efficient (what would this mean)?
What if we want to reuse the query in other tasks? Would you organize the code in a different way? (e.g. Email the most recent 50 posts to somebody).
Please write down details related to technical implementation, how to run the app etc in readme.md.
NOTE: Please DO NOT put your code in a public domain. Send it back to us via email in a zip file.