Lucky Draw App

Running the server

Create a new virtual environment

python3 -m venv drf

Activate virtual environment

source drf/bin/activate

Install the dependencies from requirements.txt and run the command in back-end directory.

$ python3 manage.py makemigrations 
$ python3 manage.py migrate
$ python3 manage.py runserver

Setting up front-end interface

Install angular cli globally.

npm install -g @angular/cli

cd into front-end directory and install the dependencies.

npm install

Set apiUrl in environment.ts to the port where server is running, default api url is http://localhost:8080.

To preview the app, run the following command and navigate to http://localhost:4200/.

ng serve

Architecture

             arch

Getting started: Create an account

Landing
Screenshot from 2021-11-23 15-36-21

A user id will be required to acquire tickets which can be then used to participate in luck draws and win rewards.

  • /users/ ["POST"] Register a new user.
    Format
{
    "username":"t2",
    "email":"t2@t.com",
    "password":"testing321",
    "is_staff": false
}

Setting the is_staff field to true enables staff login in front-end and allows user to compute winners of lucky draws.

  • /users/login/ ["POST"] Sign in as existing user
    Format
{
    "username":"t2",
    "password":"testing321"
}

Get raffle tickets (Task 1)

Get Tickets
Screenshot from 2021-11-23 16-20-33

User can buy a single ticket or multiple tickets in one request.

  • /tickets/ ["POST"]
  • /tickets/?amount={{x}} ["POST"]
    Format
{
    "user":"3"
}

Upcoming Lucky Draw Event(s) (Task 2)

All Immediate
Screenshot from 2021-11-23 18-01-32 Screenshot from 2021-11-23 18-01-44
  • /luckydraws/{{pk}} ["GET"] rewards attribute of a lucky draw contains all upcoming rewards and their announce date.

  • /luckydraws/{{pk}}/nextevent ["GET"] Immediate upcoming active event for a lucky draw

Register for a lucky draw (Task 3)

Participate Tickets
Screenshot from 2021-11-23 16-53-57 Screenshot from 2021-11-23 16-20-57
  • /luckydraws/{{pk}}/register/ ["POST"] Register in a lucky draw using raffle ticket.
    Format
{
    "ticket_id":"4"
}

List all events in last one week (Task 4)

List Winners
Screenshot from 2021-11-23 17-38-53

Get all winners or specify span query parameter ( = 7) to get all winners in specified duration.

  • /winners ["GET"]
  • /winners/span={{x}} ["GET"]

Compute winners of lucky draw (Task 5)

Compute Winners
Screenshot from 2021-11-23 17-02-39
  • /luckydraws/{{pk}}/compute/ ["POST"] Announce the winner of a lucky draw event
    Format
{
    "redeem_date": "2021-11-23"
}

Further enhancements possible

  1. Securing admin endpoints using authentication and permissions in back-end and corresponding routes using auth guard in front-end.
  2. Enhancing application logic and interface based on PRD details.
  3. Unit tests for both front-end and back-end