An open API service indexing awesome lists of open source software.

https://github.com/andrewindeche/clientorderservice

The project contains a python service for customer orders
https://github.com/andrewindeche/clientorderservice

ansible cicd django-rest-framework kubernetes postgresql rest-api terraform

Last synced: 3 months ago
JSON representation

The project contains a python service for customer orders

Awesome Lists containing this project

README

          

# Client Order Service

|Tool | Description | Tags for tools used |
| ------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------- |
| 1.GitHub| Version Control| [Version-Control]; [Repo]; [Pipeline]; [Continuous integration];[Continuous Delivery]|
| 2.Django Rest API | Python Based Backend Framework| [python]; [Django];|
| 3.PostgresQl | Relational Database| [Relational Integrity]; [Database];|
| 4.Pipenv | Package/Dependency manager| [Virtual Environment];[Dependency];|
| 5.Ansible |Configuration Automation Tool | [Orchestration];[ configuration management]|
| 6.Terraform | Infrastructure as Code Tool | [IaC]; [Provisioning]; [Cloud Resources];|
| 7.Kubernetes | Container Orchestration Platform | [Containers]; [Cluster Management]; [Scalability];|
| 8.Africa’s Talking SMS Gateway | Communication Platform | [SMS]; [API]; [Messaging];|
| 9.OpenID | Connect Authentication Protocol | [OAuth 2.0]; [Authentication]; [Identity Management];|
| 10.Google Cloud Platform | Infrastructure As A Service | [Cloud Platform]; [Deployment];|
| 11.CircleCI | continuous integration and delivery (CI/CD) Platform | [Continuous integration]; [Continuous Delivery];[CI/CD]|

##

Description


The aim of the project is to build a DRF(Django Rest Framework) client order service that enables a client to make orders.

##

Set up Instructions


Github



  • Download the Zip file from the code tab on github to get the project Zip files (Recommended)

  • Clone the project using ```bash git clone https://github.com/andreindeche/clientorderservice.git'.```

  • Unzip the file and add the Project folder to your IDE/Compiler

1. Create an .env environment on the Django root folder and add the recessary environment variables.

Use [env example](./env.example) as a guide for environment variables.

Kubernetes



  • Create a Docker Image
  • ```bash
    docker build -t your-django-project .
    ```

  • Run the Docker container:
  • ```bash
    docker run -p 8000:8000 myproject
    ```

  • Push image to a container registry
  • ```bash
    docker tag my-django-app your-username/my-django-app:latest
    docker push your-username/my-django-app:latest
    ```

  • Create a configmap.yaml for environment variables

  • Make sure to define your environment variables in this file.

  • Apply Kubernetes configuration for your Kubernetes cluster
  • ```bash
    kubectl apply -f configmap.yaml
    kubectl apply -f deployment.yaml
    kubectl apply -f service.yaml
    ```

  • If you're testing locally, you can use Minikube to create a local Kubernetes cluster
  • ```bash
    minikube start
    ```

    ```bash
    explorer.exe "http://192.168.39.84:30095"
    ```

Django


The project uses pipenv, django and postgresql backend

1. Install pipenv using the command
```bash
pip install pipenv
```

2. Activate your virtual enviromnment
```bash
pipenv shell
```

3. Naviagte to your Django project and use in the directory path: [requirements](./requirements.txt) to install the required django dependencies
```bash
pipenv install -r requirements.txt
```

4. Create an .env on the Django root folder and add the recessary environment variables.
Use [example env](backend\env.example) as a guide for environment variables

5. Create a Super User using
```bash
python manage.py createsuperuser
```

6. Migrate your DB using
```bash
python manage.py migrate
```

7. To run the project outside of a shell environment use:
```bash
pipenv run python manage.py runserver
```
or while in the shell environment use:
```bash
python manage.py runserver
```

8. To Run Tests (Tests include Security Tests):
```bash
python manage.py test
```

9.Generate Coverage report

```bash
coverage run --source='.' manage.py test
```
```bash
coverage report
```
```bash
coverage html
```

Africa's Talking


Africa's talking has been used as the SMS/Communication gateway for the project to enable SMSes on order or update of the orders.
1. Create an account on the site https://africastalking.com/sms.
2. Generate an api key and set it on the environment variable 'YOUR_API_KEY'.

Endpoints



  • Preferably Use POSTMAN or any API tool to test the endpoints after login.

  • Orders can only be made by authenticated users.

Authentication



  • Authenticate to register as a user and interact with the API Endpoints.

  • For logins, click on the link and authenticate on a browser.

  • URL = 'http://localhost:8000'

1.Login.
```bash
http://{URL}/accounts/login/ or http://{URL}/accounts/google/login/
```

2.Register
```bash
http://{URL}/accounts/signup/
```

3.View Customer code:
```bash
http://{URL}/accounts/account_page/
```

4.Logout navigate to:
```bash
http://{URL}/accounts/google/login/
```
Select Logout

5.Generate Tokens for transactions:


  • Fields: "username", "password",
  • POST:/api/token/
  • POST:/api/token/refresh/ to refresh token

6.Create Order
```bash
POST:http://{URL}/api/create_order/
Headers: Content-Type: application/json
Authorization: Add Token
Example:Json payload:{
"customer_code": "CUST123",
"item": "Laptop",
"amount": 500
}
```

7.Update Order
```bash
PUT:http://{URL}/api/update_order//
```
To get UUID via Python shell for ORM :

```bash
python3 manage.py shell
```
```bash
from orders.models import Order
order = Order.objects.first()
print(order.order_id)
```
or start psql:

```bash
SELECT order_id FROM orders;
```

8. Use GraphQl for querying:
Navigate to: http://127.0.0.1:8000/graphql/

GraphQl Mutations:

/

Generate Token.

```bash

mutation {
generateToken(username: "your_username", password: "your_password") {
access
refresh
}
}

```

Refresh Token.

/

```bash
mutation {
refreshToken(refresh: "your_refresh_token") {
access
}
}

```

Create Order

/

```bash

mutation {
createOrder(input: {
customerCode: "CUST216204",
item: "Laptop",
amount: 500.0
}) {
order {
customer {
code
}
item
amount
}
message
smsMessage
smsStatus
}
}

```

Update Order

/

```bash

mutation {
updateOrder(orderId: "128a3b7f-d146-4793-a3c1-b5ee04d21316", item: "New Item Name", amount: "150.00") {
order {
customer {
code
}
item
amount
}
}
}

```

To get UUID via Python shell for ORM :

```bash
python3 manage.py shell
```
```bash
from orders.models import Order
order = Order.objects.first()
print(order.order_id)
```
or start psql:

```bash
SELECT order_id FROM orders;
```

##

Terraform


Terraform has been used and configurations set for [Render](https://render.com/)


The configurations located are in: [text](terraform/main.tf).

##

Ansible


The Ansible playbook has been written for consistent installations across local environments and can be used to configure various local machines

Use this command to tun a playbook:

```bash
ansible-playbook -i hosts.ini local_tasks.yml
```

To run as a sudo or admin user:

```bash
ansible-playbook playbook.yml --ask-become-pass
```
##

Author


Built by Andrew Indeche