Skip to content

thuannguyen2010/call_billing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Call Billing Service

Description

Call Billing Service has two main APIs:

  1. API receives information of a call, including user_name and call_duration
  2. API returns billing information of a user based on total duration of all calls

Database Design

Call
id (bigint)
user_name (varchar(32))
call_duration (int)
created_at (datetime(6))
updated_at (datetime(6))

A call object contains user_name of caller and call_duration is the duration of the call

Project Structure

Framework: Django

.
├── app                                 # Django app setting
│   ├── settings                        # Settings folder
│   │   ├── base.py                     # Basic settings
│   │   └── production.py               # For production settings
│   ├── asgi.py                         # ASGI config
│   ├── env.py                          # Env config
│   ├── urls.py                         # API urls of app
│   └── wsgi.py                         # WSGI config
├── call_billing                        # call_billing app, contains business about call and billing
│   ├── apis                            # Define APIs of app
│   │   ├── billing_api.py              # Define APIs of billing
│   │   └── call_api.py                 # Define APIs of call
│   ├── migrations                      # Migrations folder (generated by framework)
│   ├── services                        # Services contain business logic which are called by apis
│   │   ├── billing_service.py          # Service for billing
│   │   └── call_service.py             # Service for call
│   ├── tests
│   │   ├── apis
│   │   │   ├── test_billing_api.py     # Integration test of billing api
│   │   │   └── test_call_api.py        # Integration test of call api
│   │   ├── models                      # Unit test of model
│   │   │   └── test_call_model.py      # Unit test of call model
│   │   ├── services                    # Unit test of services
│   │   │   ├── test_billing_service.py # Unit test of billing service
│   │   │   └── test_call_service.py    # Unit test of call service
│   │   └── factories.py                # Provide a default of getting a new instance
├── docker                              # docker config
│   ├── local.Dockerfile                # Dockerfile for local build
│   ├── production.Dockerfile           # Dockerfile for production build
│   └── web_entrypoint.sh               # Web entrypoint config
├── requirments                         # Dependency
│   ├── base.txt                        # Base dependecies
│   ├── local.txt                       # For local env
├── manage.py                           # manage file of framework
└── README.md                           # Readme

This project contains many layers:

  1. Models
  • Models take care of the data model
  1. Services
  • Business logic lives in services
  • Services access the database & other resources & interact with other parts in system
  1. APIs
  • Interface of input and output that interact with clients

Usages

1. Run project

1.1. Requirements

  • Python=3.10
  • MySQL ver 8

1.2. Start project

1.2.1. Build app without docker
  1. Create virtualenv
python3.10 -m venv .venv
source .venv/bin/activate
  1. Install requirements
(.venv) pip install -r requirements/local.txt
  1. Create .env file with config DB_NAME, DB_USERNAME, DB_PASSWORD, DB_PORT, DB_HOST
  2. Run app
(.venv) python manage runserver

The app will run on port 8000

1.2.2. Using docker compose

in docker-compose.yaml, there are 2 services: db and django

  • For compose v2:
docker compose up -d
  • For compose v1:
docker-compose up -d

The app will run on port 8000

2. API Usages

2.1. API put call

Example:

curl --location --request PUT 'http://localhost:8000/mobile/user_name/call' \
--header 'Content-Type: application/json' \
--data-raw '{
    "call_duration": 545000
}'

After this API has performed, a record will be inserted into calls table in the database

2.2. API get billing

Example:

curl --location --request GET 'http://localhost:8000/mobile/user_name/billing'

The billing info will be retured for the user

Tesing

The code includes both unit test and integration test

  • Unit test for models and services
  • Integration test for apis
  • Factory boy for creating object in database in test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published