Skip to content

Jhonny4975/Rebase-challenge

Repository files navigation

Rebase-challenge

This project is a challenge proposed by Rebase, it is an API in Ruby for listing medical exams.

Tech Stack

  • Ruby
  • Sinatra
  • Docker
  • Redis
  • Sidekiq

Install project

Requirements:

Only three tools are strictly needed:

Steps

Now we will need to clone the project, enter the project directory and run the script to prepare the application and start the server, for that follow the steps below.

git clone https://github.com/Jhonny4975/Rebase-challenge.git

cd rebase-challenge

bash run

After waiting for the script to finish its work you should see something like:

Screenshot_20220720_143501

Great, that means the server is active (don't close this terminal), now we can proceed with the usage instructions.

Usage

To continue we will need an API client, for this example I will use Insomnia.

Consult medical exams.

GET/tests

With the server running, run your client API and make a get request for the http://localhost:3000/tests route.

Screenshot_20220720_145343

It worked out! but why is it empty?

Well, we don't have anything in the database yet, so what we need to do now is create this data. You must be thinking "nice but how do we do that?" well, we have two ways, first, access the container and run a command that reads a previously prepared csv file and persists its data in the database, let's start with that then.

To do this, open another terminal, make sure they are in the same directory as before, and run the following command:

docker-compose run server bash

This command allows us to interact with a terminal inside the container, now we can move on to the next command:

rake db:seed:csv_data_import

After the execution you should see a success message and another one saying that 3900 exams were saved. Now go back to your API client and make the request again.

Screenshot_20220720_151209

Wow, it worked, we have a lot of exams now! But what if we want to save our own csv file? This brings us to the second way of populating the database, for which we will need to go back to our API client. You can close the terminal we ran the last command now.

Importing data from CSV files

POST/import

For this step, with the server running, run the client API and make a post request to the http://localhost:3000/import route, don't forget to upload your csv file before submitting.

If you forget or upload a document that is not a csv, you will see an error like this:

Screenshot_20220721_154546

Here is an example request using Insomnia:

Screenshot_20220721_155210

Now make a GET request to /tests again and see the csv data you just sent.

View details of a medical exam

GET/tests/:token

With the server running, run your client API and make a get request for the http://localhost:3000/tests/:token route.

Example:

Screenshot_20220721_195708

If the token is invalid, you will see something like:

Screenshot_20220721_193815

About

This project is a challenge proposed by Rebase

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published