Skip to content

A Rails app that was intentionally designed to be refactored.

Notifications You must be signed in to change notification settings

serradura/rails_app_to_refactor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This Rails app has been intentionally designed in a way that there are areas for improvement.

It's your mission to find this places and refactor them.

Requirements to run the app

  • Ruby version: 3.2.0

  • Database: sqlite3

How to setup this app

bin/setup

Table of Contents

Useful commands

  • bin/rails test - it will run the test suite.

  • bin/rails rubycritic - it will generate a quality report of this codebase.

Examples of cURL requests to interact with the API

First, run the application:

bin/rails s

Then, use some of the following commands to interact with the API resources:

Users

Add new user

curl -X POST "http://localhost:3000/users" \
  -H "Content-Type: application/json" \
  -d '{"user":{"name": "Serradura", "email": "[email protected]", "password": "123456", "password_confirmation": "123456"}}'

Display user

curl -X GET "http://localhost:3000/user" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Delete user

curl -X DELETE "http://localhost:3000/user" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

To-Do Lists

Add new to-do list

curl -X POST "http://localhost:3000/todos_lists" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Things to learn"}}'

Display to-do list

curl -X GET "http://localhost:3000/todos_lists/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Display all to-do lists

curl -X GET "http://localhost:3000/todo_lists" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

This resource accepts the following query strings:

  • sort_by (e.g, 'updated_at')
  • order (e.g, 'asc')

PS: Desc is the default order.

Example:

curl -X GET "http://localhost:3000/todo_lists?sort_by=title" -H "Content-Type: application/json" -H "Authorization: Bearer SOME-USER-TOKEN"

Edit to-do list

curl -X PUT "http://localhost:3000/todo_lists/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Things to learn"}}'

Remove to-do list

curl -X DELETE "http://localhost:3000/todo_lists/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

To-Dos

Add new to-do

Default list
curl -X POST "http://localhost:3000/todos" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Buy coffee"}}'
In a list
curl -X POST "http://localhost:3000/todo_lists/1/todos" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Buy coffee"}}'

Display to-do

Default list
curl -X GET "http://localhost:3000/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"
From a list
curl -X GET "http://localhost:3000/todo_lists/1/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Display all to-dos

This resource accepts the following query strings:

  • status (e.g, 'completed')
  • sort_by (e.g, 'updated_at')
  • order (e.g, 'asc')

PS: Desc is the default order.

Example:

curl -X GET "http://localhost:3000/todos?status=&sort_by=&order="
  -H "Content-Type: application/json"
  -H "Authorization: Bearer SOME-USER-TOKEN"

The available statuses to filter are: overdue, completed, incomplete.

From a list
curl -X GET "http://localhost:3000/todo_lists/1/todos/1?status=&sort_by=&order=" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Edit to-do

Modify the content of the item.

curl -X PUT "http://localhost:3000/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Buy milk"}}'

Todo params:

  • title: string required.
  • completed: boolean optional.
In a list
curl -X PUT "http://localhost:3000/todo_lists/1/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN" \
  -d '{"todo":{"title": "Buy milk"}}'

Mark to-do as completed

Change the status to 'completed'.

curl -X PUT "http://localhost:3000/todos/1/complete" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"
In a list
curl -X PUT "http://localhost:3000/todo_lists/1/todos/1/complete" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Mark to-do as incomplete

Change the status to 'incomplete'.

curl -X PUT "http://localhost:3000/todos/1/incomplete" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"
In a list
curl -X PUT "http://localhost:3000/todo_lists/1/todos/1/incomplete" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

Remove to-do

The item will be permanently deleted from the list

curl -X DELETE "http://localhost:3000/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"
From a list
curl -X DELETE "http://localhost:3000/todo_lists/1/todos/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer SOME-USER-TOKEN"

About

A Rails app that was intentionally designed to be refactored.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages