It's need to install in your computer:
Docker: 18.06.0+
Docker-compose: 1.27.0+
Execute this commands to start the application:
// Create the .env file
cp .env.example .env
// Start all containers docker
docker-compose up -d
// Enter in container
make bash
// Generate the key
php artisan key:generate
// It's everything!
// You can access the api in: http://localhost:8040/
- MySQL 8.0
// Drop/Create migrations with seeds
php artisan migrate:fresh --seed
// Install database without datas
php artisan migrate:fresh
Request
curl --location --request GET 'localhost:8040/api/v1/posts'
Status
HTTP 200
Response
{ "current_page": 1, "data": [ { "id": 1, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:01.000000Z", "updated_at": "2022-01-15T18:41:01.000000Z", "reposts": [], "quote_posts": [] }, { "id": 2, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:02.000000Z", "updated_at": "2022-01-15T18:41:02.000000Z", "reposts": [], "quote_posts": [] }, { "id": 3, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:03.000000Z", "updated_at": "2022-01-15T18:41:03.000000Z", "reposts": [], "quote_posts": [] }, { "id": 4, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:04.000000Z", "updated_at": "2022-01-15T18:41:04.000000Z", "reposts": [], "quote_posts": [] }, { "id": 5, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:04.000000Z", "updated_at": "2022-01-15T18:41:04.000000Z", "reposts": [], "quote_posts": [] }, { "id": 6, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:05.000000Z", "updated_at": "2022-01-15T18:41:05.000000Z", "reposts": [], "quote_posts": [] } ], "first_page_url": "http://localhost:8040/api/v1/posts?page=1", "from": 1, "last_page": 1, "last_page_url": "http://localhost:8040/api/v1/posts?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://localhost:8040/api/v1/posts?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://localhost:8040/api/v1/posts", "per_page": 15, "prev_page_url": null, "to": 6, "total": 6 }
Request
curl --location --request GET 'localhost:8040/api/v1/posts/following?user_id=6'
Status
HTTP 200
Response
{ "current_page": 1, "data": [ { "id": 1, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:01.000000Z", "updated_at": "2022-01-15T18:41:01.000000Z", "reposts": [], "quote_posts": [] }, { "id": 2, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:02.000000Z", "updated_at": "2022-01-15T18:41:02.000000Z", "reposts": [], "quote_posts": [] }, { "id": 3, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:03.000000Z", "updated_at": "2022-01-15T18:41:03.000000Z", "reposts": [], "quote_posts": [] }, { "id": 4, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:04.000000Z", "updated_at": "2022-01-15T18:41:04.000000Z", "reposts": [], "quote_posts": [] }, { "id": 5, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:04.000000Z", "updated_at": "2022-01-15T18:41:04.000000Z", "reposts": [], "quote_posts": [] }, { "id": 6, "content": "asdasd", "user_id": 1, "created_at": "2022-01-15T18:41:05.000000Z", "updated_at": "2022-01-15T18:41:05.000000Z", "reposts": [], "quote_posts": [] } ], "first_page_url": "http://localhost:8040/api/v1/posts?page=1", "from": 1, "last_page": 1, "last_page_url": "http://localhost:8040/api/v1/posts?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://localhost:8040/api/v1/posts?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://localhost:8040/api/v1/posts", "per_page": 15, "prev_page_url": null, "to": 6, "total": 6 }
Request
curl --location --request GET 'localhost:8040/api/v1/users/brunoferreiras/profile'
Status
HTTP 200
Response
{ "username": "brunoferreiras", "date_joined": "Jan 15, 2022", "total_followers": 0, "total_following": 0, "total_posts": 6 }
Request
curl --location --request POST 'localhost:8040/api/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Bruno Ferreira",
"username": "brunoferreiras"
}'
Status
HTTP 201
Response
{ "name": "Bruno Ferreira", "username": "brunoferreiras", "updated_at": "2022-01-15T19:58:31.000000Z", "created_at": "2022-01-15T19:58:31.000000Z", "id": 1 }
Request
curl --location --request POST 'localhost:8040/api/v1/posts' \
--header 'Content-Type: application/json' \
--data-raw '{
"content": "any text",
"user_id": 1
}'
Status
HTTP 201
Response
{ "content": "any text", "user_id": 1, "updated_at": "2022-01-15T19:59:07.000000Z", "created_at": "2022-01-15T19:59:07.000000Z", "id": 1 }
Request
curl --location --request POST 'localhost:8040/api/v1/posts/1/repost' \
--header 'Content-Type: application/json' \
--data-raw '{
"comment": "",
"user_id": 1
}'
Status
HTTP 201
Response
{ "comment": null, "user_id": 1, "post_id": "1", "updated_at": "2022-01-15T19:59:47.000000Z", "created_at": "2022-01-15T19:59:47.000000Z", "id": 1 }
Request
curl --location --request POST 'localhost:8040/api/v1/posts/1/repost' \
--header 'Content-Type: application/json' \
--data-raw '{
"comment": "any comment",
"user_id": 1
}'
Status
HTTP 201
Response
{ "comment": "any comment", "user_id": 1, "post_id": "1", "updated_at": "2022-01-15T19:59:47.000000Z", "created_at": "2022-01-15T19:59:47.000000Z", "id": 1 }
Request
curl --location --request POST 'localhost:8040/api/v1/users/brunoferreiras/follow' \
--header 'Content-Type: application/json' \
--data-raw '{
"follower_id": 6,
"following_id": 5
}'
Status
HTTP 204
Response
Request
curl --location --request POST 'localhost:8040/api/v1/users/brunoferreiras/unfollow' \
--header 'Content-Type: application/json' \
--data-raw '{
"follower_id": 1,
"following_id": 2
}'
Status
HTTP 204
Response
Execute the tests:
// Outside container
make test
// Inner container
./vendor/bin/phpunit --testdox --verbose
- What permission rules will need?
- Can the user reply to the post itself?
- Will the response have the same daily post-creation limit?
- Create a new column in the
posts
table called thementioned_id
, which will be the post that was mentioned. - Create a new tab on the front of the home page for this functionality.
- In the post-creation route, a regex will be added to the content to identify a mention, if there is a mention, a search in the database will be performed to identify the post, and then add the post id in the
mentioned_id
field of the tableposts
. - A new route will be created with the paginated information that will return only as posts that have been mentioned.
- In the post creation route, if a reply to the post does not respect the same limit of daily posts, an exception to this rule must be created for this situation in the authorization of the request. Otherwise, they executed the same.
- Optimize docker images (removing waits and installing packages in docker entrypoint)
- Add more tests to fails situation
- Install ElasticSearch to implement the search posts
- Add cache (Redis) for most used routes (posts, etc)
- Add custom logs during the executions on routes
- Add oauth2/JWT to better identify users.
- Analyze what slow executing queries and optimize them.
- Use some database in cloud (Google Cloud SQL, for example)
- Install Kubernetes to manager the services
- Add observability with Istio
- Use Elastic Search for logs
- Use some cache service in cloud