Backend Service for an internal social media that used in a certain company. Built with Ruby and Sinatra Framework
-
User
- Can be created
- Fields:
- username
- bio description
-
Post
- Can be created
- Affiliated to a user
- May contain hashtags
- May contain attachment which is a picture, video, or other file
- Can be filtered by a hashtag (case-insensitive)
- The hashtags will be counted in the trending hashtags board
- Fields:
- user_id
- content (max 1000 characters)
- attachment
-
Comment
- Can be created
- Affiliated to a user and a post
- May contain hashtags (case-insensitive)
- May contain attachment which is a picture, video, or other file
- Can be filtered by a hashtag
- The hashtags will be counted in the trending hashtags board
- Fields:
- user_id
- post_id
- content (max 1000 characters)
- attachment
-
Hashtag
- The top 5 trending hashtags in the past 24 hours can be fetched
- Authentication and authorization
- Ruby version ^2.7.3
- MySql Server
- API Client (Postman, Thunder Client, etc)
- Ruby Gems
- mysql2
- sinatra
- sinatra-namespace
- rspec
- simplecov
- rack-test
- Make sure all the dependencies are installed. For Ruby gems, install it with
gem install <gem_name>
e.g.gem install rspec
- Clone this repository
$ git clone https://github.com/AldiNFitrah/gg-gram
- Create a new database and test database (you can use other names)
mysql> CREATE DATABASE gg_gram;
mysql> CREATE DATABASE gg_gram_test;
- Import the database schema to both databases
$ mysql -u 'username' -p gg_gram < db/schema.sql
$ mysql -u 'username' -p gg_gram_test < db/schema.sql
- Make the
.env
file based on the.env.example
and fill in the data - Run the application
$ ruby main.rb
- To Run the Tests
$ rspec -f d
- POST
/api/users
- To create a user
- Body:
- username
- bio_description (optional)
- POST
/api/users/<user_id>/post
- To create a post by a user with id=
<user_id>
- Body:
- content (optional)
- attachment (file, optional)
- To create a post by a user with id=
- GET
/api/posts
- To get posts filtered by a hashtag
- Query Params:
- hashtag (must start with
#
)
- hashtag (must start with
- POST
/api/posts/<post_id>/comment
- To create a comment to a post with id=
<post_id>
- Body:
- user_id
- content (optional)
- attachment (file, optional)
- To create a comment to a post with id=
- GET
/api/hashtags/trending
- To get the top5 trending hashtags in the past 24 hours
- GET
public/<file_name>
- To get the file that was attached before in a post or comment