Implement a REST API in Go meeting the requirements laid out below. You may use whatever other open-source libraries you see fit to get the job done.
Before getting started on the challenge, let’s get some logistics out of the way:
- You should create a private repository on Github and add @dmaii and @ellismiranda as collaborators.
- Create an empty branch with a name of your choosing and push it up. You should push your commits to this branch.
- Create a pull request to master from this branch and copy/paste the “Requirements” section into the description.
- Add @dmaii and @ellismiranda as reviewers when you are ready for us to review.
Please complete this exercise within 3 days of when you receive it. Good luck and have fun!
Requirements Your task will be to build a simplified version of the Reddit feed API that powers http://old.reddit.com. Please use Go as the programming language. This will be a REST API that allows users to do the following:
Create new posts. Posts should be validated for correctness. They should have the following fields:
- Title
- Author: This should be a random 8 character string prefixed with t2_. The 8 character string should only contain lowercase letters and numbers. For example, my user ID is t2_11qnzrqv.
- Link: This should be a valid URL. It's ok if your validation is not perfect.
- Subreddit: The subreddit associated with this post.
- Content: In the case of a text-only post. A post cannot have both a link and content populated.
- Score: The total score associated with the upvotes and downvotes of a post.
- Promoted: A boolean field indicating whether or not the post is an ad or not.
- NSFW: Not safe for work. A boolean that indicates whether or not the post is safe for work
Generate a feed of posts. This feed should have the following characteristics:
- It should be ranked by score, and the post with the highest score should show up first.
- It should be paginated, and each page should have at most 27 posts. Your API should support fetching a specific page in the feed.
- If a page has 3 posts or greater, the second post should always be a promoted post if a promoted post is available, regardless of the score.
- If a page has greater than 16 posts, the 16th post should always be a promoted post if a promoted post is available, regardless of the score.
- As an exception to rules 3 and 4, a promoted post should never be shown adjacent to an NSFW post. You can ignore rules 3 and 4 in this case. Your codebase should have a README with setup instructions, as well as integration and unit tests.