Merge pull request #24 from danieldupriest/stub_api_call

Stub api call
This commit is contained in:
Logan Miller 2019-01-20 13:20:15 -08:00 committed by GitHub
commit 7bfe8a44ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 265 additions and 3 deletions

0
back/__init__.py Normal file
View file

0
back/backend/__init__.py Normal file
View file

3
back/backend/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
back/backend/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class BackendConfig(AppConfig):
name = 'backend'

4
back/backend/models.py Normal file
View file

@ -0,0 +1,4 @@
from django.db import models
# Create your models here.

3
back/backend/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

20
back/backend/urls.py Normal file
View file

@ -0,0 +1,20 @@
# Rupika Dikkala
# January 19, 2019
# Add urls and link to the
# views
from django.urls import path
from . import views
urlpatterns = [
path('create_report/', views.create_report),
path('delete_report/', views.delete_report),
path('get_report/', views.get_report),
path('list_report/', views.list_report),
path('update_report/', views.update_report),
path('submit_report/', views.submit_report),
path('update_section/', views.update_section),
path('create_account/', views.create_account),
path('login/', views.login),
path('logout/', views.logout),
]

219
back/backend/views.py Normal file
View file

@ -0,0 +1,219 @@
# Rupika Dikkala
# January 19, 2019
# Creating views for URL that
# returns JSON data
from django.shortcuts import render
from django.http import JsonResponse
# Create Report
def create_report(request):
data = {
"title": "2018 Portland trip",
"date_created": "2018-05-22T14:56:28.000Z",
"submitted": False,
"date_submitted": "0000-00-00T00:00:00.000Z",
"sections": [
{
"id": 1,
"completed": True,
"title": "Flight Info",
"html_description": "<p>Enter flight details here.</p>",
"fields": {
"international": {
"label": "International flight",
"type": "boolean",
"value": True
},
"travel_date": {
"label": "Travel start date",
"type": "date",
"value": "2016-05-22T14:56:28.000Z"
},
"fare": {
"label": "Fare",
"type": "decimal",
"value": "1024.99"
},
"lowest_fare_screenshot": {
"label": "Lowest fare screenshot",
"type": "file",
"value": "e92h842jiu49f8..."
},
"plane_ticket_invoice": {
"label": "Plane ticket invoice PDF",
"type": "file",
"value": ""
}
},
"rule_violations": [
{
"error_text": "Plane ticket invoice must be submitted."
}
]
},
{
"id": 2,
"completed": False,
"title": "Hotel info",
"html_description": "<p>If you used a hotel, please enter the details.</p>",
"fields": {
"total": {
"label": "Total cost",
"type": "decimal"
}
},
"rule_violations": [
]
}
]
}
return JsonResponse(data)
# Delete report
def delete_report(request):
data = {
'name': 'Delete report',
}
return JsonResponse(data)
# Get report
def get_report(request):
data = {
"title": "2018 Portland trip",
"date_created": "2018-05-22T14:56:28.000Z",
"submitted": False,
"date_submitted": "0000-00-00T00:00:00.000Z",
"sections": [
{
"id": 1,
"completed": True,
"title": "Flight Info",
"html_description": "<p>Enter flight details here.</p>",
"fields": {
"international": {
"label": "International flight",
"type": "boolean",
"value": True
},
"travel_date": {
"label": "Travel start date",
"type": "date",
"value": "2016-05-22T14:56:28.000Z"
},
"fare": {
"label": "Fare",
"type": "decimal",
"value": "1024.99"
},
"lowest_fare_screenshot": {
"label": "Lowest fare screenshot",
"type": "file",
"value": "e92h842jiu49f8..."
},
"plane_ticket_invoice": {
"label": "Plane ticket invoice PDF",
"type": "file",
"value": ""
}
},
"rule_violations": [
{
"error_text": "Plane ticket invoice must be submitted."
}
]
},
{
"id": 2,
"completed": False,
"title": "Hotel info",
"html_description": "<p>If you used a hotel, please enter the details.</p>",
"fields": {
"total": {
"label": "Total cost",
"type": "decimal"
}
},
"rule_violations": [
]
}
]
}
return JsonResponse(data)
# List Reports
def list_report(request):
data = {
"reports": [
{
"title": "2018 Portland trip",
"date_created": "2018-05-22T14:56:28.000Z",
"state": "created",
"date_submitted": "0000-00-00T00:00:00.000Z"
},
{
"title": "2017 Los Angeles trip",
"date_created": "2017-05-22T14:56:28.000Z",
"state": "submitted",
"date_submitted": "2017-07-22T14:56:28.000Z"
},
{
"title": "2017 Denver trip",
"date_created": "2015-04-22T14:56:28.000Z",
"state": "accepted",
"date_submitted": "2015-06-22T14:56:28.000Z"
}
]
}
return JsonResponse(data)
# Update Reports
def update_report(request):
data = {
'name': 'update report',
'state': 'SUBMITTED!',
}
return JsonResponse(data)
# Submit Reports
def submit_report(request):
data = {
'name': 'submit report',
}
return JsonResponse(data)
# Update section
def update_section(request):
data = {
"fields": {
"international": True,
"travel_date": "2012-04-23T18:25:43.511Z",
"fare": "1024.99",
"lowest_fare_screenshot": "image",
}
}
return JsonResponse(data)
# Create account
def create_account(request):
data = {
'name': 'create account',
}
return JsonResponse(data)
# Login
def login(request):
data = {
'name': 'login',
}
return JsonResponse(data)
# Logout
def logout(request):
data = {
'name': 'logout',
}
return JsonResponse(data)

Binary file not shown.

View file

@ -25,18 +25,20 @@ SECRET_KEY = '5(ucf-232_)x@1ck($8ck=zwh%q=p++-0j@qh=835cuqh3ic-y'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['localhost','192.168.99.100']
ALLOWED_HOSTS = ['localhost','192.168.99.100', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'backend',
]
MIDDLEWARE = [

View file

@ -13,9 +13,15 @@ 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
# Rupika Dikkala
# January 19, 2019
from django.contrib import admin
from django.urls import path, include
# add urls to this array
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("backend.urls")),
]