It's a rails application that allows users to create & list courses along with their tutors. This project includes two API's:
- Common POST API to create a course & its tutors
- GET API to list all the courses along with their tutors
It uses Ruby 3.2.1
, Ruby on Rails 7.0.4.3
and Postgresql
for the database.
- Clone the repository.
- Run
bin/setup
to install the dependencies, prepare the database & create an admin user for authorisation. - Run
bundle exec rails server
to start the Rails server. - Run
bundle exec rspec
to run the Rspec tests for the API's.
- Each user has an authentication token attribute which gets created upon user creation.
- Add
X-Auth-Email
&X-Auth-Token
in the request headers so that user making the API request can be authenticated. eg:
X-Auth-Email: '[email protected]'
X-Auth-Token: 'ByDy8KK9kjmkYmUz4khs'
- User has two roles in this application i.e standard & admin. An admin user is authorised to create courses with the tutors while standard user can list all the courses with the tutors.
- On running
bin/setup
an admin user is also created which can be used for courses creation.
You can create a custom user via rails console i.e rails c
using the following attributes. By default, it'll create a standard
user and we can create an admin user by specifying role as admin
.
user_attributes = {
first_name: "Test",
last_name: "User",
email: "[email protected]",
password: "welcome",
password_confirmation: "welcome",
role: "admin"
}
User.create user_attributes
{
"course": {
"title": "Learn personal finance",
"description": "This course helps you to save money",
"category": "finance", (Categories can be finance, development or gaming.)
"tutors_attributes": [{
"first_name": "Test",
"last_name": "One",
"email": "[email protected]"
},
{
"first_name": "Test",
"last_name": "Two",
"email": "[email protected]"
}]
}
}
{
"notice": "Course & its tutors are added successfully",
"id": "d4242c94-dfee-4c04-b01c-6fe68dbd7a83",
"title": "Learn personal finance",
"description": "This course helps you to save money",
"category": "finance",
"tutors": [
{
"id": "d99964cd-5b27-4771-a99c-6b10ec8149cf",
"first_name": "Test",
"last_name": "One",
"email": "[email protected]"
},
{
"id": "0c276668-bf70-49f2-ac86-5b45c310d328",
"first_name": "Test",
"last_name": "Two",
"email": "[email protected]"
}
]
}
[
{
"id": "96741859-a912-46b7-aba7-a884193d73cc",
"title": "Learn personal finance",
"description": "This course helps you to save money",
"category": "finance",
"tutors": [
{
"id": "9eb9d55d-f867-4257-8b54-295678690a60",
"first_name": "Test",
"last_name": "One",
"email": "[email protected]"
},
{
"id": "55dda6a1-c862-438e-ae28-0ff8c579aa16",
"first_name": "Test",
"last_name": "Two",
"email": "[email protected]"
}
]
},
{
"id": "06c1cff5-5c27-4aee-9746-4a449cde09cb",
"title": "Learn Ruby on rails",
"description": "This course helps you to learn ROR",
"category": "development",
"tutors": [
{
"id": "1fc539e2-a9d6-46a8-bcb8-3839b097926f",
"first_name": "Test",
"last_name": "Three",
"email": "[email protected]"
},
{
"id": "64dc75bc-b2f7-4678-a4f3-4ad36a9c8f67",
"first_name": "Test",
"last_name": "Four",
"email": "[email protected]"
}
]
}
]