-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
733 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
aniso8601==2.0.1 | ||
attrs==17.4.0 | ||
certifi==2018.1.18 | ||
chardet==3.0.4 | ||
aniso8601==3.0.2 | ||
astroid==1.6.5 | ||
atomicwrites==1.1.5 | ||
attrs==18.1.0 | ||
click==6.7 | ||
coverage==4.5.1 | ||
coveralls==1.3.0 | ||
docopt==0.6.2 | ||
Flask==0.12.2 | ||
Flask-JWT-Extended==3.7.1 | ||
Flask==1.0.2 | ||
Flask-JWT-Extended==3.10.0 | ||
Flask-RESTful==0.3.6 | ||
gunicorn==19.7.1 | ||
idna==2.6 | ||
gunicorn==19.8.1 | ||
isort==4.3.4 | ||
itsdangerous==0.24 | ||
Jinja2==2.10 | ||
lazy-object-proxy==1.3.1 | ||
MarkupSafe==1.0 | ||
mccabe==0.6.1 | ||
more-itertools==4.2.0 | ||
nose==1.3.7 | ||
pluggy==0.6.0 | ||
py==1.5.2 | ||
PyJWT==1.6.0 | ||
pytest==3.4.2 | ||
pytz==2018.3 | ||
requests==2.18.4 | ||
py==1.5.3 | ||
PyJWT==1.6.4 | ||
pylint==1.9.2 | ||
pytest==3.6.2 | ||
pytz==2018.4 | ||
six==1.11.0 | ||
urllib3==1.22 | ||
Werkzeug==0.14.1 | ||
wrapt==1.10.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from ridemyway.models.ride import Ride | ||
from datetime import datetime | ||
from flask import current_app as app | ||
import re | ||
from ridemyway.utils.validators import date_has_passed | ||
|
||
|
||
class RideController(): | ||
""" | ||
Controls all CRUD operations of the Ride object. | ||
""" | ||
|
||
def create_ride(self, **Kwargs): | ||
""" | ||
Creates and adds a ride to the app database. | ||
Returns: | ||
A success status if success adding ride, | ||
failed status otherwise. | ||
""" | ||
try: | ||
ride_ids = [x for x in app.database['Rides']] | ||
if ride_ids: | ||
ride_id = max(ride_ids) + 1 | ||
else: | ||
ride_id = 1 | ||
date_offered = datetime.now().strftime('%b %d %Y %H:%M%p') | ||
self.new_ride = Ride( | ||
ride_id=ride_id, | ||
departure=Kwargs['departure'], | ||
origin=Kwargs['origin'], | ||
destination=Kwargs['destination'], | ||
vehicle_number_plate= | ||
Kwargs['vehicle_number_plate'], | ||
capacity=Kwargs['capacity'], | ||
cost=Kwargs['cost'], | ||
date_offered=date_offered, | ||
availability='available') | ||
ride = self.new_ride.__dict__ | ||
app.database['Rides'][self.new_ride.ride_id] = ride | ||
status = { | ||
'status': 'success', | ||
'message': 'Ride created successfully', | ||
'attributes': { | ||
'location': | ||
'/api/v1/rides/' + str(ride['ride_id']), | ||
'repr': | ||
str(ride['ride_id']) + ' - from ' + | ||
ride['origin'] + ' to ' + | ||
ride['destination'] | ||
} | ||
} | ||
return(status) | ||
except Exception as e: | ||
status = { | ||
'status': 'failed', | ||
'message': 'Exceptions', | ||
'meta': { | ||
'errors': 1 | ||
}, | ||
'errors': [ | ||
{ | ||
str(type(e)): str(e) | ||
} | ||
] | ||
} | ||
return(status) | ||
|
||
def fetch_one(self, ride_id): | ||
try: | ||
one_ride = app.database['Rides'][ride_id] | ||
fetched_ride = { | ||
'status': 'success', | ||
'message': 'Ride fetched successfully', | ||
'data': { | ||
'rideId': one_ride['ride_id'], | ||
'departure': one_ride['departure'], | ||
'origin': one_ride['origin'], | ||
'destination': one_ride['destination'], | ||
'cost': one_ride['cost'], | ||
'vehicleNumberPlate': one_ride['vehicle_number_plate'], | ||
'capacity': one_ride['capacity'], | ||
'dateoffered': one_ride['date_offered'] | ||
} | ||
} | ||
return fetched_ride, 200 | ||
except KeyError: | ||
error_message_404 = 'Chapter 404: The Lost Resource. \ | ||
A careful and diligent search \ | ||
has been made for the desired resource, \ | ||
but it just cannot be found.' | ||
status = { | ||
'status': 'failed', | ||
'message': 'NOT FOUND', | ||
'meta': { | ||
'errors': 1 | ||
}, | ||
'errors': [ | ||
{ | ||
404: re.sub(' +', ' ', error_message_404) | ||
} | ||
] | ||
} | ||
return status, 404 | ||
|
||
def fetch_all(self): | ||
rides_count = 0 | ||
fetched_rides = { | ||
'status': 'success', | ||
'message': 'Rides fetched successfully', | ||
'meta': { | ||
'rides': 0 | ||
}, | ||
'data': {} | ||
} | ||
for key, value in app.database['Rides'].items(): | ||
if date_has_passed(value['departure']): | ||
continue | ||
rides_count += 1 | ||
fetched_rides['data'][key] = { | ||
'departure': value['departure'], | ||
'origin': value['origin'], | ||
'destination': value['destination'], | ||
'cost': value['cost'], | ||
'vehicle_number_plate': value['vehicle_number_plate'], | ||
'capacity': value['capacity'], | ||
'dateoffered': value['date_offered'] | ||
} | ||
fetched_rides['meta']['rides'] = rides_count | ||
return fetched_rides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ridemyway.models.request import Request | ||
from flask import current_app as app | ||
import re | ||
from ridemyway.utils.validators import date_has_passed | ||
|
||
|
||
class RequestController(): | ||
""" | ||
Controls all CRUD operations of the Request object. | ||
""" | ||
|
||
def create_request(self, **Kwargs): | ||
""" | ||
Creates and adds a request to the app database. | ||
Returns: | ||
A success status if success adding ride, | ||
failed status otherwise. | ||
""" | ||
try: | ||
app.database['Rides'][Kwargs['ride_id']] | ||
request_ids = [x for x in app.database['Requests']] | ||
if request_ids: | ||
request_id = max(request_ids) + 1 | ||
else: | ||
request_id = 1 | ||
self.new_request = Request( | ||
request_id=request_id, | ||
ride_id=Kwargs['ride_id'], | ||
status='available' | ||
) | ||
request = self.new_request.__dict__ | ||
app.database['Requests'][request['request_id']] = request | ||
status = { | ||
'status': 'success', | ||
'message': 'Ride request created successfully', | ||
'attributes': { | ||
'location': | ||
'/api/v1/rides/' + str(request['ride_id']) + '/requests' | ||
} | ||
} | ||
return status, 201 | ||
except KeyError: | ||
error_message_404 = 'Chapter 404: The Lost Resource. \ | ||
A careful and diligent search \ | ||
has been made for the desired resource, \ | ||
but it just cannot be found.' | ||
status = { | ||
'status': 'failed', | ||
'message': 'NOT FOUND', | ||
'meta': { | ||
'errors': 1 | ||
}, | ||
'errors': [ | ||
{ | ||
404: re.sub(' +', ' ', error_message_404) | ||
} | ||
] | ||
} | ||
return status, 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Request(): | ||
""" | ||
Creates Request objects. | ||
**Kwargs: | ||
ride_id: A unique identifier of the ride the request is | ||
being made to. | ||
request_id: A unique identifier for the request. | ||
status: Status of the request. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
""" | ||
Request object initializer. | ||
Returns: | ||
Object | ||
""" | ||
self.request_id = kwargs['request_id'] | ||
self.ride_id = kwargs['ride_id'] | ||
self.status = kwargs['status'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Ride(): | ||
""" | ||
Creates Ride objects. | ||
**Kwargs: | ||
ride_id: A unique identifier for the ride. | ||
departure: Date and time the ride is to take place. | ||
origin: Place where the ride starts. | ||
destination: Where the ride should end. | ||
vehicle_number_plate: The number plate of the vehicle. | ||
capacity: Maximum number of passengers the ride will accept. | ||
cost: The cost of receiving the ride. | ||
date_offered: The time this ride offer was created. | ||
availability: Status of the ride. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
""" | ||
Ride object initializer. | ||
Returns: | ||
Object | ||
""" | ||
self.ride_id = kwargs['ride_id'] | ||
self.departure = kwargs['departure'] | ||
self.origin = kwargs['origin'] | ||
self.destination = kwargs['destination'] | ||
self.vehicle_number_plate = kwargs['vehicle_number_plate'] | ||
self.capacity = kwargs['capacity'] | ||
self.cost = kwargs['cost'] | ||
self.date_offered = kwargs['date_offered'] | ||
self.availability = kwargs['availability'] | ||
|
||
def __repr__(self): | ||
return(str(self.ride_id) + ' - from ' + | ||
self.origin + ' to ' + self.destination) |
Oops, something went wrong.