Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pomodroizer committed Jul 20, 2020
0 parents commit b01ca70
Show file tree
Hide file tree
Showing 33 changed files with 332 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /manning/rest_django_payments
WORKDIR /manning/rest_django_payments
COPY requirements.txt /manning/rest_django_payments/
RUN pip install -r requirements.txt
ADD . /manning/rest_django_payments/

EXPOSE 8200

CMD ["gunicorn", "--chdir", "rest_django_payments", "--bind", ":8200", "rest_django_payments.wsgi:application"]
Empty file added api/__init__.py
Empty file.
Binary file added api/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/serializers.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added api/__pycache__/views.cpython-38.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Payment, BankTransfer

admin.site.register(Payment)
admin.site.register(BankTransfer)
5 changes: 5 additions & 0 deletions api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):
name = 'api'
39 changes: 39 additions & 0 deletions api/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 2.2.12 on 2020-05-08 23:11

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Payment',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('deal_reference', models.CharField(max_length=128)),
('currency_pair', models.CharField(max_length=8)),
('buy_currency', models.CharField(max_length=4)),
('sell_currency', models.CharField(max_length=4)),
('amount', models.IntegerField(default=0)),
('client_id', models.UUIDField(default=uuid.uuid4)),
],
),
migrations.CreateModel(
name='BankTransfer',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('bank_name', models.CharField(max_length=128)),
('iban_bank_account', models.CharField(max_length=24)),
('status', models.CharField(max_length=24)),
('amount', models.IntegerField(default=0)),
('payment', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='api.Payment')),
],
),
]
Empty file added api/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added api/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
28 changes: 28 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import uuid
from django.db import models

class Payment(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
deal_reference = models.CharField(max_length=128)
currency_pair = models.CharField(max_length=8)
buy_currency = models.CharField(max_length=4)
sell_currency = models.CharField(max_length=4)
amount = models.IntegerField(default=0)
client_id = models.UUIDField(primary_key=False, default=uuid.uuid4, editable=True)

def __str__(self):
return self.deal_reference

def get_sell_buy_format(self):
return self.sell_currency + self.buy_currency

class BankTransfer(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
payment = models.ForeignKey(Payment, null=True, on_delete=models.SET_NULL)
bank_name = models.CharField(max_length=128)
iban_bank_account = models.CharField(max_length=24)
status = models.CharField(max_length=24)
amount = models.IntegerField(default=0)

def __str__(self):
return self.iban_bank_account
17 changes: 17 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from rest_framework import serializers

from .models import Payment
from .models import BankTransfer

class PaymentSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Payment
fields = (
'id', 'deal_reference', 'currency_pair', 'buy_currency', 'sell_currency',
'amount', 'client_id'
)

class BankTransferSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = BankTransfer
fields = ('id', 'payment', 'bank_name', 'iban_bank_account', 'status', 'amount')
Empty file added api/tests/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions api/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.test import TestCase
from ..models import Payment

class PaymentTest(TestCase):
""" Test module for Payment model """

def setUp(self):
Payment.objects.create(
deal_reference='MNN-DJANGO-PAY-20200503212231', currency_pair='GBPEUR', sell_currency='GBP',
buy_currency='EUR', amount=10000, client_id='7f1f1d95-4b3e-404f-a44c-919ccafbc09d')
def test_payment_deal_reference(self):
payment_gbpeur = Payment.objects.get(deal_reference='MNN-DJANGO-PAY-20200503212231')
self.assertEqual(
payment_gbpeur.get_sell_buy_format(), "GBPEUR")
11 changes: 11 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import include, path
from rest_framework import routers
from . import views

router = routers.DefaultRouter()
router.register(r'payments', views.PaymentViewSet)
router.register(r'bank_transfer', views.BankTransferViewSet)

urlpatterns = [
path('', include(router.urls))
]
12 changes: 12 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import viewsets

from .serializers import PaymentSerializer, BankTransferSerializer
from .models import Payment, BankTransfer

class PaymentViewSet(viewsets.ModelViewSet):
queryset = Payment.objects.all()
serializer_class = PaymentSerializer

class BankTransferViewSet(viewsets.ModelViewSet):
queryset = BankTransfer.objects.all()
serializer_class = BankTransferSerializer
21 changes: 21 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rest_django_payments.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Django>=2.0,<3.0
gunicorn==19.9.0
django-mysql>=2.2.0
djangorestframework==3.11.0
requests==2.23.0
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added rest_django_payments/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added rest_django_payments/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
126 changes: 126 additions & 0 deletions rest_django_payments/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
Django settings for rest_django_payments project.
Generated by 'django-admin startproject' using Django 2.2.12.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'su9id&)ww_kn0%^vus+e)0^z!14hu)fu$r6rs=&d_t3hx=ise7'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
'rest_framework',
'api.apps.ApiConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'rest_django_payments.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'rest_django_payments.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'moneyfx',
'USER': 'root',
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'password'),
'HOST': os.environ.get('MONEYFX_PG_HOST', 'mysql'),
'PORT': 3306,
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions rest_django_payments/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""rest_django_payments URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('api.urls'))
]
16 changes: 16 additions & 0 deletions rest_django_payments/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for rest_django_payments project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rest_django_payments.settings')

application = get_wsgi_application()

0 comments on commit b01ca70

Please sign in to comment.