Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
PazBazak committed Dec 28, 2020
0 parents commit 5b3cd34
Show file tree
Hide file tree
Showing 22 changed files with 785 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
.idea/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
/venv
ENV/
.vscode
# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.DS_Store
*.pyc
*.db
*.pid
# django migrations
ATM_api/api/migrations/__init__.py
!**/migrations
!**/migrations/__init__.py
*.iml
*.sqlite3
*.jpg
*.jpeg
Empty file added ATM_api/ATM/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions ATM_api/ATM/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for ATM project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
124 changes: 124 additions & 0 deletions ATM_api/ATM/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
Django settings for ATM project.
Generated by 'django-admin startproject' using Django 3.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$8s-4)=h7v))3@89d2h_(g(&71xr01n@5wbu%pfk8+fir0wfvt'

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

ALLOWED_HOSTS = []


# Application definition

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

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 = 'ATM.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'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 = 'ATM.wsgi.application'


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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/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/3.1/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions ATM_api/ATM/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""ATM URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/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('api/', include('api.urls'))
]
16 changes: 16 additions & 0 deletions ATM_api/ATM/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for ATM 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/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
Empty file added ATM_api/api/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions ATM_api/api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Bill, Coin, Currency

# Register your models here.
admin.site.register(Bill)
admin.site.register(Coin)
admin.site.register(Currency)
5 changes: 5 additions & 0 deletions ATM_api/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'
8 changes: 8 additions & 0 deletions ATM_api/api/atm_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class TooMuchCoinsException(Exception):
"""
Raised when there are more than 50 coins requested to be withdraw
"""
pass

37 changes: 37 additions & 0 deletions ATM_api/api/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


# region bills

BILL_200 = 'B200'
BILL_100 = 'B100'
BILL_50 = 'B50'
BILL_20 = 'B20'

VALID_BILLS = [BILL_200, BILL_100, BILL_50, BILL_20]

# endregion

# region coins

COIN_10 = 'C10'
COIN_5 = 'C5'
COIN_1 = 'C1'
COIN_01 = 'C0_1'
COIN_001 = 'C0_01'

VALID_COINS = [COIN_10, COIN_5, COIN_1, COIN_01, COIN_001]

# endregion

# region responses

ERROR_AMOUNT_RES = {"result": {"error": "ATM does not have enough funds, please try to withdraw a different amount!"}}

# endregion

CURRENCY = "currency"
AMOUNT = "amount"

VALID_CURRENCIES = ['ILS', 'USD']


39 changes: 39 additions & 0 deletions ATM_api/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.1.4 on 2020-12-28 17:54

from decimal import Decimal
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Currency',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(max_length=36)),
],
),
migrations.CreateModel(
name='Coin',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.DecimalField(choices=[(Decimal('10.0'), 'C10'), (Decimal('5.0'), 'C5'), (Decimal('1.0'), 'C1'), (Decimal('0.1'), 'C0_1'), (Decimal('0.01'), 'C0_01')], decimal_places=2, max_digits=4)),
('currency', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.currency')),
],
),
migrations.CreateModel(
name='Bill',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.IntegerField(choices=[(200, 'B200'), (100, 'B100'), (50, 'B50'), (20, 'B20')])),
('currency', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.currency')),
],
),
]
Empty file.
Loading

0 comments on commit 5b3cd34

Please sign in to comment.