Image for post
Image for post

Building a Coding Challenge Platform — Week #1

In this article I will present my first week of progress on my personal project called AlgoShell — a coding challenge platform where users can use the command line to test algorithms on a file from their computer. This is in contrast to traditional platforms such as LeetCode and Hackerrank where users interact with an browser-based code editor to write and submit code. This weeks accomplishments are:

  1. Set up admin interface
  2. Automated database setup
  3. Created a basic API endpoint

Setting up the Admin Interface

The purpose of the admin interface is so that a website administrator can login and manage the questions that are being displayed to a user. After starting up the application, the admin interface is accessible on localhost:8000/admin where an administrator can enter their credentials into a login screen:

Image for post
Image for post

After authenticating, the admin will be able to create or edit existing questions by providing a name, description, category, and difficulty.

Image for post
Image for post

Automating Database Setup

Each time a new instance of the application is created, two things are required for proper database transactions:

1. Database migration — The creation of relational database tables according to the schema defined by the application so that data can be stored and retrieved.

2. Superuser creation — Account creation so that the Admin can login in order to manage question, difficulty, and category database objects.

Without automation, the following commands must be executed:

docker-compose run web python manage.py migrate
docker-compose run web python manage.py createsuperuser

In addition to these commands the developer must provide 1.) username 2.) email address 3.) password 4.) confirm password

The goal of this task was to abstract this entire process away as much as possible. The new database setup process consists of simply running a setup script:

Image for post
Image for post

After running the setup script the terminal output indicates all the database migration operations that took place:

Image for post
Image for post

At the end of the script execution the developer is then prompted to input their desired password for the administrator to use when logging in:

Image for post
Image for post

Creating a Basic API Endpoint

The goal of this task was to setup up the basic data pipeline such that a client could communicate with the API. Nothing special going on other than responding to the API call with the contents of the URL and request body. Postman is being used to demonstrate the functionality of this endpoint with 3 key characteristics:

Image for post
Image for post
  1. A POST request is being made to http://127.0.0.1:8000/tests/is_palindrome (Note: is_palindrome is being passed a function name string variable)
  2. The request body is a JSON object with a single entry with “solution” as the key and a string “Solution goes here.” as the value
{
"solution": "Solution goes here."
}

3. The response body is a JSON object with both the function name from the URL and the solution from the request body

{
"function_name": "is_palindrome",
"solution": "Solution goes here."
}

Try It Out

The most recent version of this project is available at the Github link below:

Written by

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store