Y is a platform for posting questions and asking more. Users can create posts and comments as long as they're all questions, encouraging deeper thought. Users can also follow each other and like and repost posts and comments. Posts and highly reposted comments are aggregated onto the front page. For a currated list, a user can view a front page of their followed users.
The frontend client of this server is located at https://github.com/JayOneTheSk8/why-client.
Requires ruby-3.2.2
and postgresql
bundle install
bin/rails db:migrate
bin/rails s
bin/rubocop
bin/rspec
Install openssl
# via Ubunutu
sudo apt install openssl
Create local key/certificate
# From top-repo level (lasts 1 year)
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -keyout config/ssl/localhost.key -out config/ssl/localhost.crt -subj "/CN=localhost" -days 365
Run server via puma config
bundle exec puma -C config/puma.rb
Creates a new User
and signs them in.
{
"user": {
"username": <string>
"display_name": <string>
"email": <string>
"password": <string>
"password_confirmation": <string> # optional
}
}
{
"id": <bigint>
"username": <string>
"display_name": <string>
"email": <string>
}
Signs a User
in.
{
"user": {
"login": <string> # Username or email for user
"password": <string>
}
}
{
"id": <bigint>
"username": <string>
"display_name": <string>
"email": <string>
}
Signs the User
out.
200 OK
Returns the current logged in User
.
{
"id": <bigint>
"username": <string>
"display_name": <string>
"email": <string>
}
Get the data of the User
.
{
"id": <bigint>
"username": <string>
"display_name": <string>
"email": <string>
"current_user_following": <boolean>
"post_count": <int>
"following_count": <int>
"follower_count": <int>
}
Edits the User
.
{
"user": {
"display_name": <string>
"email": <string>
}
}
{
"id": <bigint>
"username": <string>
"display_name": <string>
"email": <string>
"current_user_following": <boolean>
"post_count": <int>
"following_count": <int>
"follower_count": <int>
}
Gets all Post
s by lastest creation date.
[
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
...
]
Gets the data of the Post
.
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Creates a new Post
.
{
"post": {
"text": <string>
}
}
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Updates a Post
's text.
{
"post": {
"text": <string>
}
}
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Deletes a Post
and its associated comments
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": []
}
Gets the User
's created Post
s.
[
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": false
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
...
]
Gets all User
's created Post
s and reposted Post
s and Comment
s
{
"user": {
"username": <string>
"display_name": <string>
}
"posts": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": <CommentRepost|PostRepost|Post>
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime> # datetime of post creation or repost
"reposted_by": <string> # display name of reposter; optional
"reposted_by_username": <string> # username of reposter; optional
"user_liked": <boolean> # current user liked
"user_reposted": <boolean> # current user reposted
"user_followed": <boolean> # current user following author
"replying_to": <string[]> # usernames of parent comment and post author; optional
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Gets the most popular Post
s and reposted (at least 5 times) Comment
s by date and popularity.
{
"posts": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": <CommentRepost||Post>
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int> # comment/post's popularity
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Gets the most popular posts and reposted comments by date and popularity; filtered by the current User
's following list. Includes the User
's posts and reposts as well.
{
"posts": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": <CommentRepost|PostRepost|Post>
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"reposted_by": <string>
"reposted_by_username": <string>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Gets the Post
's full data with its associated top-level comments.
{
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": null
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
},
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
}
Gets the data of a Comment
.
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"parent": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"replies": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Creates a new Comment
.
{
"comment": {
"text": <string>
"post_id": <bigint>
"parent_id": <bigint> # optional parent comment being replied to
}
}
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"parent": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"replies": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Updates Comment
's text.
{
"comment": {
"text": <string>
}
}
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"parent": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"replies": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Deletes a Comment
.
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"current_user_following": <boolean>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"parent": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"replies": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Gets the User
's created comments.
[
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
"parent": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"reply_count": <int>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
}
...
]
Gets the User
's created and reposted Comment
s.
{
"user": {
"username": <string>
"display_name": <string>
},
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": <CommentRepost||Comment>
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"reposted_by": <string>
"reposted_by_username": <string>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Gets the Comment
's full data with its associated post and optional parent and replies.
{
"comment": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
},
"post": {
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": null
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
},
"parent": { # nullable
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
},
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"comment_count": <int>
"like_count": <int>
"repost_count": <int>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
}
Creates a new CommentLike
.
{
"like": {
"message_id": <bigint>
}
}
{
"type": "CommentLike"
"comment_id": <bigint>
"user_id": <bigint>
}
Deletes a CommentLike
.
{
"like": {
"message_id": <bigint>
}
}
{
"type": "CommentLike"
"comment_id": <bigint>
"user_id": <bigint>
}
Creates a new PostLike
.
{
"like": {
"message_id": <bigint>
}
}
{
"type": "PostLike"
"post_id": <bigint>
"user_id": <bigint>
}
Deletes a PostLike
.
{
"like": {
"message_id": <bigint>
}
}
{
"type": "PostLike"
"post_id": <bigint>
"user_id": <bigint>
}
Gets the Post
s and Comment
s the User
liked in order of Like
.
{
"user": {
"username": <string>
"display_name": <string>
}
"likes": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"like_type": <PostLike||CommentLike>
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"liked_at": <datetime>
"reposted_by": <string>
"reposted_by_username": <string>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Creates a CommentRepost
.
{
"repost": {
"message_id": <bigint>
}
}
{
"type": "CommentRepost"
"comment_id": <bigint>
"user_id": <bigint>
}
Deletes a CommentRepost
.
{
"repost": {
"message_id": <bigint>
}
}
{
"type": "CommentRepost"
"comment_id": <bigint>
"user_id": <bigint>
}
Creates a PostRepost
.
{
"repost": {
"message_id": <bigint>
}
}
{
"type": "PostRepost"
"post_id": <bigint>
"user_id": <bigint>
}
Deletes a PostRepost
.
{
"repost": {
"message_id": <bigint>
}
}
{
"type": "PostRepost"
"post_id": <bigint>
"user_id": <bigint>
}
Creates a Follow
.
{
"follow": {
"followee_id": <bigint>
}
}
{
"follower_id": <bigint>
"followee_id": <bigint>
}
Deletes a Follow
.
{
"follow": {
"followee_id": <bigint>
}
}
{
"follower_id": <bigint>
"followee_id": <bigint>
}
Gets the User
s the User
is following.
{
"id": <bigint>
"display_name": <string>
"username": <string>
"followed_users": [
{
"id": <bigint>
"username": <string>
"display_name": <string>
"following_current_user": <boolean>
"current_user_following": <boolean>
}
...
]
}
Gets the User
s that follow the User
.
{
"id": <bigint>
"display_name": <string>
"username": <string>
"followers": [
{
"id": <bigint>
"username": <string>
"display_name": <string>
"following_current_user": <boolean>
"current_user_following": <boolean>
}
...
]
}
Does a quick search of the top 6 most popular/active User
s with the search text in their username
or display_name
.
{
"search": {
"text": <string>
}
}
{
"users": [
{
"id": <bigint>
"username": <string>
"display_name": <string>
"current_user_following": <boolean>
"following_current_user": <boolean>
"follower_count": <int>
"followed_user_count": <int>
"user_rating": <int>
}
...
]
}
Does a search of the top 3 most popular/active User
s with the search text in their username
or display_name
and top 3 popular Post
s and Comment
s with the search text in their text
.
{
"search": {
"text": <string>
}
}
{
"users": [
{
"id": <bigint>
"username": <string>
"display_name": <string>
"current_user_following": <boolean>
"following_current_user": <boolean>
"follower_count": <int>
"followed_user_count": <int>
"user_rating": <int>
}
...
]
"posts": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": "Post"
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int>
"replying_to": null
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": "Comment"
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Does a search of the User
s with the search text in their username
or display_name
.
{
"search": {
"text": <string>
}
}
{
"users": [
{
"id": <bigint>
"username": <string>
"display_name": <string>
"current_user_following": <boolean>
"following_current_user": <boolean>
"follower_count": <int>
"followed_user_count": <int>
"user_rating": <int>
}
...
]
}
Does a search of the Post
s with the search text in their text
.
{
"search": {
"text": <string>
}
}
{
"posts": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": "Post"
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int>
"replying_to": null
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}
Does a search of the Comment
s with the search text in their text
.
{
"search": {
"text": <string>
}
}
{
"comments": [
{
"id": <bigint>
"text": <string>
"created_at": <datetime>
"post_type": "Comment"
"like_count": <int>
"repost_count": <int>
"comment_count": <int>
"post_date": <datetime>
"user_liked": <boolean>
"user_reposted": <boolean>
"user_followed": <boolean>
"rating": <int>
"replying_to": <string[]>
"author": {
"id": <bigint>
"username": <string>
"display_name": <string>
}
}
...
]
}