This is an API to provide the api endpoint for user to create an fitness app that can track their daily exercises.
The ER diagram used to create the model for this project is as below:
The features of this project are, user can:
- register and login.
- Perform CRUD operation for exercise.
- Perform CRUD operation for measurements.
- Get user information and update it.
Authorization is required for all endpoints except /api/login
and /api/register
.
- How to get the authorization token?
To get the authorization token user should register using endpoint /user
. If they have an account they can call the /login
api to get the token.
- How the token should be passed?
Once user have the token they can pass it on every request header as below:
Authorization: Token {user_token}
Below is the information regarding api endpoint to use.
-
/api/login
-
Request verb:
POST
-
Action: login
-
Request body parameters:
{ "user": { "email": "example@mail.com", "password": "test123" } }
-
Response:
{ "user": { "id": 1, "email": "example@mail.com", "bio": "user bio", "image": null, "token": "jwt_token" } }
-
-
/api/register
-
Request verb:
POST
-
Action: Register
-
Request body parameters:
{ "user": { "email": "example@mail.com", "password": "test123" } }
-
Response:
{ "user": { "id": 1, "email": "example@mail.com", "bio": "user bio", "image": null, "token": "jwt_token" } }
-
-
/api/exercises
- Request verb:
GET
- Action: Get all exercises
- Request body parameters:
null
- Response:
[ { "id": 4, "name": "Pull up", "created_at": "2021-07-13T10:51:25.417Z", "updated_at": "2021-07-30T07:56:54.386Z", "unit": "reps", "target": 50, "icon": "pull-up" }, { "id": 5, "name": "Running", "created_at": "2021-07-13T11:10:10.535Z", "updated_at": "2021-07-30T07:58:18.039Z", "unit": "KM", "target": 5, "icon": "runner" } ]
- Request verb:
-
/api/exercises
- Request verb:
POST
- Action: Creat new exercise
- Request body parameters:
{ "exercise": { "name": "Push up", "unit": "reps", "target": 100 } }
- Response:
{ "id": 1, "name": "Push up", "created_at": "2021-08-06T09:45:13.058Z", "updated_at": "2021-08-06T09:45:13.058Z", "unit": "reps", "target": 100, "icon": "push-up" }
- Request verb:
-
/api/exercises/{exercise_id}
- Request verb:
PUT
- Action: Update exercise
- Request body parameters:
# from these fields which ever you want to update # you can pass that field or all if you want # to update all. { "exercise": { "name": "Push up", "unit": "reps", "target": 100, "icon": "icon-name" } }
- Response:
{ "id": 1, "name": "Push up", "created_at": "2021-08-06T09:45:13.058Z", "updated_at": "2021-08-06T09:45:13.058Z", "unit": "reps", "target": 100, "icon": "icon-name" }
- Request verb:
-
/api/exercises/{exercise_id}
- Request verb:
DELETE
- Action: Delete exercise
- Request body parameters: null
- Response: null
- Request verb:
-
/api/exercises/{exercise_id}
- Request verb:
GET
- Action: Get exercise detail
- Request body parameters: null
- Response:
{ "id": 1, "name": "Push up", "created_at": "2021-08-06T09:45:13.058Z", "updated_at": "2021-08-06T09:45:13.058Z", "unit": "reps", "target": 100, "icon": "push-up" }
- Request verb:
-
/api/measurements
- Request verb:
GET
- Action: Get all measurements
- Request body parameters:
null
- Response:
[ { "id": 2, "exercise_id": 3, "quantity": 60, "created_at": "2021-07-30T08:18:20.212Z", "updated_at": "2021-07-30T08:18:20.212Z", "user_id": 1 }, { "id": 3, "exercise_id": 3, "quantity": 1, "created_at": "2021-07-30T10:21:09.310Z", "updated_at": "2021-07-30T10:21:09.310Z", "user_id": 1 } ]
- Request verb:
-
/api/measurements
- Request verb:
POST
- Action: Creat new measurement
- Request body parameters:
{ "measurement": { "exercise_id": 3, "quantity": 60 } }
- Response:
{ "id": 1, "exercise_id": 3, "quantity": 60, "created_at": "2021-08-06T10:00:09.831Z", "updated_at": "2021-08-06T10:00:09.831Z", "user_id": 1 }
- Request verb:
-
/api/measurements/{measurement_id}
- Request verb:
PUT
- Action: Update measurement
- Request body parameters:
{ "measurement": { "quantity": "12" } }
- Response:
{ "quantity": 12, "id": 1, "exercise_id": 3, "created_at": "2021-08-06T07:14:38.695Z", "updated_at": "2021-08-06T10:01:31.594Z", "user_id": 1 }
- Request verb:
-
/api/measurements/{measurement_id}
- Request verb:
DELETE
- Action: Delete measurement
- Request body parameters: null
- Response: null
- Request verb:
-
/api/measurements/{measurement_id}
- Request verb:
GET
- Action: Get measurement detail
- Request body parameters: null
- Response:
{ "id": 1, "quantity": 12, "exercise_id": 3, "created_at": "2021-08-06T07:14:38.695Z", "updated_at": "2021-08-06T10:01:31.594Z", "user_id": 1 }
- Request verb:
-
/api/user
- Request verb:
GET
- Action: Get user detail
- Request body parameters: null
- Response:
{ "user": { "id": 1, "email": "example@mail.com", "bio": "user bio", "image": null, "token": "jwt_token" } }
- Request verb:
-
/api/user
- Request verb:
PUT
- Action: Update user details
- Request body parameters:
{ "user": { "bio": "Updated bio." } }
- Response:
{ "user": { "id": 1, "email": "example@mail.com", "bio": "Updated bio", "image": null, "token": "jwt_token" } }
- Request verb:
This project is hosted on heroku.
- Ruby
- Rails
- postgresql
If you intend to download the project, you will need to have
-
Ruby
For more information on how to install Ruby, follow this link
-
Ruby on rails
After ruby is installed run cmd
gem rails
-
postgresql
For installing postgresql follow this link
Follow along the steps below to get a copy at your local machine.
-
Navigate to the directory where you want this project to clone and then clone it
git clone https://github.com/dipbazz/track-my-fitness.git
-
Navigate to the
track-my-fitness
directorycd track-my-fitness
-
install the gem package
bundle install
-
install npm packages
npm install
-
Create your database
rails db:create
-
Migrate the database
rails db:migrate
-
Start your server
rails server
-
Open browser at http://localhost:3000/
To test the project run the below cmd from your project root directory.
rspec
OR
rspec --format doc
If you want to populate initial user data instead of creating it for manual testing you can run
rails db:seed
👤 Dipesh Bajgain
- GitHub: @dipbazz
- Twitter: @dipbazz
- LinkedIn: Dipesh Bajgain
Contributions, issues, and feature requests are welcome!
Give a ⭐️ if you like this project!
This project is MIT licensed.